Raspberry-Button : Différence entre versions

De DiouxX's Wiki
Aller à : navigation, rechercher
(Page créée avec « {{ Introduction | Cette page liste un script permettant d'interfacer le Raspberry avec un boutton }} == Schéma == <br> centré <b... »)
 
(Action basique)
Ligne 22 : Ligne 22 :
 
         print('Button Pressed')
 
         print('Button Pressed')
 
         time.sleep(0.2)
 
         time.sleep(0.2)
</pre>
+
</syntaxhighlight>
  
 
== Rafraichir une page Internet ==
 
== Rafraichir une page Internet ==

Version du 26 novembre 2015 à 13:53

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)

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