Étape 4: Code source Arduino pour le geste de base voiture robot
#define bauds 9600
const int MotR_A = 3 ; DC Motor1 Pole_A
const int MotR_B = 5 ; DC Motor1 Pole_B
const int MotL_A = 6 ; DC Motor2 Pole_A
const int MotL_B = 9 ; DC Motor2 Pole_B
octet GetValue ;
void setup()
{
Serial.Begin(baudrate) ;
pinMode (MotR_A, sortie) ;
pinMode (MotR_B, sortie) ;
pinMode (MotL_A, sortie) ;
pinMode (MotL_B, sortie) ;
}
octet ReadOneByte() / / un octet lu fonction
{
int ByteRead ;
while (!. Serial.available()) ;
ByteRead = Serial.read() ;
Return ByteRead ;
}
void loop()
{
GetValue = ReadOneByte() ;
Switch(GetValue)
{
case « C » :
Robot_Left() ;
rupture ;
case « A » :
Robot_Right() ;
rupture ;
cas ' n ' :
Robot_Forword() ;
rupture ;
de l’affaire ":
Robot_Reverse() ;
rupture ;
case « E » :
Robot_Left() ;
Delay(1000) ;
Robot_Forword() ;
rupture ;
case « W » :
Robot_Right() ;
Delay(1000) ;
Robot_Forword() ;
rupture ;
}
}
Sub Robot_Reverse()
{
digitalWrite (MotR_B, élevé) ;
digitalWrite (MotR_A, basse) ;
digitalWrite (MotL_A, élevé) ;
digitalWrite (MotL_B, basse) ;
}
Sub Robot_Forword()
{
digitalWrite (MotR_A, élevé) ;
digitalWrite (MotR_B, basse) ;
digitalWrite (MotL_B, élevé) ;
digitalWrite (MotL_A, basse) ;
}
Sub Robot_Left()
{
digitalWrite (MotR_B, élevé) ;
digitalWrite (MotR_A, basse) ;
digitalWrite (MotL_A, basse) ;
digitalWrite (MotL_B, élevé) ;
}
Sub Robot_Right()
{
digitalWrite (MotR_B, basse) ;
digitalWrite (MotR_A, élevé) ;
digitalWrite (MotL_A, élevé) ;
digitalWrite (MotL_B, basse) ;
}
Sub Robot_Stop()
{
digitalWrite (MotR_B, basse) ;
digitalWrite (MotR_A, basse) ;
digitalWrite (MotL_A, basse) ;
digitalWrite (MotL_B, basse) ;
}