Created
January 24, 2013 20:42
-
-
Save anroots/4627503 to your computer and use it in GitHub Desktop.
Python script to blink two LED-s on/off from a Raspberry Pi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Script for blinking two LED-s connected to a Raspberry Pi | |
# | |
# Author Ando Roots <ando@sqroot.eu> | |
# Created 24 Jan 2013 | |
# Usage: run from CRON every 10 minutes | |
# Link http://sqroot.eu/2013/01/pi-hacking-1-my-intro-to-the-world-of-electronics | |
import RPi.GPIO as GPIO, time, datetime | |
# Setup | |
GPIO.setmode(GPIO.BCM) | |
GREEN_LED = 18 | |
RED_LED = 23 | |
GPIO.setup(GREEN_LED, GPIO.OUT) | |
GPIO.setup(RED_LED, GPIO.OUT) | |
# Time in ms between blinks | |
BLINK_DELAY = 0.4 | |
# Temp vars for loop state | |
counter = 1 | |
green_state = True | |
# How many blinks? 1 for every ten minutes of the current time (1 - 5 blinks) | |
times_to_blink = datetime.datetime.now().minute / 10 | |
# Blink LED-s! | |
while counter <= times_to_blink: | |
print "Blink %d of %d!" % (counter, times_to_blink) | |
# Switch LED states | |
GPIO.output(GREEN_LED, green_state) | |
GPIO.output(RED_LED, not green_state) | |
# Save new states | |
green_state = not green_state | |
counter += 1 | |
# Wait... | |
time.sleep(BLINK_DELAY) | |
print "Done!" | |
# Switch the LED-s off when done | |
GPIO.output(GREEN_LED, False) | |
GPIO.output(RED_LED, False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment