I've currently set up my Pi and a simple Python program so that when I press a button, an LED blinks and Python prints a timestamp of when the button was pressed.
Now, I'm trying to extend this so that when I press the button, the Pi sends a message with the timestamp to my laptop as a notification(or not, as long as the message gets sent in some method it's good).
What do I have to do to do this, and how would the code need to be changed?
Code: Select all
import RPi.GPIO as GPIO import time import datatime SW=7 LED=11 GPIO.setmode(GPIO.BOARD) GPIO.setup(SW, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(LED, GPIO.OUT, initial=GPIO.LOW) try: while True: a=GPIO.input(SW) if a==0: ts=time.time() readable=datetime.datetime.frofromtimestamp(ts).isoformat() print 'Button pressed at', readable for i in range(0,10): GPIO.output(LED,GPIO.HIGH) time.sleep(0.5) GPIO.output(LED,GPIO.LOW) time.sleep(0.5) except KeyboardInterrupt: pass GPIO.cleanup()