Circuits, Raspberry Pi

Starting with LED’s and a RPi 1

I have been wanting to get into hobbytronics for several years. I’ve had a raspberry pi 1 for several years and decided to put it to use instead of sitting at the bottom of my desk drawers.

I purchased a starter kit from Adeept off of Amazon for $65. I received it a few days ago and started tinkering with it over the weekend. I started off slow by using this Sparkfun tutorial and then gradually built upon that.

once completing the tutorial I felt that i had at least a very basic understanding of how the GPIO pins worked and tried to add LEDs and make them do something together.

my next step is going to be messing with motors, stepper motors, and servos.but anyway this is what I ended up doing

I lined up 7 LEDs and wired them into the extra GPIO pins.

here is the code that I made to make it work. Feel free to criticize because I know there are better ways but this displays what is happening very well.

Here is the code that I made to make it work. Feel free to criticize because I know there are better ways but this does display what is happening very well.

## External module imports
import RPi.GPIO as GPIO
import time

# Pin Definitons:
led1 = 18 # Broadcom pin 18
led2 = 23 # Broadcom pin 23
led3 = 27 # Broadcom pin 27
led4 = 22 # Broadcom pin 22
led5 = 24 # Broadcom pin 24
led6 = 25 # Broadcom pin 25
led7 = 10 # Broadcom pin 10
butPin = 17 # Broadcom pin 17 (P1 pin 11)


# Pin Setup:
GPIO.setmode(GPIO.BCM) # Broadcom pin-numbering scheme
GPIO.setup(led1, GPIO.OUT) # LED pin set as output
GPIO.setup(led2, GPIO.OUT) # LED pin set as output
GPIO.setup(led3, GPIO.OUT) # LED pin set as output
GPIO.setup(led4, GPIO.OUT) # LED pin set as output
GPIO.setup(led5, GPIO.OUT) # LED pin set as output
GPIO.setup(led6, GPIO.OUT) # LED pin set as output
GPIO.setup(led7, GPIO.OUT) # LED pin set as output
GPIO.setup(butPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Button pin set as input w/ pull-up

# Initial state for LEDs:
GPIO.output(led1, GPIO.LOW)
GPIO.output(led2, GPIO.LOW)
GPIO.output(led3, GPIO.LOW)
GPIO.output(led4, GPIO.LOW)
GPIO.output(led5, GPIO.LOW)
GPIO.output(led6, GPIO.LOW)
GPIO.output(led7, GPIO.LOW)

print("Here we go! Press CTRL+C to exit")
try:
 while 1:
 if GPIO.input(butPin): # button is released
 GPIO.output(led1, GPIO.LOW)
 GPIO.output(led2, GPIO.LOW)
 GPIO.output(led3, GPIO.LOW)
 GPIO.output(led4, GPIO.LOW)
 GPIO.output(led5, GPIO.LOW)
 GPIO.output(led6, GPIO.LOW)
 GPIO.output(led7, GPIO.LOW)


 else: # button is pressed:
 #this is a crude first attempt 
 #I'm going to put the leds into a list instead of individual variables
 GPIO.output(led7, GPIO.LOW);GPIO.output(led1, GPIO.HIGH)
 time.sleep(0.075)
 GPIO.output(led1, GPIO.LOW); GPIO.output(led2, GPIO.HIGH)
 time.sleep(0.075)
 GPIO.output(led2, GPIO.LOW); GPIO.output(led3, GPIO.HIGH)
 time.sleep(0.075)
 GPIO.output(led3, GPIO.LOW); GPIO.output(led4, GPIO.HIGH)
 time.sleep(0.075)
 GPIO.output(led4, GPIO.LOW); GPIO.output(led5, GPIO.HIGH)
 time.sleep(0.075)
 GPIO.output(led5, GPIO.LOW); GPIO.output(led6, GPIO.HIGH)
 time.sleep(0.075)
 GPIO.output(led6, GPIO.LOW); GPIO.output(led7, GPIO.HIGH)
 time.sleep(0.075)
 GPIO.output(led7, GPIO.LOW); GPIO.output(led6, GPIO.HIGH)
 time.sleep(0.075)
 GPIO.output(led6, GPIO.LOW); GPIO.output(led5, GPIO.HIGH)
 time.sleep(0.075)
 GPIO.output(led5, GPIO.LOW); GPIO.output(led4, GPIO.HIGH)
 time.sleep(0.075)
 GPIO.output(led4, GPIO.LOW); GPIO.output(led3, GPIO.HIGH)
 time.sleep(0.075)
 GPIO.output(led3, GPIO.LOW); GPIO.output(led2, GPIO.HIGH)
 time.sleep(0.075)


except KeyboardInterrupt: # If CTRL+C is pressed, exit cleanly:
 GPIO.cleanup() # cleanup all GPIO

 

Here is a video of this project in action. And yes I know it’s nothing spectacular but ramping this up even further is where things get interesting.