Raspberry-Button
Révision datée du 26 novembre 2015 à 13:53 par Ddevleeschauwer (discussion | contributions) (→Action basique)
Cette page liste un script permettant d'interfacer le Raspberry avec un boutton
Schéma
Action basique
Ce script permet simplement d'afficher un message quand il y a un appui sur le boutton.
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
while True:
input_state = GPIO.input(18)
if input_state == False:
print('Button Pressed')
time.sleep(0.2)Rafraichir une page Internet
Ce script python permet de rafraichir une page Internet ouvert dans Iceweasel via l'appel d'un script Bash pour réaliser l'action.
Script pyhton
import RPi.GPIO as GPIO
import time
import subprocess
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
while True:
input_state = GPIO.input(18)
if input_state == False:
print('Button Pressed to refresh')
subprocess.call("./xdotool-refresh-browser.sh", shell=True)
time.sleep(0.2)Script Bash
#!/bin/bash
WID=`xdotool search --sync --onlyvisible --class iceweasel | head -1`
#xdotool windowactivate $WID
#xdotool key F5
xdotool key --window $WID F5