I have these two functions that i use on different esp32 board with two SN74HC595N shift registers.
Code: Select all
def idle_led(i, data, clock, latch):
global globalinterrupt_counter
global total_interrupts_counter
global reset_counter_val
global led_count
zeros = 16- i
print(zeros)
for e in range(zeros):
clock.value(0)
data.value(0)
clock.value(1)
clock.value(0)
clock.value(0)
data.value(1)
clock.value(1)
clock.value(0)
for e in range(i):
clock.value(0)
data.value(0)
clock.value(1)
clock.value(0)
latch.value(0)
latch.value(1)
latch.value(0)
print('did the idle')
def reset_race(i, data, clock, latch):
global globalinterrupt_counter
global total_interrupts_counter
global reset_counter_val
global led_count
global idle_interrupt_counter
global idle_totalInterrupts_counter
global interrupt_counter
# animate leds on race complete
# keep all leds on for 0.5 seconds
sleep(0.5)
for e in range(i):
#turn all leds off
for e in range(16):
clock.value(0)
data.value(0)
clock.value(1)
clock.value(0)
latch.value(0)
latch.value(1)
latch.value(0)
sleep(0.1)
# fill leds up
for e in range(16):
clock.value(0)
data.value(1)
clock.value(1)
clock.value(0)
latch.value(0)
latch.value(1)
latch.value(0)
sleep(0.05)
#turn all leds off
for e in range(16):
clock.value(0)
data.value(0)
clock.value(1)
clock.value(0)
latch.value(0)
latch.value(1)
latch.value(0)
sleep(0.5)
globalinterrupt_counter = 0
total_interrupts_counter = 0
reset_counter_val = 0
led_count = 0
idle_interrupt_counter = 0
idle_totalInterrupts_counter = 0
interrupt_counter = 0
print('all zeros')
def update_led(i, data, clock, latch):
zeros = 16 - i
print(zeros)
for e in range(zeros):
clock.value(0)
data.value(0)
clock.value(1)
clock.value(0)
for e in range(i):
clock.value(0)
data.value(1)
clock.value(1)
clock.value(0)
latch.value(0)
latch.value(1)
latch.value(0)
print('did the leds')
I have an external interupt handling the reset_race and a timer interupt for the idle animation before the race starts. The race is handled by a reed counter on a bike, counting wheel roation calling update_led.
My only problem is that the idle animation has weird behaviour. I have 16 leds and i want each one to turn on one at a time. BUT some don't turn on. With one esp it works, with the second only the first 8 leds turn on then nothing until it loops back to the first. With the third board leds 6,7 15 and 16 don't turn on.
So my question is is their a feature i mist with the shift registers that could create such a weird behaviour, or can i factory reset them ?
All other functions work fine, the reset animation turns all leds on no worries. The wheel rotation counter turns all leds on to... I don't understand why the idle function wouldn't behave the same with three different board with exact same code...??