Raspberry Pi Lab

Tag: hello world

A Three LED Blink

by on Jan.03, 2014, under Code

My first RPi circuit.

My first RPi circuit.

My first actual circuit is a three LED blinking system.  It is a pretty simple circuit.  I have a ground pin coming off the GPIO to the blue rail on the bread board.  Then a red LED on pin 25, a green LED on pin 24, and a blue LED on pin 18.  Each LED has a 560 ohm resister.

The Python code then cycles through each LED making them blink in sequence.

It isn’t a complicated circuit or a complicated program.  However, it is an excellent starting point and a great “Hello World” program.

In my next post, I’ll use the same circuit to indicate when I have new messages waiting in my GMail account.  Should be fun.

Here is the code I used…

#!/usr/bin/env python
 
import RPi.GPIO as GPIO, time
 
DEBUG = 0
PAUSE = 1
 
GPIO.setmode(GPIO.BCM)
RED_LED = 25
GREEN_LED = 24
BLUE_LED = 18
GPIO.setup(RED_LED, GPIO.OUT)
GPIO.setup(GREEN_LED, GPIO.OUT)
GPIO.setup(BLUE_LED, GPIO.OUT)

while True:
        if DEBUG:
                print "LED ON."

        GPIO.output(RED_LED, True)
        GPIO.output(GREEN_LED, False)
        GPIO.output(BLUE_LED, False)

        time.sleep(PAUSE)

        if DEBUG:
    	print"LED OFF"

        GPIO.output(RED_LED, False)
        GPIO.output(GREEN_LED, True)
        GPIO.output(BLUE_LED, False)

        time.sleep(PAUSE)

        GPIO.output(RED_LED, False)
        GPIO.output(GREEN_LED, False)
        GPIO.output(BLUE_LED, True)

        time.sleep(PAUSE)

Leave a Comment :, , , , , , more...

Archives

All entries, chronologically...

Our Partners

Please take a minute to visit our partners

Looking for something?

Search the Site

If you can't find what you are looking for, please leave a comment somewhere, subscribe to our feed and hopefully your question will be answered shortly, so please visit again!