summaryrefslogtreecommitdiffstats
path: root/examples/scripts/basic
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2013-12-25 13:25:16 +0100
committermanuel <manuel@mausz.at>2013-12-25 13:25:16 +0100
commit0c8c9ad976879f7c90f9915a60845ccb0cdb337d (patch)
tree162951b4713f3836f4114958a423e2c90ecf9c6b /examples/scripts/basic
downloadwebiopi-0c8c9ad976879f7c90f9915a60845ccb0cdb337d.tar.gz
webiopi-0c8c9ad976879f7c90f9915a60845ccb0cdb337d.tar.bz2
webiopi-0c8c9ad976879f7c90f9915a60845ccb0cdb337d.zip
initial commit
Diffstat (limited to 'examples/scripts/basic')
-rw-r--r--examples/scripts/basic/script.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/examples/scripts/basic/script.py b/examples/scripts/basic/script.py
new file mode 100644
index 0000000..5750a69
--- /dev/null
+++ b/examples/scripts/basic/script.py
@@ -0,0 +1,34 @@
1# Imports
2import webiopi
3
4# Enable debug output
5webiopi.setDebug()
6
7# Retrieve GPIO lib
8GPIO = webiopi.GPIO
9SWITCH = 21
10SERVO = 23
11LED0 = 24
12LED1 = 25
13
14# Called by WebIOPi at script loading
15def setup():
16 webiopi.debug("Basic 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# Called by WebIOPi at server shutdown
28def destroy():
29 webiopi.debug("Basic script - Destroy")
30 # Reset GPIO functions
31 GPIO.setFunction(SWITCH, GPIO.IN)
32 GPIO.setFunction(SERVO, GPIO.IN)
33 GPIO.setFunction(LED0, GPIO.IN)
34 GPIO.setFunction(LED1, GPIO.IN)