Problem with interrupts on Raspberry Pi Pico - newbee with problems #12971
-
I'm building a three digit 7-segment LED counter by the use of a Pico and 74HC595 shift registers. from machine import Pin
import utime
import random
#GPIO's for 74HC595 shift-registers
dataPIN=Pin(2, Pin.OUT)
latchPIN=Pin(4, Pin.OUT)
clockPIN=Pin(3, Pin.OUT)
#GPIO's for count pulses (up and down)
upPIN = Pin(14, Pin.IN, Pin.PULL_DOWN)
downPIN = Pin(15, Pin.IN, Pin.PULL_DOWN)
Counter = 0
#7-segment digits (00000000 is for leading zero's)
bit_string = [
"00111111",
"00000110",
"01011011",
"01001111",
"01100110",
"01101101",
"01111101",
"00000111",
"01111111",
"01101111",
"00000000"
]
#shifting in data in three 74HC595's
def shift_update(input,data,clock,latch):
#make latch low
latch.value(0)
#shifting in data
for i in range(0 , 24):
clock.value(0)
data.value(int(input[i]))
clock.value(1)
clock.value(0)
#make latch high to show displays
latch.value(1)
#when starting the program, all three displays are cleared.
shift_update(bit_string[10] + bit_string[10] + bit_string[10], dataPIN, clockPIN, latchPIN)
#handler for adding counter
def add():
global Counter
Counter +=1
counting (Counter)
#handler for substracting counter
def subtract():
global Counter
Counter -=1
counting (Counter)
#splitting counter in units, tens and hundreds
def counting (Counter):
if Counter < 10 :
Units = Counter
shift_update(bit_string[Units] + bit_string[10] + bit_string[10], dataPIN, clockPIN, latchPIN)
elif Counter > 9 and Counter < 100:
Units = Counter % 10
Tens = Counter // 10
shift_update(bit_string[Units] + bit_string[Tens] + bit_string[10], dataPIN, clockPIN, latchPIN)
elif Counter > 99 and Counter < 1000 :
Units = Counter % 10
Tens = (Counter // 10) % 10
Hundreds = Counter // 100
shift_update(bit_string[Units] + bit_string[Tens] + bit_string[Hundreds], dataPIN, clockPIN, latchPIN)
#IRQ routines
upPIN.irq(trigger = upPIN.IRQ_RISING, handler = add())
downPIN.irq(trigger = downPIN.IRQ_RISING, handler = subtract())
while True:
if Counter < 0:
Counter = 0
elif Counter > 999:
Counter = 999
` |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Please do us a favor and reformat your sourcecode appropriately. |
Beta Was this translation helpful? Give feedback.
Those two lines:
need a change: