This series is a goldmine! Thank you dear Paul! Since the power is small here I used only one resistor from ground rail where all LED's are connected and connected them through 1k (330 ohms is too bright for my eyes, even 10k works well) resistor to the GND or (-)
In the past, I would have counted from 0 to 31 in a for-loop, and then decoded the decimal number to binary. For this exercise, I created an array, to store the 5 '1's and '0's, and then did the math in binary, by starting the loop through with toggling bit[1] from '0' to '1', and then when toggling from '1' to '0', setting a 'Carry' flag. For bit[2] to [5], using the Carry flag to indicate the need to set, or reset the bit, turning the LED On, (or Off) and managing the Carry flag, as necessary. Your way was simpler. Many thanks for this new series.
Ok took me awhile to get it right but your method was much simpler for us just starting to write code then some of the solutions that others had entered on TH-cam. I am having fun doing this so it is keeping me busy at 73 years of age
Yeah! Raspberry Pi finally arrived so I can start the lessons! In the meantime I completed the Paul McWhorter Python lessons and did a considerable amount of additional Python learning. Here is my take on the binary counter; import RPi.GPIO as PIN # 'PIN' can be named anything you like # PIN.setmode(PIN.BOARD) # use for board pin numbering scheme PIN.setmode(PIN.BCM) # use for BCM pin numbering scheme from time import sleep # Set GPIO pin numbers led1 = 4 led2 = 17 led3 = 27 led4 = 22 led5 = 26 # Setup pins as outputs PIN.setup(led1, PIN.OUT) PIN.setup(led2, PIN.OUT) PIN.setup(led3, PIN.OUT) PIN.setup(led4, PIN.OUT) PIN.setup(led5, PIN.OUT) # Send command to all pins to turn them off, '0' does this PIN.output(led1, 0) PIN.output(led2, 0) PIN.output(led3, 0) PIN.output(led4, 0) PIN.output(led5, 0) # Create for loop to count. Create a list that formats the count # and outputs to a binary Python list. example [0, 1, 1, 0, 1] is 13 for i in range(0, 32): lst = [int(i) for i in format(i, '07b') [2:]] print(str(i) + " to binary: " + str(lst)) sleep(.5) # Use the list and list indexing to assign 0 or 1 value to led output pin PIN.output(led1, lst[4]) PIN.output(led2, lst[3]) PIN.output(led3, lst[2]) PIN.output(led4, lst[1]) PIN.output(led5, lst[0]) sleep(5) PIN.cleanup()
I am really enjoying your lessons and am learning so much. Here's my code for this lesson: # Blink 5 LED in Binary counting from 0 to 31 import RPi.GPIO as GPIO from time import sleep # Setup GPIO Pins GPIO.setmode(GPIO.BCM) GPIO.setup(5,GPIO.OUT) GPIO.setup(6,GPIO.OUT) GPIO.setup(13,GPIO.OUT) GPIO.setup(19,GPIO.OUT) GPIO.setup(26,GPIO.OUT) # Initialize setup a = 0 b = 0 c = 0 d = 0 e = 0 temp = 0 # Create a function to convert from Base10 to Base2 def Convert_base10_base2(i): a = i % 2 temp = i // 2 b = temp % 2 temp = temp // 2 c = temp % 2 temp = temp // 2 d = temp % 2 temp = temp // 2 e = temp % 2 return a, b, c, d, e # Light up each binary number for i in range(0,32,1): a,b,c,d,e = Convert_base10_base2(i) GPIO.output(5,a), GPIO.output(6,b), GPIO.output(13,c), GPIO.output(19,d), GPIO.output(26,e) sleep(1) GPIO.cleanup()
Thanks, Paul. Jolly good lesson!! I would never thought of putting the resistors going down across the gap and I will also be getting some of those short wires.
I am legend! I did this project back in the "New Arduino Tutorials, so I decided to make the assignment a little more complex by using if and elif statements to turn the LEDs on and on. 1. The Code uses if-statements to first checks to see if the 1splace LED is on or off (x1). It then determines if a one will be carried over to the next place. 2. The second set of if-statements checks to see if a one was carried over from the 1splace. Depending on the answer, the program will turn or turn off the x2 LED and determine if a 1 is carried over to the 4splace. 3. Step 2 is repeated for all the LEDs. 4. The final if-statement determines if a one is carried from the 16splace to the 32splace. 4A. If the answer is now, the code starts back at step 1. 4B. If the answer is yes, their is now more places to dump in the 1, so the program exits the while loop. Due to the number of necessary if-statements and variable required, it probably took as long to write this code as Mr. McWhorter's solution, but it was good practice. If I had time to go back and do it, I would create a function. It would make the code so much cleaner Great lessons as always!
Here is my code for the lesson 5 assignment. I retired as a programmer in 1998, but I'm rather new to Python and Linux. I wrote a program that I think handles a variable number of bits. The GPIO assignments make that not entirely true. I had to do a lot of Googling to solve the problem. I know I've gone beyond the scope of the lesson, but I couldn't get a good nights sleep until I solved the problem. I also had a HW problem. I discovered a resistor measured much higher than it should be. The corresponding LED was very dim. The resistor was not from my SunFounder kit, but from an old Arduino kit. # Binary counter with LEDs # Works with variable number of bits, except for GPIO assignments import RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) GPIO.setup(29,GPIO.OUT) GPIO.setup(31,GPIO.OUT) GPIO.setup(33,GPIO.OUT) GPIO.setup(35,GPIO.OUT) GPIO.setup(37,GPIO.OUT) On = True Off = False import time OnTime = 1 OffTime = .25 i = 0 #Number counter j = 0 #Bit index num_bits = 5 max_binary_values = 2**num_bits GPIO_Num = (37, 35, 33, 31, 29) #LED GPIO pin numbers - Reverse pin numbers if needed LED_Status = [] LED_Status = [Off for i in range(number of bits)] #Set Array size i = 0 while i < max_binary_values: b = bin(i)[2:] #Convert Number to string of ones and zeros, ignore leading 0b b = b.zfill(num_bits) #Pad String with zeros if less than number of bits j = 0 while j < num_bits: #Turn off all LEDs GPIO.output(GPIO_Num[j],Off) #turn LED Off# print(j) j = j + 1 time.sleep(OffTime) j = 0 while j < num_bits: #Set LED_Status Array for current binary number binarydigit = int(b[j]) if binarydigit == 0: LED_Status[j] = Off if binarydigit == 1: LED_Status[j] = On j = j + 1 j = 0 while j < num_bits: #turn on LED Pattern GPIO.output(GPIO_Num[j],LED_Status[j]) j = j + 1 time.sleep(OnTime) i = i + 1 GPIO.cleanup()
I'm just doing this series now (chip shortage) and I'm thankful to see a programing solution that could go on without the copy/paste business, assumed that is what we'd learn.
I did achieve legendary status but I used your instruction here to improve my circuit layout. I'm using the RP400 so it gets a bit claustrophobic building out from the back of the keyboard. I'm going to invest in a breakout cable to make it a bit easier moving forward.
The series is amazing and I am learning a lot! The one question I have is why hardcode the leds for each number. In my solution I used a loop where I used the bin(I)[2:].zfill[5] to get the num in binary, I converted to a string to be able to access each position by index, then when I had the 0 or 1 for each position I mapped the value to the led as an int - 0 or 1 - and used that to turn the led on or off. It seemed like less work to me.
Well I guess I folded, but not quite like a cheap WalMart lawn chair. I was trying to use some sort of looping code with a counter, but folded before watching your solution. But after you defined the 0 - 15 count, why not just copy and paste those 16, then all you would have had to edit would have been turning on LED5 on the second block of 16?
Hi Paul, great series, thank you! Is the source code for your solutions somewhere available for download? I’d like to keep your code next to mine for comparison.
I enjoyed the lesson here is my solution. import RPi.GPIO as GPIO import time pins = [4, 17, 27, 22, 25] GPIO.setmode(GPIO.BCM) for i in range(5): GPIO.setup(pins[i], GPIO.OUT) for i in range(0,32): binary_string = format(i, '05b')
for j in range(5): GPIO.output(pins[j], int(binary_string[j]))
We did it this way: import RPi.GPIO as rp import time rp.setmode(rp.BOARD) pin_list = [29,31,33,35,37] for pin in pin_list: rp.setup(pin,rp.OUT) for counter in range(2**len(pin_list)): print(counter) time.sleep(.25) for pin in pin_list: if not rp.input(pin): rp.output(pin,True) break elif rp.input(pin): rp.output(pin,False) rp.cleanup() We had to look up how to detect if a pin had voltage and it was pretty simple with 'rp.input(pin)' returning a boolean value on the state of containing voltage or not. This method makes it very easy to add more LEDs, as we only have to modify the 'pin_list'.
I wanted to enlarge on my comment on the pi400 and sense hat. The sense hat is one of the more interesting components of the Pi b/c is has accompanied astronauts on a mission or two along with student projects. It made the binary coding lesson easier and perhaps more esthetic. On the other hand, the sense hat does not seem easy (and maybe not possible) to use with push buttons on a breadboard, which is rather frustrating. As consolation though, it has a built in joystick which might be used to substitute for some button functions. Since almost every project on a breadboard seems harder to accomplish with a Pi than an Arduino, I like Paul's idea of using the Pi for 2nd level visualization and elaboration of Arduino data with the exception that the sense hat makes it easy to do some data gathering as well. For example, the sense hat has built in temperature and humidity sensors, joystick, altimeter, and of course the 8X8 pixel display which can also substitute for a TFT or LCD.
Yet part of what I am trying to do is teach things the hard way. Meaning, assembling things on a breadboard leads to mistakes, and that leads to troubleshooting and frustration, and that leads to building skills. My goal is maximize skill building, and sometimes that skill building is less if the package is preconfigured and all you do is plug it in. So, that is my rational.
I am legend-ish. I couldn't bear the thought of doing a manual count, so I just used a for loop to count to 31 and manually decoded it to binary with 5 if-then-else statements like this. It could have been neater, with less repetition, but I haven't quite figured out how. Part of the code: loop here # section E leftmost if counter > 15: counter = counter - 16 ledEState = True else: ledEState = False # section D if counter > 7: counter = counter - 8 ledDState = True else: ledDState = False # section C if counter > 3: counter = counter - 4 ledCState = True else: ledCState = False # section B if counter > 1: counter = counter - 2 ledBState = True else: ledBState = False # section A rightmost if counter == 1: ledAState = True else: ledAState = False
I am legend. I did not use any jumper wires and instead plugged all the LEDs into the top ground rail. I did use the same GPIO pins but in the reverse order. My code is much more compact. for num in range (32): bNum = format (num,'05b') GPIO.output(29,int(bNum[0])) GPIO.output(31,int(bNum[1])) GPIO.output(33,int(bNum[2])) GPIO.output(35,int(bNum[3])) GPIO.output(37,int(bNum[4])) time.sleep(1)
Paul - my 8yo son and I are learning RPi together from your excellent videos. Thank you for the taking the time to create this content! Here is our code, would love feedback if any: import RPi.GPIO as gpio gpio.setmode(gpio.BOARD) gpio.setup(11,gpio.OUT) gpio.setup(13,gpio.OUT) gpio.setup(15,gpio.OUT) gpio.setup(29,gpio.OUT) gpio.setup(31,gpio.OUT) import time p1,p2,p3,p4,p5 = 0,0,0,0,0 binary = [p5,p4,p3,p2,p1] for p5 in range(0,2,1): binary = [p5,p4,p3,p2,p1] for p4 in range(0,2,1): binary = [p5,p4,p3,p2,p1] for p3 in range(0,2,1): binary = [p5,p4,p3,p2,p1] for p2 in range(0,2,1): binary = [p5,p4,p3,p2,p1] for p1 in range(0,2,1): binary = [p5,p4,p3,p2,p1] print(binary) time.sleep(1) gpio.output(11,p1) gpio.output(13,p2) gpio.output(15,p3) gpio.output(29,p4) gpio.output(31,p5) time.sleep(1) gpio.output(11,0) gpio.output(13,0) gpio.output(15,0) gpio.output(29,0) gpio.output(31,0) gpio.cleanup()
I think using the bin() function in combination with the slice() function ( to remove the sign( ie "Ob" ) a the start of the binary number) looping through an array of integers (e.g. 1- 31) is perhaps a more efficient way to obtain the binary numbers......just a thought
Yet at this early stage of the lessons, I am trying to get students to understand binary and then to know how to use the GPIO pins. Later we can think at more advanced levels, but at this point just giving little steps at a time.
Thanks Paul for the lesson and the homework assignment / solution vids! I'm really appreciating your teaching style and your effort in doing this for us! I do have one question... Which brand/model sketchpad and software are you using with the cool engineering graph background? I'd love to have one just like it!
I am using autodesk sketchpad running on an ipad pro. I can not do well with the cheap sketchpads that dont let you see right under the stylus what you are writing. Then I take output of ipad and feed to the blackmagic capture board on my PC
My first thought was to do it this way but then I thought that's way too many lines of code, that can't be right lol. I created a 'for' loop with an 'if' statement and got them to turn on at the right time, but they didn't turn off so by 16 all LEDs were on. My next idea was to make a 1x5 array of 1's and 0's but didn't know the code to convert the number into binary but still thought for sure I needed to use a loop. For my wiring, I put the short end of the LEDs on the grnd bus so I didn't have to ground each one with a wire 😁 Edit: I found someone else who did what I was trying to do. I didn't use the 'else' statement to switch LEDs back off lol.
Okay.... another question. Do you have a reason why you are not using an IDE such as Thonny for these lessons? Do you have any lessons that use Thonny that you've done in the past? I ask because I had never heard of it until I watched lesson 1 in this series when you happened to mention it in passing. I looked at it and it seems just right for these kinds of projects, and the editing functions are actually fairly sophisticated.
yes. I want students to learn how to program old school. A python program is JUST TEXT. The interpreter takes the TEXT and then interprets it line by line and executes it line by line. Jumping into an IDE, students think the IDE is running the code. The IDE is just a more advanced text editor. I want them to learn the basics. We do move to Thonny in about 5 more lessons or so.
Hi Paul Sorry I missed you live because my internet was down due to gales. It keeps breaking so I haven't done a video but my code is in the comments on the last lesson. I'll look at your solution and everybody else's tomorrow. Probably mine isn't as good 😿
I thought the project was to convert a decimal number(user input) into binary and blink the binary on the LEDs. That would have required time which I didn't feel was worth it. Good thing I skipped to the answer video.
Hi Paul, As this part of the course is focused on understanding the binary nature of computers, this would have been a great place to introduce python's binary operators. This would have allowed you to use a user-defined function making use of the '&' (binary AND) to determine the LEDs to light for each number. Duplicating code over and over leads to errors such as you encountered, and makes the code difficult to read and maintain.
Yet what I am trying to do is give new learners little bite size amounts. I want them to understand binary numbers. We can later get more advanced ways to interact with them. Baby steps at a time for new learners.
my improved algorithm import RPi.GPIO as GPIO import time pins = [4, 17, 27, 22, 25] GPIO.setmode(GPIO.BCM) for i in range(len(pins)): GPIO.setup(pins[i], GPIO.OUT) for i in range(0, 2**len(pins)): binary_string = format(i, f'0{len(pins)}b')
for j in range(len(pins)): GPIO.output(pins[j], int(binary_string[j]))
import time import RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) GPIO.setup(11,GPIO.OUT) GPIO.setup(13,GPIO.OUT) GPIO.setup(15,GPIO.OUT) GPIO.setup(19,GPIO.OUT) GPIO.setup(21,GPIO.OUT) for i in range(0,32,1): if i >= 16 : i=i-16 GPIO.output(21,1) else : GPIO.output(21,0) if i >= 8: i=i-8 GPIO.output(19,1) else: GPIO.output(19,0) if i >= 4: i=i-4 GPIO.output(15,1) else: GPIO.output(15,0) if i >= 2: i = i-2 GPIO.output(13,1) else: GPIO.output(13,0) if i == 1: GPIO.output(11,1) else: GPIO.output(11,0) time.sleep(1/2) time.sleep(3) GPIO.cleanup()
I'm getting a real kick rehashing some things I haven't thought about since I took an assembly class in the early 1980's. Back in the days of punch cards and mainframes! Here's a link to a perpetual 0-31 counter using bitwise OR's to trigger the LED's. Keep up the great work! While I have it wired up I'm going to do left and right bitwise shifts. Love watching those LED's dance! th-cam.com/users/shortswhcFOp4OK6E?feature=share
th-cam.com/video/DeS2oU9esXA/w-d-xo.html This is a link to my solution to the binary led homework. It's very different from the one presented in the lesson 5 homework solution.
@@paulmcwhorter Paul keith Lowmeyer had a link to his answer homework 5 also charlette had posted her home work. Sorry did not reply sooner have been out of town. and very tired.
Great assignment. But I'm surprised you didn't use an array since that was in one of the previous lessons. Like this: x =[[0,0,0,0,1],[0,0,0,1,1],[0,0,0,1,1],[0,0,1,0,0]]...and so on Then a for loop to turn on the LEDs. Like this: for i in range (0,31,1): GPIO.output(29,x[i][0] GPIO.output(31,x[i][1]) and so on...
I'm a Legend LOL. I'm sure there's an easier way to do it, but my solution worked as intended. It is not scalable however, the solution only works for number up to 31. I have an idea how to make it work with any number and more LEDs but since I've never worked with Python I though this solution is good enough for now. This is my code: import numpy as np import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BOARD) GPIO.setup(11,GPIO.OUT) GPIO.setup(12,GPIO.OUT) GPIO.setup(37,GPIO.OUT) GPIO.setup(8,GPIO.OUT) GPIO.setup(29,GPIO.OUT) def b0(): return [GPIO.output(29,0),GPIO.output(8,0),GPIO.output(11,0),GPIO.output(12,0),GPIO.output(37,0)] def b1(): return [GPIO.output(29,0),GPIO.output(8,0),GPIO.output(11,0),GPIO.output(12,0),GPIO.output(37,1)] def b2(): return [GPIO.output(29,0),GPIO.output(8,0),GPIO.output(11,0),GPIO.output(12,1),GPIO.output(37,0)] def b3(): return [GPIO.output(29,0),GPIO.output(8,0),GPIO.output(11,0),GPIO.output(12,1),GPIO.output(37,1)] def b4(): return [GPIO.output(29,0),GPIO.output(8,0),GPIO.output(11,1),GPIO.output(12,0),GPIO.output(37,0)] def b5(): return [GPIO.output(29,0),GPIO.output(8,0),GPIO.output(11,1),GPIO.output(12,0),GPIO.output(37,1)] def b6(): return [GPIO.output(29,0),GPIO.output(8,0),GPIO.output(11,1),GPIO.output(12,1),GPIO.output(37,0)] def b7(): return [GPIO.output(29,0),GPIO.output(8,0),GPIO.output(11,1),GPIO.output(12,1),GPIO.output(37,1)] def b8(): return [GPIO.output(29,0),GPIO.output(8,1),GPIO.output(11,0),GPIO.output(12,0),GPIO.output(37,0)] def b9(): return [GPIO.output(29,0),GPIO.output(8,1),GPIO.output(11,0),GPIO.output(12,0),GPIO.output(37,1)] def b10(): return [GPIO.output(29,0),GPIO.output(8,1),GPIO.output(11,0),GPIO.output(12,1),GPIO.output(37,0)] def b11(): return [GPIO.output(29,0),GPIO.output(8,1),GPIO.output(11,0),GPIO.output(12,1),GPIO.output(37,1)] def b12(): return [GPIO.output(29,0),GPIO.output(8,1),GPIO.output(11,1),GPIO.output(12,0),GPIO.output(37,0)] def b13(): return [GPIO.output(29,0),GPIO.output(8,1),GPIO.output(11,1),GPIO.output(12,0),GPIO.output(37,1)] def b14(): return [GPIO.output(29,0),GPIO.output(8,1),GPIO.output(11,1),GPIO.output(12,1),GPIO.output(37,0)] def b15(): return [GPIO.output(29,0),GPIO.output(8,1),GPIO.output(11,1),GPIO.output(12,1),GPIO.output(37,1)] def b16(): return [GPIO.output(29,1),GPIO.output(8,0),GPIO.output(11,0),GPIO.output(12,0),GPIO.output(37,0)] def b17(): return [GPIO.output(29,1),GPIO.output(8,0),GPIO.output(11,0),GPIO.output(12,0),GPIO.output(37,1)] def b18(): return [GPIO.output(29,1),GPIO.output(8,0),GPIO.output(11,0),GPIO.output(12,1),GPIO.output(37,0)] def b19(): return [GPIO.output(29,1),GPIO.output(8,0),GPIO.output(11,0),GPIO.output(12,1),GPIO.output(37,1)] def b20(): return [GPIO.output(29,1),GPIO.output(8,0),GPIO.output(11,1),GPIO.output(12,0),GPIO.output(37,0)] def b21(): return [GPIO.output(29,1),GPIO.output(8,0),GPIO.output(11,1),GPIO.output(12,0),GPIO.output(37,1)] def b22(): return [GPIO.output(29,1),GPIO.output(8,0),GPIO.output(11,1),GPIO.output(12,1),GPIO.output(37,0)] def b23(): return [GPIO.output(29,1),GPIO.output(8,0),GPIO.output(11,1),GPIO.output(12,1),GPIO.output(37,1)] def b24(): return [GPIO.output(29,1),GPIO.output(8,1),GPIO.output(11,0),GPIO.output(12,0),GPIO.output(37,0)] def b25(): return [GPIO.output(29,1),GPIO.output(8,1),GPIO.output(11,0),GPIO.output(12,0),GPIO.output(37,1)] def b26(): return [GPIO.output(29,1),GPIO.output(8,1),GPIO.output(11,0),GPIO.output(12,1),GPIO.output(37,0)] def b27(): return [GPIO.output(29,1),GPIO.output(8,1),GPIO.output(11,0),GPIO.output(12,1),GPIO.output(37,1)] def b28(): return [GPIO.output(29,1),GPIO.output(8,1),GPIO.output(11,1),GPIO.output(12,0),GPIO.output(37,0)] def b29(): return [GPIO.output(29,1),GPIO.output(8,1),GPIO.output(11,1),GPIO.output(12,0),GPIO.output(37,1)] def b30(): return [GPIO.output(29,1),GPIO.output(8,1),GPIO.output(11,1),GPIO.output(12,1),GPIO.output(37,0)] def b31(): return [GPIO.output(29,1),GPIO.output(8,1),GPIO.output(11,1),GPIO.output(12,1),GPIO.output(37,1)] arr = [b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16,b17,b18,b19,b20,b21,b22,b23,b24,b25,b26,b27,b28,b29,b30,b31] cont = "y" while cont == "y": userInput = int(input("What number would you like to count up to in binery? ")) for i in np.linspace(1,userInput,userInput): time.sleep(.5) arr[int(i)]() time.sleep(2) b0() cont = input("Would you like to continue? y/n ") GPIO.cleanup()
This series is a goldmine! Thank you dear Paul! Since the power is small here I used only one resistor from ground rail where all LED's are connected and connected them through 1k (330 ohms is too bright for my eyes, even 10k works well) resistor to the GND or (-)
In the past, I would have counted from 0 to 31 in a for-loop, and then decoded the decimal number to binary. For this exercise, I created an array, to store the 5 '1's and '0's, and then did the math in binary, by starting the loop through with toggling bit[1] from '0' to '1', and then when toggling from '1' to '0', setting a 'Carry' flag. For bit[2] to [5], using the Carry flag to indicate the need to set, or reset the bit, turning the LED On, (or Off) and managing the Carry flag, as necessary. Your way was simpler. Many thanks for this new series.
There are 10 types of people in this world:
Those who understand binary, and those who don't.
Ok took me awhile to get it right but your method was much simpler for us just starting to write code then some of the solutions that others had entered on TH-cam. I am having fun doing this so it is keeping me busy at 73 years of age
Yeah! Raspberry Pi finally arrived so I can start the lessons!
In the meantime I completed the Paul McWhorter Python lessons and did a considerable
amount of additional Python learning.
Here is my take on the binary counter;
import RPi.GPIO as PIN # 'PIN' can be named anything you like
# PIN.setmode(PIN.BOARD) # use for board pin numbering scheme
PIN.setmode(PIN.BCM) # use for BCM pin numbering scheme
from time import sleep
# Set GPIO pin numbers
led1 = 4
led2 = 17
led3 = 27
led4 = 22
led5 = 26
# Setup pins as outputs
PIN.setup(led1, PIN.OUT)
PIN.setup(led2, PIN.OUT)
PIN.setup(led3, PIN.OUT)
PIN.setup(led4, PIN.OUT)
PIN.setup(led5, PIN.OUT)
# Send command to all pins to turn them off, '0' does this
PIN.output(led1, 0)
PIN.output(led2, 0)
PIN.output(led3, 0)
PIN.output(led4, 0)
PIN.output(led5, 0)
# Create for loop to count. Create a list that formats the count
# and outputs to a binary Python list. example [0, 1, 1, 0, 1] is 13
for i in range(0, 32):
lst = [int(i) for i in format(i, '07b') [2:]]
print(str(i) + " to binary: " + str(lst))
sleep(.5)
# Use the list and list indexing to assign 0 or 1 value to led output pin
PIN.output(led1, lst[4])
PIN.output(led2, lst[3])
PIN.output(led3, lst[2])
PIN.output(led4, lst[1])
PIN.output(led5, lst[0])
sleep(5)
PIN.cleanup()
I am really enjoying your lessons and am learning so much. Here's my code for this lesson:
# Blink 5 LED in Binary counting from 0 to 31
import RPi.GPIO as GPIO
from time import sleep
# Setup GPIO Pins
GPIO.setmode(GPIO.BCM)
GPIO.setup(5,GPIO.OUT)
GPIO.setup(6,GPIO.OUT)
GPIO.setup(13,GPIO.OUT)
GPIO.setup(19,GPIO.OUT)
GPIO.setup(26,GPIO.OUT)
# Initialize setup
a = 0
b = 0
c = 0
d = 0
e = 0
temp = 0
# Create a function to convert from Base10 to Base2
def Convert_base10_base2(i):
a = i % 2
temp = i // 2
b = temp % 2
temp = temp // 2
c = temp % 2
temp = temp // 2
d = temp % 2
temp = temp // 2
e = temp % 2
return a, b, c, d, e
# Light up each binary number
for i in range(0,32,1):
a,b,c,d,e = Convert_base10_base2(i)
GPIO.output(5,a), GPIO.output(6,b), GPIO.output(13,c), GPIO.output(19,d), GPIO.output(26,e)
sleep(1)
GPIO.cleanup()
Always loving the breadboard wandering ants!
Me and my friend Eshhu are your biggest fans!! We Watch all ur arduino videos and happily on video 52! Keep up the good work!!!
Thanks, Paul.
Jolly good lesson!! I would never thought of putting the resistors going down across the gap and I will also be getting some of those short wires.
I am legend!
I did this project back in the "New Arduino Tutorials, so I decided to make the assignment a little more complex by using if and elif statements to turn the LEDs on and on.
1. The Code uses if-statements to first checks to see if the 1splace LED is on or off (x1). It then determines if a one will be carried over to the next place.
2. The second set of if-statements checks to see if a one was carried over from the 1splace. Depending on the answer, the program will turn or turn off the x2 LED and determine if a 1 is carried over to the 4splace.
3. Step 2 is repeated for all the LEDs.
4. The final if-statement determines if a one is carried from the 16splace to the 32splace.
4A. If the answer is now, the code starts back at step 1.
4B. If the answer is yes, their is now more places to dump in the 1, so the program exits the while loop.
Due to the number of necessary if-statements and variable required, it probably took as long to write this code as Mr. McWhorter's solution, but it was good practice.
If I had time to go back and do it, I would create a function. It would make the code so much cleaner
Great lessons as always!
LEGEND!
Here is my code for the lesson 5 assignment. I retired as a programmer in 1998, but I'm rather new to Python and Linux. I wrote a program that I think handles a variable number of bits. The GPIO assignments make that not entirely true. I had to do a lot of Googling to solve the problem. I know I've gone beyond the scope of the lesson, but I couldn't get a good nights sleep until I solved the problem. I also had a HW problem. I discovered a resistor measured much higher than it should be. The corresponding LED was very dim. The resistor was not from my SunFounder kit, but from an old Arduino kit.
# Binary counter with LEDs
# Works with variable number of bits, except for GPIO assignments
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(29,GPIO.OUT)
GPIO.setup(31,GPIO.OUT)
GPIO.setup(33,GPIO.OUT)
GPIO.setup(35,GPIO.OUT)
GPIO.setup(37,GPIO.OUT)
On = True
Off = False
import time
OnTime = 1
OffTime = .25
i = 0 #Number counter
j = 0 #Bit index
num_bits = 5
max_binary_values = 2**num_bits
GPIO_Num = (37, 35, 33, 31, 29) #LED GPIO pin numbers - Reverse pin numbers if needed
LED_Status = []
LED_Status = [Off for i in range(number of bits)] #Set Array size
i = 0
while i < max_binary_values:
b = bin(i)[2:] #Convert Number to string of ones and zeros, ignore leading 0b
b = b.zfill(num_bits) #Pad String with zeros if less than number of bits
j = 0
while j < num_bits: #Turn off all LEDs
GPIO.output(GPIO_Num[j],Off) #turn LED Off# print(j)
j = j + 1
time.sleep(OffTime)
j = 0
while j < num_bits: #Set LED_Status Array for current binary number
binarydigit = int(b[j])
if binarydigit == 0:
LED_Status[j] = Off
if binarydigit == 1:
LED_Status[j] = On
j = j + 1
j = 0
while j < num_bits: #turn on LED Pattern
GPIO.output(GPIO_Num[j],LED_Status[j])
j = j + 1
time.sleep(OnTime)
i = i + 1
GPIO.cleanup()
That's smart!
I'm just doing this series now (chip shortage) and I'm thankful to see a programing solution that could go on without the copy/paste business, assumed that is what we'd learn.
The rain and storm had no effect on your quality of teaching...hats off!
I did achieve legendary status but I used your instruction here to improve my circuit layout. I'm using the RP400 so it gets a bit claustrophobic building out from the back of the keyboard. I'm going to invest in a breakout cable to make it a bit easier moving forward.
Haha, yet another ant on your breadboard! at: 40:24 !! It stays on the board until 42:22
Thanks Paul for another lesson!
The series is amazing and I am learning a lot! The one question I have is why hardcode the leds for each number. In my solution I used a loop where I used the bin(I)[2:].zfill[5] to get the num in binary, I converted to a string to be able to access each position by index, then when I had the 0 or 1 for each position I mapped the value to the led as an int - 0 or 1 - and used that to turn the led on or off. It seemed like less work to me.
I have not taught those things in the earlier lessons. I only use techniques that I have already taught in the class.
Well I guess I folded, but not quite like a cheap WalMart lawn chair. I was trying to use some sort of looping code with a counter, but folded before watching your solution. But after you defined the 0 - 15 count, why not just copy and paste those 16, then all you would have had to edit would have been turning on LED5 on the second block of 16?
good lesson!
Thanks! 😃
35:38 is it only me who saw a ant? Thought it was on my screen lol
it is there around 12min too
Thanks a lot, Sir Paul!
Hi Paul, great series, thank you! Is the source code for your solutions somewhere available for download? I’d like to keep your code next to mine for comparison.
I enjoyed the lesson here is my solution.
import RPi.GPIO as GPIO
import time
pins = [4, 17, 27, 22, 25]
GPIO.setmode(GPIO.BCM)
for i in range(5):
GPIO.setup(pins[i], GPIO.OUT)
for i in range(0,32):
binary_string = format(i, '05b')
for j in range(5):
GPIO.output(pins[j], int(binary_string[j]))
time.sleep(1)
GPIO.cleanup()
We did it this way:
import RPi.GPIO as rp
import time
rp.setmode(rp.BOARD)
pin_list = [29,31,33,35,37]
for pin in pin_list:
rp.setup(pin,rp.OUT)
for counter in range(2**len(pin_list)):
print(counter)
time.sleep(.25)
for pin in pin_list:
if not rp.input(pin):
rp.output(pin,True)
break
elif rp.input(pin):
rp.output(pin,False)
rp.cleanup()
We had to look up how to detect if a pin had voltage and it was pretty simple with 'rp.input(pin)' returning a boolean value on the state of containing voltage or not. This method makes it very easy to add more LEDs, as we only have to modify the 'pin_list'.
I wanted to enlarge on my comment on the pi400 and sense hat. The sense hat is one of the more interesting components of the Pi b/c is has accompanied astronauts on a mission or two along with student projects. It made the binary coding lesson easier and perhaps more esthetic. On the other hand, the sense hat does not seem easy (and maybe not possible) to use with push buttons on a breadboard, which is rather frustrating. As consolation though, it has a built in joystick which might be used to substitute for some button functions. Since almost every project on a breadboard seems harder to accomplish with a Pi than an Arduino, I like Paul's idea of using the Pi for 2nd level visualization and elaboration of Arduino data with the exception that the sense hat makes it easy to do some data gathering as well. For example, the sense hat has built in temperature and humidity sensors, joystick, altimeter, and of course the 8X8 pixel display which can also substitute for a TFT or LCD.
Yet part of what I am trying to do is teach things the hard way. Meaning, assembling things on a breadboard leads to mistakes, and that leads to troubleshooting and frustration, and that leads to building skills. My goal is maximize skill building, and sometimes that skill building is less if the package is preconfigured and all you do is plug it in. So, that is my rational.
I am legend. Thank you once again!
LEGEND!
I'm glad there were only 5 red LEDs in the kit...
I am legend-ish. I couldn't bear the thought of doing a manual count, so I just used a for loop to count to 31 and manually decoded it to binary with 5 if-then-else statements like this. It could have been neater, with less repetition, but I haven't quite figured out how. Part of the code:
loop here
# section E leftmost
if counter > 15:
counter = counter - 16
ledEState = True
else:
ledEState = False
# section D
if counter > 7:
counter = counter - 8
ledDState = True
else:
ledDState = False
# section C
if counter > 3:
counter = counter - 4
ledCState = True
else:
ledCState = False
# section B
if counter > 1:
counter = counter - 2
ledBState = True
else:
ledBState = False
# section A rightmost
if counter == 1:
ledAState = True
else:
ledAState = False
GPIO.output(LED_A, ledAState)
GPIO.output(LED_B, ledBState)
GPIO.output(LED_C, ledCState)
GPIO.output(LED_D, ledDState)
GPIO.output(LED_E, ledEState)
I am legend. I did not use any jumper wires and instead plugged all the LEDs into the top ground rail. I did use the same GPIO pins but in the reverse order. My code is much more compact.
for num in range (32):
bNum = format (num,'05b')
GPIO.output(29,int(bNum[0]))
GPIO.output(31,int(bNum[1]))
GPIO.output(33,int(bNum[2]))
GPIO.output(35,int(bNum[3]))
GPIO.output(37,int(bNum[4]))
time.sleep(1)
Thats the way!
Paul - my 8yo son and I are learning RPi together from your excellent videos. Thank you for the taking the time to create this content! Here is our code, would love feedback if any:
import RPi.GPIO as gpio
gpio.setmode(gpio.BOARD)
gpio.setup(11,gpio.OUT)
gpio.setup(13,gpio.OUT)
gpio.setup(15,gpio.OUT)
gpio.setup(29,gpio.OUT)
gpio.setup(31,gpio.OUT)
import time
p1,p2,p3,p4,p5 = 0,0,0,0,0
binary = [p5,p4,p3,p2,p1]
for p5 in range(0,2,1):
binary = [p5,p4,p3,p2,p1]
for p4 in range(0,2,1):
binary = [p5,p4,p3,p2,p1]
for p3 in range(0,2,1):
binary = [p5,p4,p3,p2,p1]
for p2 in range(0,2,1):
binary = [p5,p4,p3,p2,p1]
for p1 in range(0,2,1):
binary = [p5,p4,p3,p2,p1]
print(binary)
time.sleep(1)
gpio.output(11,p1)
gpio.output(13,p2)
gpio.output(15,p3)
gpio.output(29,p4)
gpio.output(31,p5)
time.sleep(1)
gpio.output(11,0)
gpio.output(13,0)
gpio.output(15,0)
gpio.output(29,0)
gpio.output(31,0)
gpio.cleanup()
Excellent!
This is so great!
I think using the bin() function in combination with the slice() function ( to remove the sign( ie "Ob" ) a the start of the binary number) looping through an array of integers (e.g. 1- 31) is perhaps a more efficient way to obtain the binary numbers......just a thought
Yet at this early stage of the lessons, I am trying to get students to understand binary and then to know how to use the GPIO pins. Later we can think at more advanced levels, but at this point just giving little steps at a time.
@@paulmcwhorter no worries.....and thanks so much for giving of your time and knowledge it's very much appreciated
Peter, Great minds think alike. Check out my homework video. th-cam.com/video/0kEnc2YQ43Q/w-d-xo.html
Thanks Paul for the lesson and the homework assignment / solution vids! I'm really appreciating your teaching style and your effort in doing this for us! I do have one question... Which brand/model sketchpad and software are you using with the cool engineering graph background? I'd love to have one just like it!
I am using autodesk sketchpad running on an ipad pro. I can not do well with the cheap sketchpads that dont let you see right under the stylus what you are writing. Then I take output of ipad and feed to the blackmagic capture board on my PC
I am legend, thank u Paul 🙏
LEGEND!
Interesting that there were so many different solutions to this homework.
great lesson paul . where is that beautiful place behind you ?
It is the headwaters of the Nile River.
I made thesame program but in Arduino
Thanks for the solution in python Sir
My first thought was to do it this way but then I thought that's way too many lines of code, that can't be right lol. I created a 'for' loop with an 'if' statement and got them to turn on at the right time, but they didn't turn off so by 16 all LEDs were on. My next idea was to make a 1x5 array of 1's and 0's but didn't know the code to convert the number into binary but still thought for sure I needed to use a loop. For my wiring, I put the short end of the LEDs on the grnd bus so I didn't have to ground each one with a wire 😁
Edit: I found someone else who did what I was trying to do. I didn't use the 'else' statement to switch LEDs back off lol.
Okay.... another question. Do you have a reason why you are not using an IDE such as Thonny for these lessons? Do you have any lessons that use Thonny that you've done in the past? I ask because I had never heard of it until I watched lesson 1 in this series when you happened to mention it in passing. I looked at it and it seems just right for these kinds of projects, and the editing functions are actually fairly sophisticated.
yes. I want students to learn how to program old school. A python program is JUST TEXT. The interpreter takes the TEXT and then interprets it line by line and executes it line by line. Jumping into an IDE, students think the IDE is running the code. The IDE is just a more advanced text editor. I want them to learn the basics. We do move to Thonny in about 5 more lessons or so.
Hi Paul
Sorry I missed you live because my internet was down due to gales. It keeps breaking so I haven't done a video but my code is in the comments on the last lesson.
I'll look at your solution and everybody else's tomorrow. Probably mine isn't as good 😿
I thought the project was to convert a decimal number(user input) into binary and blink the binary on the LEDs. That would have required time which I didn't feel was worth it. Good thing I skipped to the answer video.
Hi Paul, As this part of the course is focused on understanding the binary nature of computers, this would have been a great place to introduce python's binary operators. This would have allowed you to use a user-defined function making use of the '&' (binary AND) to determine the LEDs to light for each number. Duplicating code over and over leads to errors such as you encountered, and makes the code difficult to read and maintain.
Yet what I am trying to do is give new learners little bite size amounts. I want them to understand binary numbers. We can later get more advanced ways to interact with them. Baby steps at a time for new learners.
my improved algorithm
import RPi.GPIO as GPIO
import time
pins = [4, 17, 27, 22, 25]
GPIO.setmode(GPIO.BCM)
for i in range(len(pins)):
GPIO.setup(pins[i], GPIO.OUT)
for i in range(0, 2**len(pins)):
binary_string = format(i, f'0{len(pins)}b')
for j in range(len(pins)):
GPIO.output(pins[j], int(binary_string[j]))
time.sleep(1)
GPIO.cleanup()
Paul what will the live chat tonight be called!
#RESISTTHEMETAVERSE
thank god for shift registers.
How do you make a computer say 5?
Its binary 101
I wish u were my math teacher
I wish you were my student!
@@paulmcwhorter I bet you don't wish that I were your student!! 😼
Who noticed that ant on board 😂36:39
Hello Sir . I am form India. Once run the program I am getting permission denied
try sudo
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11,GPIO.OUT)
GPIO.setup(13,GPIO.OUT)
GPIO.setup(15,GPIO.OUT)
GPIO.setup(19,GPIO.OUT)
GPIO.setup(21,GPIO.OUT)
for i in range(0,32,1):
if i >= 16 :
i=i-16
GPIO.output(21,1)
else :
GPIO.output(21,0)
if i >= 8:
i=i-8
GPIO.output(19,1)
else:
GPIO.output(19,0)
if i >= 4:
i=i-4
GPIO.output(15,1)
else:
GPIO.output(15,0)
if i >= 2:
i = i-2
GPIO.output(13,1)
else:
GPIO.output(13,0)
if i == 1:
GPIO.output(11,1)
else:
GPIO.output(11,0)
time.sleep(1/2)
time.sleep(3)
GPIO.cleanup()
I'm getting a real kick rehashing some things I haven't thought about since I took an assembly class in the early 1980's. Back in the days of punch cards and mainframes! Here's a link to a perpetual 0-31 counter using bitwise OR's to trigger the LED's. Keep up the great work! While I have it wired up I'm going to do left and right bitwise shifts. Love watching those LED's dance!
th-cam.com/users/shortswhcFOp4OK6E?feature=share
I AM LEGEND💪
LEGEND!
I messed up at the start. Then I reworked it. Blown out of the water.
th-cam.com/video/DeS2oU9esXA/w-d-xo.html This is a link to my solution to the binary led homework. It's very different from the one presented in the lesson 5 homework solution.
Excellent!
what happened to the other comments ?
I dont understand what you are asking. Which other comments?
I agree. It seems other comments have been eliminated from this video (and other videos in this and many of your other series)
@@paulmcwhorter Paul keith Lowmeyer had a link to his answer homework 5 also charlette had posted her home work. Sorry did not reply sooner have been out of town. and very tired.
I found Keith's post in lesson 5 comments. I guess was too tired and missed it,
this is my solution
```python
import RPi.GPIO as gpio
import time
xPin = 11
xMask = 1
yPin = 13
yMask = 1
I am Legend
LEGEND!
Great assignment. But I'm surprised you didn't use an array since that was in one of the previous lessons. Like this: x =[[0,0,0,0,1],[0,0,0,1,1],[0,0,0,1,1],[0,0,1,0,0]]...and so on
Then a for loop to turn on the LEDs. Like this:
for i in range (0,31,1):
GPIO.output(29,x[i][0]
GPIO.output(31,x[i][1])
and so on...
Yes, I was kind of let down on this video. WAS a fun project.
I am legend
LEGEND!
My solution:
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(22, GPIO.OUT)
GPIO.setup(32, GPIO.OUT)
GPIO.setup(36, GPIO.OUT)
GPIO.setup(38, GPIO.OUT)
GPIO.setup(40, GPIO.OUT)
def switch_leds(num):
binary_string = format(num, f'0{5}b')
GPIO.output(22, int(binary_string[0]))
GPIO.output(32, int(binary_string[1]))
GPIO.output(36, int(binary_string[2]))
GPIO.output(38, int(binary_string[3]))
GPIO.output(40, int(binary_string[4]))
for j in range(0,3):
for i in range(0, 32):
switch_leds(i)
time.sleep(0.3)
GPIO.cleanup()
Finally got my kit and hooked up my Pi to finish the homework assignment! Thanks Paul!
th-cam.com/video/1EgyX8W5pA8/w-d-xo.html
Excellent
I'm a Legend LOL. I'm sure there's an easier way to do it, but my solution worked as intended. It is not scalable however, the solution only works for number up to 31. I have an idea how to make it work with any number and more LEDs but since I've never worked with Python I though this solution is good enough for now. This is my code:
import numpy as np
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11,GPIO.OUT)
GPIO.setup(12,GPIO.OUT)
GPIO.setup(37,GPIO.OUT)
GPIO.setup(8,GPIO.OUT)
GPIO.setup(29,GPIO.OUT)
def b0(): return [GPIO.output(29,0),GPIO.output(8,0),GPIO.output(11,0),GPIO.output(12,0),GPIO.output(37,0)]
def b1(): return [GPIO.output(29,0),GPIO.output(8,0),GPIO.output(11,0),GPIO.output(12,0),GPIO.output(37,1)]
def b2(): return [GPIO.output(29,0),GPIO.output(8,0),GPIO.output(11,0),GPIO.output(12,1),GPIO.output(37,0)]
def b3(): return [GPIO.output(29,0),GPIO.output(8,0),GPIO.output(11,0),GPIO.output(12,1),GPIO.output(37,1)]
def b4(): return [GPIO.output(29,0),GPIO.output(8,0),GPIO.output(11,1),GPIO.output(12,0),GPIO.output(37,0)]
def b5(): return [GPIO.output(29,0),GPIO.output(8,0),GPIO.output(11,1),GPIO.output(12,0),GPIO.output(37,1)]
def b6(): return [GPIO.output(29,0),GPIO.output(8,0),GPIO.output(11,1),GPIO.output(12,1),GPIO.output(37,0)]
def b7(): return [GPIO.output(29,0),GPIO.output(8,0),GPIO.output(11,1),GPIO.output(12,1),GPIO.output(37,1)]
def b8(): return [GPIO.output(29,0),GPIO.output(8,1),GPIO.output(11,0),GPIO.output(12,0),GPIO.output(37,0)]
def b9(): return [GPIO.output(29,0),GPIO.output(8,1),GPIO.output(11,0),GPIO.output(12,0),GPIO.output(37,1)]
def b10(): return [GPIO.output(29,0),GPIO.output(8,1),GPIO.output(11,0),GPIO.output(12,1),GPIO.output(37,0)]
def b11(): return [GPIO.output(29,0),GPIO.output(8,1),GPIO.output(11,0),GPIO.output(12,1),GPIO.output(37,1)]
def b12(): return [GPIO.output(29,0),GPIO.output(8,1),GPIO.output(11,1),GPIO.output(12,0),GPIO.output(37,0)]
def b13(): return [GPIO.output(29,0),GPIO.output(8,1),GPIO.output(11,1),GPIO.output(12,0),GPIO.output(37,1)]
def b14(): return [GPIO.output(29,0),GPIO.output(8,1),GPIO.output(11,1),GPIO.output(12,1),GPIO.output(37,0)]
def b15(): return [GPIO.output(29,0),GPIO.output(8,1),GPIO.output(11,1),GPIO.output(12,1),GPIO.output(37,1)]
def b16(): return [GPIO.output(29,1),GPIO.output(8,0),GPIO.output(11,0),GPIO.output(12,0),GPIO.output(37,0)]
def b17(): return [GPIO.output(29,1),GPIO.output(8,0),GPIO.output(11,0),GPIO.output(12,0),GPIO.output(37,1)]
def b18(): return [GPIO.output(29,1),GPIO.output(8,0),GPIO.output(11,0),GPIO.output(12,1),GPIO.output(37,0)]
def b19(): return [GPIO.output(29,1),GPIO.output(8,0),GPIO.output(11,0),GPIO.output(12,1),GPIO.output(37,1)]
def b20(): return [GPIO.output(29,1),GPIO.output(8,0),GPIO.output(11,1),GPIO.output(12,0),GPIO.output(37,0)]
def b21(): return [GPIO.output(29,1),GPIO.output(8,0),GPIO.output(11,1),GPIO.output(12,0),GPIO.output(37,1)]
def b22(): return [GPIO.output(29,1),GPIO.output(8,0),GPIO.output(11,1),GPIO.output(12,1),GPIO.output(37,0)]
def b23(): return [GPIO.output(29,1),GPIO.output(8,0),GPIO.output(11,1),GPIO.output(12,1),GPIO.output(37,1)]
def b24(): return [GPIO.output(29,1),GPIO.output(8,1),GPIO.output(11,0),GPIO.output(12,0),GPIO.output(37,0)]
def b25(): return [GPIO.output(29,1),GPIO.output(8,1),GPIO.output(11,0),GPIO.output(12,0),GPIO.output(37,1)]
def b26(): return [GPIO.output(29,1),GPIO.output(8,1),GPIO.output(11,0),GPIO.output(12,1),GPIO.output(37,0)]
def b27(): return [GPIO.output(29,1),GPIO.output(8,1),GPIO.output(11,0),GPIO.output(12,1),GPIO.output(37,1)]
def b28(): return [GPIO.output(29,1),GPIO.output(8,1),GPIO.output(11,1),GPIO.output(12,0),GPIO.output(37,0)]
def b29(): return [GPIO.output(29,1),GPIO.output(8,1),GPIO.output(11,1),GPIO.output(12,0),GPIO.output(37,1)]
def b30(): return [GPIO.output(29,1),GPIO.output(8,1),GPIO.output(11,1),GPIO.output(12,1),GPIO.output(37,0)]
def b31(): return [GPIO.output(29,1),GPIO.output(8,1),GPIO.output(11,1),GPIO.output(12,1),GPIO.output(37,1)]
arr = [b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16,b17,b18,b19,b20,b21,b22,b23,b24,b25,b26,b27,b28,b29,b30,b31]
cont = "y"
while cont == "y":
userInput = int(input("What number would you like to count up to in binery? "))
for i in np.linspace(1,userInput,userInput):
time.sleep(.5)
arr[int(i)]()
time.sleep(2)
b0()
cont = input("Would you like to continue? y/n ")
GPIO.cleanup()
I am legend
LEGEND!