main.py
#
from machine import Pin,PWM,reset
import urequests
from time import sleep
#sens de rotation moteur
rmot = Pin(0, Pin.OUT)
lmot = Pin(2, Pin.OUT)
#vitesse moteur duty 0 à 1023
rpwm = PWM(Pin(5), freq=500 , duty=0)
lpwm = PWM(Pin(4), freq=500 , duty=0)
def stop():
#vitesse à 0 des moteur
rpwm.duty(0)
lpwm.duty(0)
def avancer():
rpwm.duty(1023)
lpwm.duty(1023)
rmot.on()
lmot.on()
def droite():
rpwm.duty(1023)
rmot.on()
lmot.off()
def gauche():
lpwm.duty(1023)
rmot.off()
lmot.on()
def reculer():
rpwm.duty(1023)
lpwm.duty(1023)
rmot.off()
lmot.off()
get_cmd = "http://lycee-serusier.fr/ota1/get_com.txt"
while True:
reponse = urequests.get(get_cmd)
cmd = reponse.text
if cmd == 'a':
avancer()
elif cmd == 'r':
reculer()
elif cmd == 'd':
droite()
elif cmd == 'g':
gauche()
elif cmd == 're':
reset()
else :
stop()
sleep(1)
page.php
<!doctype html>
<html>
<head>
<meta charset="utf-8" >
<title>Robot</title>
</head>
<body>
<table>
<tr>
<td></td>
<td><input type="button" value="av." onclick="envoyer('a')"></td>
<td></td>
</tr>
<tr>
<td><input type="button" value="ga." onclick="envoyer('g')"></td>
<td><input type="button" value="st." onclick="envoyer('s')"></td>
<td><input type="button" value="dr." onclick="envoyer('d')"></td>
</tr>
<tr>
<td></td>
<td><input type="button" value="ar." onclick="envoyer('r')"></td>
<td><input type="button" value="re." onclick="envoyer('re')"></td>
</tr>
</table>
<script>
function envoyer(com){
location.href = "wcom.php?com="+com;
}
</script>
</body>
</html>
<?php
$myfile = fopen("get_com.txt", "w") or die("Unable to open file!");
$com = $_GET['com'];
fwrite($myfile, $com);
fclose($myfile);
?>