Étape 5: CODE et aller!!
1) Assurez-vous que vous avez SoftwareSerial.h. Cela nous permet d’exécuter deux instances de série à la fois !
2) Télécharger le code de votre arduino
3) démarrer en appuyant sur les boutons pour vos commentaires
4) vous pouvez changer l’ID du xbee. Ces valeurs sont rédigés chaque fois que l’arduino est mis sous tension.
5) va chercher quelque chose au contrôle!
Arduino pro 5v code avec protocole de contrôle de newhaven :
#include
SoftwareSerial xbeeSerial (12, 13) ; RX, TX
variables
int i = 0 ;
int j = 0 ;
int m = 0 ;
dChange int = 0 ;
sChange int = 0 ;
int stChange = 0 ;
int ret = 0 ;
exécuter des int = 0 ;
int inByte = 0 ;
int = jusqu'à 3 ;
int bas = 4 ;
int gauche = 5 ;
int droite = 6 ;
Sélectionnez int = 7 ;
int start = 8 ;
commandes int [100]; //for util
int d’entrée [6] = {vers le haut, bas, gauche, droite, sélectionner, démarrer} ;
buttonState int [6] ;
char * directions [] = {"Avance", "Retour", "LEFT", "RIGHT", "SELECT", "START"} ;
char * dlist [] = {"F", "R", "<", ">", "sel", "sta"} ;
xbeeSend Byte [4] = {0 x 31, 0 x 32, 0 x 33, 0 x 34} ;
Char [] roverData = "" ;
commandes de Newhaven NHD-0220D3Z-NSW-BBW-V3
programme d’octet = 0xFE ;
displayOn octet = 0 x 41 ;
displayOff octet = 0 x 42 ;
cursorPos octet = 0 x 45 ; Set de 1 octet
cursorHome octet = 0 x 46 ;
underlineOn octet = 0 x 47 ;
underlineOff octet = 0 x 48 ;
cursorLeft octet = 0 x 49 ;
cursorRight octets = 0x4A ;
blinkingOn octets = 0x4B ;
blinkingOff octets = 0x4C ;
retour arrière octets = 0xFE ;
clearScreen octet = 0 x 51 ;
setContrast octet = 0 x 52 ; jeu d’octets //1
setBrightness octet = 0 x 53 ; ensemble de 1 octet
octet personnalisé = 0 x 54 ;
displayLeft octet = 0 x 55 ;
displayRight octet = 0 x 56 ;
firmware octet = 0 x 70 ;
/*
0xFE 0x61 1 octet changement RS‐232 BAUDrate 3mS
0xFE 0x62 adresse de 1 octet changement I2C 3mS
0xFE 0x70 aucun affichage firmware version numéro 4mS
0xFE 0x71 aucun affichage RS‐232 BAUDrate 10mS
0xFE 0x72 aucun affichage I2C adresse 4mS
*/
void setup()
{
Ouvrir com série et définir les entrées
Serial.Begin(9600) ;
xbeeSerial.begin(9600) ;
pour (i = 3; i < 9; i ++) {}
pinMode (i, entrée) ;
}
lcdCommand(program,clearScreen) ;
Delay(500) ;
//
mettre la radio en mode commande :
xbeeSerial.print("+++") ;
Attendez que la radio à répondre avec « OK\r »
char thisByte = 0 ;
tandis que (thisByte! = « \r ») {}
Si (xbeeSerial.available() > 0) {}
thisByte = xbeeSerial.read() ;
// }
// }
Définissez l’adresse de destination avec l’adressage de 16 bits. Cette radio
destination doit être l’autre radio mon adresse et vice versa :
xbeeSerial.print ("ATDH0, DL1234\r") ;
xbeeSerial.print("ATMY5678\r") ; définir mon adresse (adressage de 16 bits)
définir l’ID de PAN. Si vous êtes dans un lieu où de nombreuses personnes
sont à l’aide de XBees, choisissez un ID unique de PAN
xbeeSerial.print("ATID1111\r") ;
xbeeSerial.print("ATCN\r") ;
xbeeListen() ;
}
void xbeeListen() {}
char thisByte = 0 ;
Si (Serial.available() > 0) {}
thisByte = Serial.read() ;
}
}
void loop() / / loufoque !
{
lcdCommand(program,cursorHome) ;
lcdCommand(program,blinkingOn) ;
lcdCommand(program,setContrast) ;
Serial.Write(0x28) ;
readDpadInput() ;
readSelInput() ;
lcdCommand(program,cursorRight) ;
Serial.Print("Command:") ;
Serial.Print(j) ;
Serial.Print("?") ;
lcdCommand(program,cursorPos) ;
Serial.Write(0x40) ;
while(dChange ==1) {}
directionFeedback() ;
Delay(500) ;
commandes [j] = ret ;
j ++ ;
lcdCommand(program,clearScreen) ;
dChange = 0 ;
}
Delay(500) ;
}
Serial
Protocole de commande :
int lcdCommand (adresse de l’octet, int value) {}
Serial.Write (adresse); //CORRECT syntaxe de commandes lcd
Serial.Write(value) ;
}
lire d’entrée
int readDpadInput() {}
pour (i = 0; i < 4; i ++) {}
buttonState[i]=digitalRead(input[i]) ;
dChange = buttonState [i] + dChange ;
}
}
int readSelInput() {}
buttonState[4]=digitalRead(input[4]) ;
sChange = buttonState [4] + sChange ;
}
int readStartInput() {}
buttonState[5]=digitalRead(input[5]) ;
stChange = buttonState [5] + stChange ;
}
afficher l’itinéraire
int directionFeedback() {}
pour (i = 0; i < 4; i ++) {}
{Switch(ButtonState[i])}
case 0: lcdCommand(program,cursorHome) ;
rupture ;
cas 1 :
lcdCommand(program,blinkingOff) ;
lcdCommand(program,cursorPos) ;
Serial.Write(0xc) ;
Serial.Print(directions[i]) ;
xbeeSerial.print(i+1) ;
handleSerial() ;
Delay(1000) ;
xbeeSerial.write("\r") ;
RET = i ;
rupture ;
}
}
}
int handleSerial() {}
xbeeSerial.print(56) ;
if(xbeeSerial.available() > 0) {}
inByte = xbeeSerial.read() ;
Serial.Print(inByte) ;
}
}