diff options
| author | manuel <manuel@mausz.at> | 2013-12-25 13:25:16 +0100 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2013-12-25 13:25:16 +0100 |
| commit | 0c8c9ad976879f7c90f9915a60845ccb0cdb337d (patch) | |
| tree | 162951b4713f3836f4114958a423e2c90ecf9c6b /examples/scripts/blink/script.py | |
| download | webiopi-0c8c9ad976879f7c90f9915a60845ccb0cdb337d.tar.gz webiopi-0c8c9ad976879f7c90f9915a60845ccb0cdb337d.tar.bz2 webiopi-0c8c9ad976879f7c90f9915a60845ccb0cdb337d.zip | |
initial commit
Diffstat (limited to 'examples/scripts/blink/script.py')
| -rw-r--r-- | examples/scripts/blink/script.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/examples/scripts/blink/script.py b/examples/scripts/blink/script.py new file mode 100644 index 0000000..90c6c8c --- /dev/null +++ b/examples/scripts/blink/script.py | |||
| @@ -0,0 +1,41 @@ | |||
| 1 | # Imports | ||
| 2 | import webiopi | ||
| 3 | |||
| 4 | # Enable debug output | ||
| 5 | webiopi.setDebug() | ||
| 6 | |||
| 7 | # Retrieve GPIO lib | ||
| 8 | GPIO = webiopi.GPIO | ||
| 9 | SWITCH = 21 | ||
| 10 | SERVO = 23 | ||
| 11 | LED0 = 24 | ||
| 12 | LED1 = 25 | ||
| 13 | |||
| 14 | # Called by WebIOPi at script loading | ||
| 15 | def setup(): | ||
| 16 | webiopi.debug("Blink script - Setup") | ||
| 17 | # Setup GPIOs | ||
| 18 | GPIO.setFunction(SWITCH, GPIO.IN) | ||
| 19 | GPIO.setFunction(SERVO, GPIO.PWM) | ||
| 20 | GPIO.setFunction(LED0, GPIO.PWM) | ||
| 21 | GPIO.setFunction(LED1, GPIO.OUT) | ||
| 22 | |||
| 23 | GPIO.pwmWrite(LED0, 0.5) # set to 50% ratio | ||
| 24 | GPIO.pwmWriteAngle(SERVO, 0) # set to 0 (neutral) | ||
| 25 | GPIO.digitalWrite(LED1, GPIO.HIGH) | ||
| 26 | |||
| 27 | # Looped by WebIOPi | ||
| 28 | def loop(): | ||
| 29 | # Toggle LED each 5 seconds | ||
| 30 | value = not GPIO.digitalRead(LED1) | ||
| 31 | GPIO.digitalWrite(LED1, value) | ||
| 32 | webiopi.sleep(5) | ||
| 33 | |||
| 34 | # Called by WebIOPi at server shutdown | ||
| 35 | def destroy(): | ||
| 36 | webiopi.debug("Blink script - Destroy") | ||
| 37 | # Reset GPIO functions | ||
| 38 | GPIO.setFunction(SWITCH, GPIO.IN) | ||
| 39 | GPIO.setFunction(SERVO, GPIO.IN) | ||
| 40 | GPIO.setFunction(LED0, GPIO.IN) | ||
| 41 | GPIO.setFunction(LED1, GPIO.IN) | ||
