Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- char letra;
- const int pot = A0;
- int pin1 = 9; // motor A
- int pin2 = 8; // MOtor A
- int pin3 = 6;
- int pin4 = 7;
- int pin5 = 5;
- int pin6 = 4;
- int states = LOW;
- int pos = 0 ;
- int p = 0;
- void setup() {
- Serial.begin(9600);
- pinMode(pin1,OUTPUT);
- pinMode(pin2,OUTPUT);
- pinMode(pin3,OUTPUT);
- pinMode(pin4,OUTPUT);
- pinMode(pin5,OUTPUT);
- pinMode(pin6,OUTPUT);
- pinMode(pot,INPUT);
- }
- void loop() {
- int val = analogRead(pot);
- pos = map(val,0,1023,0,100);
- Serial.println(pos);
- delay(100);
- letra = Serial.read();
- switch(letra){
- case 'w':
- Serial.println("MOTOR A and B RUN ");
- digitalWrite(pin1,HIGH); // Motor A
- digitalWrite(pin2,LOW); // Motor A
- digitalWrite(pin3,HIGH);
- digitalWrite(pin4,LOW);
- break;
- case 's':
- Serial.println("MOTOR A and B BACK ");
- digitalWrite(pin1,LOW); // Motor A
- digitalWrite(pin2,HIGH); // Motor A
- digitalWrite(pin3,LOW); // MOtor B
- digitalWrite(pin4,HIGH); // MOtor B
- break;
- case 'p':
- Serial.println("MOTOR A and B STOP ");
- digitalWrite(pin1,LOW); // Motor A
- digitalWrite(pin2,LOW); // Motor A
- digitalWrite(pin3,LOW); // MOtor B
- digitalWrite(pin4,LOW); // MOtor B
- digitalWrite(pin5,LOW); // MOtor B
- digitalWrite(pin6,LOW); // MOtor B
- break;
- case 'd':
- Serial.println("MOTOR 3 DIRECAO: (DIREITA)");
- digitalWrite(pin5,LOW);
- digitalWrite(pin6,HIGH);
- delay(40);
- digitalWrite(pin5,LOW);
- digitalWrite(pin6,LOW);
- delay(40);
- break;
- case 'a':
- Serial.println("MOTOR 3 DIRECAO: (ESQUERDA");
- digitalWrite(pin5,HIGH);
- digitalWrite(pin6,LOW);
- delay(40);
- digitalWrite(pin5,LOW);
- digitalWrite(pin6,LOW);
- delay(40);
- states = HIGH;
- /*** Serial.println("MOTO A RIGHT and MOTOR B LEFTp");
- digitalWrite(pin1,LOW); // Motor A
- digitalWrite(pin2,HIGH); // Motor A
- digitalWrite(pin3,HIGH);
- // 70167
- digitalWrite(pin4,LOW);
- */
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement