Raspberry Pi Pico W LESSON 86: Up Down Binary Counter Using Interrupts and Pushbuttons

preview_player
Показать описание
You guys can help me out over at Patreon, and that will help me keep my gear updated, and help me keep this quality content coming:

In this class we will be using the Sunfounder Raspberry Pi Pico W Keppler Kit. It will make things a lot easier if we are working on identical hardware. the link below is to amazon, and is for the identical hardware I will be using in this entire class.

In this video, I will show you how to create a hardware interrupt on the Raspberry Pi Pico W in micropython. We will have two pins connected to pushbuttons, with interrupts connected to both pins. We will have 4 led, and will create a binary counter. One button increments the counter, while the second button decrements the counter. The counter buttons are debounced so it counts without error.

More great content at:

#raspberrypipicow
#interrupts
#micropython
Рекомендации по теме
Комментарии
Автор

I enjoyed the lesson. Yes if folded up like a cheap Walmart lawn chair many times. Each failure was in itself a positive learning experience. Thank you!!!

craigflorin
Автор

👍 How amazing it all is from 1976 when I first learned compiled Basic and Simula as an undergrad and carried those bundles of punchcards to the computer centre for overnight batch runs. Wonderful stuff.

patrickfox-roberts
Автор

Thanks Paul! both programs worked the same (mine very primitive) and decided to merge them to gain better understanding and appreciation on how to work more efficiently.

edSabio
Автор

I am legend. I got the binary up and down counter working perfectly.

louistoweill
Автор

Thanks Paul! My program worked but used the same globals on both functions for red and green buttons. I am comparing the functionality of both. If my chair folds, will fess up next lesson : ) Loved this lesson and look forward to next week.

edSabio
Автор

Great tutorial!

In function driving LEDs how about:
- converting pass counter (cnt) to binary representation string (bin), and then
- set the each LED.value acording to each element/character of the bin array?

since I'm not able to set the model - I got the pass counter values from the loop
also instead of driving the LED I'm building the string (line) which will be printed to the console

for cnt in range(16):
bin = ('000' + "{0:b}".format(cnt))[-4:]

line = '[' + bin + ']'

for i in range(len(bin)):
line += ' | LED[' + str(2**(len(bin)-i-1)) + ']=' + bin[i]

print(line)

result:
[0000] | LED[8]=0 | LED[4]=0 | LED[2]=0 | LED[1]=0
[0001] | LED[8]=0 | LED[4]=0 | LED[2]=0 | LED[1]=1
[0010] | LED[8]=0 | LED[4]=0 | LED[2]=1 | LED[1]=0
[0011] | LED[8]=0 | LED[4]=0 | LED[2]=1 | LED[1]=1
[0100] | LED[8]=0 | LED[4]=1 | LED[2]=0 | LED[1]=0
[0101] | LED[8]=0 | LED[4]=1 | LED[2]=0 | LED[1]=1
[0110] | LED[8]=0 | LED[4]=1 | LED[2]=1 | LED[1]=0
[0111] | LED[8]=0 | LED[4]=1 | LED[2]=1 | LED[1]=1
[1000] | LED[8]=1 | LED[4]=0 | LED[2]=0 | LED[1]=0
[1001] | LED[8]=1 | LED[4]=0 | LED[2]=0 | LED[1]=1
[1010] | LED[8]=1 | LED[4]=0 | LED[2]=1 | LED[1]=0
[1011] | LED[8]=1 | LED[4]=0 | LED[2]=1 | LED[1]=1
[1100] | LED[8]=1 | LED[4]=1 | LED[2]=0 | LED[1]=0
[1101] | LED[8]=1 | LED[4]=1 | LED[2]=0 | LED[1]=1
[1110] | LED[8]=1 | LED[4]=1 | LED[2]=1 | LED[1]=0
[1111] | LED[8]=1 | LED[4]=1 | LED[2]=1 | LED[1]=1

also defining LEDs as array of LEDs, will allow to set their values, by index coresponding to character index in bit representation

I'm not a native English speaker, so I'm not only refreshing the basics of Micropython, but also improving my English.

Thank you...

robertkarney