Raspberry-Button

De DiouxX's Wiki
Révision datée du 26 novembre 2015 à 13:53 par Ddevleeschauwer (discussion | contributions) (Page créée avec « {{ Introduction | Cette page liste un script permettant d'interfacer le Raspberry avec un boutton }} == Schéma == <br> centré <b... »)
(diff) ← Version précédente | Voir la version actuelle (diff) | Version suivante → (diff)
Aller à : navigation, rechercher
Cette page liste un script permettant d'interfacer le Raspberry avec un boutton

Schéma


Raspberry-switch-button.png


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)
</pre>

== 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 ===

<syntaxhighlight lang=python>
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