Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shiftOut command missing #131

Closed
eadmaster opened this issue Jun 10, 2024 · 1 comment
Closed

shiftOut command missing #131

eadmaster opened this issue Jun 10, 2024 · 1 comment

Comments

@eadmaster
Copy link

eadmaster commented Jun 10, 2024

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.

@eadmaster
Copy link
Author

eadmaster commented Jun 11, 2024

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant