Advertisement
tomateblue

TanGOO

Dec 16th, 2017
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.07 KB | None | 0 0
  1. char letra;
  2. const int pot = A0;
  3.  
  4. int pin1 = 9; // motor A
  5. int pin2 = 8; // MOtor A
  6.  
  7.  
  8. int pin3 = 6;
  9. int pin4 = 7;
  10. int pin5 = 5;
  11. int pin6 = 4;
  12.  
  13. int states = LOW;
  14. int pos = 0 ;
  15. int p = 0;
  16. void setup() {
  17.  Serial.begin(9600);
  18.  pinMode(pin1,OUTPUT);
  19.  pinMode(pin2,OUTPUT);
  20.  pinMode(pin3,OUTPUT);
  21.  pinMode(pin4,OUTPUT);
  22.  pinMode(pin5,OUTPUT);
  23.  pinMode(pin6,OUTPUT);
  24.  pinMode(pot,INPUT);
  25. }
  26.  
  27. void loop() {
  28.   int val = analogRead(pot);
  29.   pos = map(val,0,1023,0,100);
  30.   Serial.println(pos);
  31.   delay(100);
  32.   letra = Serial.read();
  33.   switch(letra){
  34.     case 'w':
  35.     Serial.println("MOTOR A and B RUN ");
  36.     digitalWrite(pin1,HIGH);       // Motor A
  37.     digitalWrite(pin2,LOW);       // Motor A
  38.     digitalWrite(pin3,HIGH);
  39.     digitalWrite(pin4,LOW);
  40.     break;
  41.     case 's':
  42.     Serial.println("MOTOR A and B  BACK ");  
  43.     digitalWrite(pin1,LOW);  // Motor A
  44.     digitalWrite(pin2,HIGH);  // Motor A
  45.     digitalWrite(pin3,LOW);   // MOtor B
  46.     digitalWrite(pin4,HIGH);    // MOtor B
  47.     break;
  48.     case 'p':
  49.     Serial.println("MOTOR A and B STOP ");
  50.     digitalWrite(pin1,LOW); // Motor A
  51.     digitalWrite(pin2,LOW); // Motor A
  52.     digitalWrite(pin3,LOW); // MOtor B
  53.     digitalWrite(pin4,LOW);  // MOtor B
  54.     digitalWrite(pin5,LOW); // MOtor B
  55.     digitalWrite(pin6,LOW);  // MOtor B
  56.     break;
  57.  
  58.     case 'd':
  59.  
  60.         Serial.println("MOTOR 3 DIRECAO: (DIREITA)");
  61.         digitalWrite(pin5,LOW);
  62.         digitalWrite(pin6,HIGH);
  63.         delay(40);
  64.         digitalWrite(pin5,LOW);
  65.         digitalWrite(pin6,LOW);
  66.         delay(40);
  67.  
  68.     break;
  69.     case 'a':
  70.      Serial.println("MOTOR 3 DIRECAO: (ESQUERDA");
  71.      digitalWrite(pin5,HIGH);
  72.      digitalWrite(pin6,LOW);
  73.      delay(40);
  74.      digitalWrite(pin5,LOW);
  75.      digitalWrite(pin6,LOW);
  76.      delay(40);
  77.      states = HIGH;
  78.  
  79. /***    Serial.println("MOTO A RIGHT and MOTOR B LEFTp");
  80.     digitalWrite(pin1,LOW);  // Motor A
  81.     digitalWrite(pin2,HIGH);  // Motor A
  82.     digitalWrite(pin3,HIGH);
  83. //    70167
  84.  
  85.     digitalWrite(pin4,LOW);
  86.     */
  87.     break;
  88.  
  89.    
  90.   }
  91.  
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement