Closed eadmaster closed 2 months ago
UPDATE: i've managed to port this piece of code from Johnny Five ,seems to work correctly, so no need to add a command:
def pyfirmata_shift_out(board, data_pin, clock_pin, value, is_big_endian=False):
# derived from https://github.com/rwaldron/johnny-five/blob/main/lib/board.js#L560
for i in range(8):
board.digital[clock_pin].write(0)
if is_big_endian:
b = int(bool(value & (1 << (7 - i))))
else:
b = int(bool(value & (1 << i)))
board.digital[data_pin].write(b)
board.digital[clock_pin].write(1)
def update_bar_display(value):
# open latch to fill register with data
board.digital[LEDBAR_SHIFTREG_LATCH_PIN].write(0)
def convert_to_bits_on(num):
result = 0
for i in range(num):
result |= 1 << i
return result
#print("real value", value)
value = int(value/9)
if value>7:
value=7
#print("real value", value)
value = convert_to_bits_on(value)
pyfirmata_shift_out(board, LEDBAR_SHIFTREG_DATA_PIN, LEDBAR_SHIFTREG_CLOCK_PIN, value, True)
# close latch to commit bits into register.
board.digital[LEDBAR_SHIFTREG_LATCH_PIN].write(1)
original example: https://johnny-five.io/examples/shift-register/
i've seen it is commented in the code, is there a fork/branch with this command implemented?
I'd like to use a bunch of these common 74HC595 Shift Registers in my code.