#!/usr/bin/env python # //////////////////////////////////////// # // pushLED.py # // Blinks an LED attached to P9_12 when the button at P9_42 is pressed # // Wiring: # // Setup: # // See: # //////////////////////////////////////// import time import os ms = 50 # Read time in ms LED="50" # Look up P9.14 using gpioinfo | grep -e chip -e P9.14. chip 1, line 18 maps to 50 button="7" # P9_42 mapps to 7 GPIOPATH="/sys/class/gpio/" # Make sure LED is exported if (not os.path.exists(GPIOPATH+"gpio"+LED)): f = open(GPIOPATH+"export", "w") f.write(LED) f.close() # Make it an output pin f = open(GPIOPATH+"gpio"+LED+"/direction", "w") f.write("out") f.close() # Make sure button is exported if (not os.path.exists(GPIOPATH+"gpio"+button)): f = open(GPIOPATH+"export", "w") f.write(button) f.close() # Make it an output pin f = open(GPIOPATH+"gpio"+button+"/direction", "w") f.write("in") f.close() # Read every ms fin = open(GPIOPATH+"gpio"+button+"/value", "r") fout = open(GPIOPATH+"gpio"+LED+"/value", "w") while True: fin.seek(0) fout.seek(0) fout.write(fin.read()) time.sleep(ms/1000)