Code: Select all
<script type="text/javascript">
var charfield=document.getElementById("char")
charfield.onkeydown=function(e){
var e=window.event || e;
alert(e.keyCode);
}
</script>
</head>
<body id="char">
</body>
</html>
Code: Select all
pi@raspberrypi /etc $ sudo cat /etc/modprobe.d/raspi-blacklist.conf
# blacklist spi and i2c by default (many users don't need them)
blacklist spi-bcm2708
blacklist i2c-bcm2708Code: Select all
pi@raspberrypi ~ $ cat ON.py
#!/usr/bin/python
import RPi.GPIO as GPIO
LED = 23
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(LED , GPIO.OUT)
GPIO.output(LED, True)Code: Select all
pi@raspberrypi ~ $ cat OFF.py
#!/usr/bin/python
import RPi.GPIO as GPIO
LED = 23
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(LED , GPIO.OUT)
GPIO.output(LED, False)Code: Select all
sudo chmod +x ON.py
sudo chmod +x OFF.pyCode: Select all
wget http://webiopi.googlecode.com/files/WebIOPi-0.6.0.tar.gz
tar xvzf WebIOPi-0.6.0.tar.gz
cd WebIOPi-0.6.0
sudo ./setup.shCode: Select all
sudo /etc/init.d/webiopi startCode: Select all
sudo ifconfigCode: Select all
#HOME=/usr/share/webiopi/htdocs
#DAEMON_ARGS="-m webiopi -l $LOG_FILE -c $CONFIG_FILE"
DAEMON_ARGS="/usr/share/webiopi/htdocs/onoff.py"Code: Select all
pi@raspberrypi ~ $ sudo nano /usr/share/webiopi/htdocs/onoff.pyCode: Select all
#!/usr/bin/env python
from time import sleep
import webiopi
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO11= 23
GPIO.setup(GPIO11, GPIO.OUT)
def TurnON():
GPIO.output(GPIO11,True)
def TurnOFF():
GPIO.output(GPIO11,False)
server = webiopi.Server(port=8000, login="webiopi", password="framboise")
server.addMacro(TurnON)
server.addMacro(TurnOFF)
webiopi.runLoop()
server.stop()
Code: Select all
sudo chmod +x /usr/share/webiopi/htdocs/onoff.pyCode: Select all
pi@raspberrypi ~ $ sudo nano /usr/share/webiopi/htdocs/onoff.htmlCode: Select all
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>ON_OFF sur le GPIO 11</title>
<script type="text/javascript" src="/webiopi.js"></script>
<script type="text/javascript">
function init() {
}
function TurnON() {
webiopi().callMacro("TurnON");
}
function TurnOFF() {
webiopi().callMacro("TurnOFF");
}
webiopi().ready(init);
</script>
</head>
<body>
<button type="button" onclick="TurnON()">ON</button>
<button type="button" onclick="TurnOFF()">OFF</button>
</body>
</html>
Code: Select all
sudo /etc/init.d/webiopi restartCode: Select all
#!/usr/bin/env python
from time import sleep
import webiopi
import RPi.GPIO as GPIO
# Enable debug output
webiopi.setDebug()
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
def ModeIO( Pin , Mode):
# only 2 possibilities
if Mode in ["OUT"]:
GPIO.setup(int(Pin), GPIO.OUT)
if Mode in ["IN"]:
GPIO.setup(int(Pin), GPIO.IN)
def SetIO( Pin, Value):
#only 4 possibilities
if Value in ["true","false","0","1"]:
GPIO.output(int(Pin), Value in ["true","1"])
server = webiopi.Server(port=8000, login="webiopi", password="framboise")
server.addMacro(ModeIO)
server.addMacro(SetIO)
webiopi.runLoop()
server.stop()
Code: Select all
html>
<head>
<title>ON_OFF sur le GPIO 11</title>
</style>
<script type="text/javascript" src="/webiopi.js"></script>
<script type="text/javascript">
// declaration des Pins
var GPIO11=23;
// declaration des modes In/Out
var OUT = "OUT";
var IN = "IN";
// Les fonctions
function init()
{
// init sortie
ModeIO(GPIO11,OUT);
}
function ModeIO(Pin, Mode){
webiopi().callMacro("ModeIO",[Pin,Mode]);
}
function SetIO(Pin,Value) {
webiopi().callMacro("SetIO",[Pin,Value]);
}
webiopi().ready(init);
</script>
</head>
<body>
<button type="button" onclick="SetIO(GPIO11,true)">ON</button>
<button type="button" onclick="SetIO(GPIO11,false)">OFF</button>
</body>
</html>
Code: Select all
il reste gris car il y na pas d activer sur les bouton onoff.htmlCode: Select all
sudo ./test.pyCode: Select all
sudo service webiopi stopCode: Select all
pi@raspberrypi ~ $ cat test.html
<html>
<head>
<title>ON_OFF sur le GPIO 11</title>
<style type="text/css">
.btn{width: auto; height: auto; padding: 0;font:normal 14px/20px helvetica,arial,sans-serif;
color: #000000;border: #d0d0d0;border-style: outset;border-width: 3px;}
</style>
<script type="text/javascript" src="/webiopi.js"></script>
<script type="text/javascript">
// declaration des Pins
var GPIO11=23;
var GPIO23=16;
var GPIO24=18;
// declaration des modes In/Out
var OUT = "OUT";
var IN = "IN";
// Les fonctions
function init()
{
// init sortie
ModeIO(GPIO11,OUT);
ModeIO(GPIO23,OUT);
ModeIO(GPIO24,OUT);
}
function ModeIO(Pin, Mode){
webiopi().callMacro("ModeIO",[Pin,Mode]);
}
function SetIO(Pin,Value) {
webiopi().callMacro("SetIO",[Pin,Value]);
}
function StopAll() {
webiopi().callMacro("SetIO",[GPIO11,false]);
webiopi().callMacro("SetIO",[GPIO23,false]);
webiopi().callMacro("SetIO",[GPIO24,false]);
}
webiopi().ready(init);
</script>
</head>
<body>
GPIO11 <button type="button" onclick="SetIO(GPIO11,true)">ON</button>
<button type="button" onclick="SetIO(GPIO11,false)">OFF</button><br>
GPIO23 <button type="button" onclick="SetIO(GPIO23,true)">ON</button>
<button type="button" onclick="SetIO(GPIO23,false)">OFF</button><br>
GPIO24 <button type="button" onclick="SetIO(GPIO24,true)">ON</button>
<button type="button" onclick="SetIO(GPIO24,false)">OFF</button><br>
<button class="btn" type="button" onclick="StopAll()"> STOP ALL </button>
</body>
</html>
dans le fichier htmlGPIO11=26