Код
код Arduino Arduino
char buffer [67]; байт Pino02 =2; байт Pino03 =3; байт Pino04 =4; байт Pino05 =5; байт Pino06 =6; байт Pino07 =7; байт Pino12 =12; байт Pino13 =13; void setup () {Serial.begin (9600); Serial.flush (); pinMode (Pino02, ВЫХОД); pinMode (Pino03, ВЫХОД); pinMode (Pino04, ВЫХОД); pinMode (Pino05, ВЫХОД); pinMode (Pino06, ВЫХОД); pinMode (Pino07, ВЫХОД); pinMode (9, ВЫХОД); pinMode (10, ВЫХОД); pinMode (12, ВЫХОД); pinMode (13, OUTPUT);} void loop () {if (Serial.available ()> 0) {int index =0; delay (100); // deixe o buffer encher int numChar =Serial.available (); если (numChar> 65) {numChar =65; } пока (numChar -) {буфер [индекс ++] =Serial.read (); } splitString (буфер); }} void splitString (char * data) {Serial.print ("Dados Inseridos:"); Serial.println (данные); char * параметр; параметр =strtok (данные, ","); while (параметр! =NULL) {setLED (параметр); параметр =strtok (NULL, ","); } // Ограничение текстовых буферов последовательно для (int x =0; x <66; x ++) {buffer [x] ='\ 0'; } Serial.flush ();} void setLED (char * data) {if (data [0] =='A') {analogWrite (9, 50); analogWrite (10, 50); digitalWrite (Pino02, LOW); digitalWrite (Pino03, HIGH); digitalWrite (Pino04, HIGH); digitalWrite (Pino05, LOW); digitalWrite (12, ВЫСОКИЙ); digitalWrite (13, LOW); } // İLERİSOL if (data [0] =='C') {analogWrite (9, 50); analogWrite (10, 50); digitalWrite (Pino02, HIGH); digitalWrite (Pino03, LOW); digitalWrite (Pino04, LOW); digitalWrite (Pino05, HIGH); digitalWrite (12, ВЫСОКИЙ); digitalWrite (13, LOW); } // İLERİSAĞ if (data [0] =='B') {analogWrite (9, 25); analogWrite (10, 25); digitalWrite (Pino02, HIGH); digitalWrite (Pino03, LOW); digitalWrite (Pino04, HIGH); digitalWrite (Pino05, LOW); digitalWrite (12, LOW); digitalWrite (13, ВЫСОКИЙ); } // GERİ1 if (data [0] =='M') {analogWrite (9, 75); analogWrite (10, 75); digitalWrite (Pino02, HIGH); digitalWrite (Pino03, LOW); digitalWrite (Pino04, HIGH); digitalWrite (Pino05, LOW); digitalWrite (12, LOW); digitalWrite (13, ВЫСОКИЙ); } // GERİ2 if (data [0] =='N') {analogWrite (9, 125); analogWrite (10, 125); digitalWrite (Pino02, HIGH); digitalWrite (Pino03, LOW); digitalWrite (Pino04, HIGH); digitalWrite (Pino05, LOW); digitalWrite (12, LOW); digitalWrite (13, ВЫСОКИЙ); } // GERİ3 if (data [0] =='P') {analogWrite (9, 175); analogWrite (10, 175); digitalWrite (Pino02, HIGH); digitalWrite (Pino03, LOW); digitalWrite (Pino04, HIGH); digitalWrite (Pino05, LOW); digitalWrite (12, LOW); digitalWrite (13, ВЫСОКИЙ); } // GERİ4 if (data [0] =='L') {analogWrite (9, 225); analogWrite (10, 225); digitalWrite (Pino02, HIGH); digitalWrite (Pino03, LOW); digitalWrite (Pino04, HIGH); digitalWrite (Pino05, LOW); digitalWrite (12, LOW); digitalWrite (13, ВЫСОКИЙ); } // GERİ5 if (data [0] =='D') {analogWrite (9, 25); analogWrite (10, 25); digitalWrite (Pino02, LOW); digitalWrite (Pino03, HIGH); digitalWrite (Pino04, LOW); digitalWrite (Pino05, HIGH); digitalWrite (12, ВЫСОКИЙ); digitalWrite (13, LOW); } // İLERİ1 if (data [0] =='H') {analogWrite (9, 75); analogWrite (10, 75); digitalWrite (Pino02, LOW); digitalWrite (Pino03, HIGH); digitalWrite (Pino04, LOW); digitalWrite (Pino05, HIGH); digitalWrite (12, ВЫСОКИЙ); digitalWrite (13, LOW); } // İLERİ2 if (data [0] =='I') {analogWrite (9, 125); analogWrite (10, 125); digitalWrite (Pino02, LOW); digitalWrite (Pino03, HIGH); digitalWrite (Pino04, LOW); digitalWrite (Pino05, HIGH); digitalWrite (12, ВЫСОКИЙ); digitalWrite (13, LOW); } // İLERİ3 if (data [0] =='K') {analogWrite (9, 175); analogWrite (10, 175); digitalWrite (Pino02, LOW); digitalWrite (Pino03, HIGH); digitalWrite (Pino04, LOW); digitalWrite (Pino05, HIGH); digitalWrite (12, ВЫСОКИЙ); digitalWrite (13, LOW); } // İLERİ4 if (data [0] =='L') {analogWrite (9, 225); analogWrite (10, 225); digitalWrite (Pino02, LOW); digitalWrite (Pino03, HIGH); digitalWrite (Pino04, LOW); digitalWrite (Pino05, HIGH); digitalWrite (12, ВЫСОКИЙ); digitalWrite (13, LOW); } // İLERİ5 if (data [0] =='U') {digitalWrite (Pino02, LOW); digitalWrite (Pino03, LOW); digitalWrite (Pino04, LOW); digitalWrite (Pino05, LOW); digitalWrite (12, LOW); digitalWrite (13, LOW); } // DUR if (data [0] =='E') {analogWrite (9, 50); analogWrite (10, 50); digitalWrite (Pino02, LOW); digitalWrite (Pino03, HIGH); digitalWrite (Pino04, LOW); digitalWrite (Pino05, HIGH); } // YAVAŞ İLERİ if (data [0] =='F') {analogWrite (9, 50); analogWrite (10, 50); digitalWrite (Pino02, HIGH); digitalWrite (Pino03, LOW); digitalWrite (Pino04, HIGH); digitalWrite (Pino05, LOW); } // ЯВА ГЕРИ}