Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- Servo servo1;
- Servo servo2;
- Servo servo3;
- Servo servo4;
- char buffer[4];
- int received;
- void setup(){
- //Inicia a porta serial
- Serial.begin(9600);
- //Atribui as entradas do Arduino
- //as variaveis
- servo1.attach(13); //garra
- servo2.attach(12); //pulso
- servo3.attach(11); //base
- servo4.attach(10); //cotovelo
- received = 0;
- buffer[received] = '\0';
- }
- void loop(){
- //Verifica se possui alguma entrada de dados
- //na entrada Serial
- if(Serial.available()){
- char c = Serial.read();
- // Se o "c" for igual ao caracter "A" (97 na tabela ASCII)
- if(c == 97){
- Serial.println(buffer);
- int numero = atoi(buffer);
- if(numero <= 30){
- servo1.write(numero);
- received = 0;
- }
- // Se o "c" for igual ao caracter "B" (98 na tabela ASCII)
- if(c == 98){
- Serial.println(buffer);
- int numero = atoi(buffer);
- if(numero <= 60){
- servo2.write(numero);
- received = 0;
- }
- received = 0;
- }
- // Se o "c" for igual ao caracter "C" (99 na tabela ASCII)
- if(c == 99){
- Serial.println(buffer);
- int numero = atoi(buffer);
- if(numero >= 360){
- servo3.write(numero);
- received = 0;
- }
- received = 0;
- }
- // Se o "c" for igual ao caracter "D" (100 na tabela ASCII)
- if(c == 99){
- Serial.println(buffer);
- int numero = atoi(buffer);
- if(numero <= 120){
- servo4.write(numero);
- received = 0;
- }
- received = 0;
- }
- if(c != 97 && c != 98 && c != 99 && c != 100){
- buffer[received++] = c;
- }
- Serial.flush();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement