Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1. //Motor A
  2. const int motorPin1  = 10;  // Pino 14 of L293
  3. const int motorPin2  = 9;  // Pino 10 of L293
  4. //Motor B
  5. const int motorPin3  = 7; // Pino  7 of L293
  6. const int motorPin4  = 6;  // Pino  2 of L293
  7.  
  8. void setup(){
  9.  
  10.     //Set pins as outputs
  11.     pinMode(motorPin1, OUTPUT);
  12.     pinMode(motorPin2, OUTPUT);
  13.     pinMode(motorPin3, OUTPUT);
  14.     pinMode(motorPin4, OUTPUT);  
  15. }
  16.  
  17.  
  18. void loop(){
  19.   turnMotorA();
  20.     delay(2000);//Arduino espera este tempo em ms para comecar a próxima linha
  21.   turnMotorB();
  22.     delay(2000);
  23.     turnMotors();
  24.     delay(2000);
  25.  
  26. }
  27. //Declarando funcoes para controle dos motores
  28. void stopMotors(){
  29.   digitalWrite(motorPin1, LOW);
  30.     digitalWrite(motorPin2, LOW);
  31.     digitalWrite(motorPin3, LOW);
  32.     digitalWrite(motorPin4, LOW);
  33. }
  34. void turnMotorA(){
  35.     digitalWrite(motorPin1, LOW);
  36.     digitalWrite(motorPin2, HIGH);
  37.     digitalWrite(motorPin3, LOW);
  38.     digitalWrite(motorPin4, LOW);
  39. }
  40. void turnMotorB(){
  41.   digitalWrite(motorPin1, LOW);
  42.     digitalWrite(motorPin2, LOW);
  43.     digitalWrite(motorPin3, HIGH);
  44.     digitalWrite(motorPin4, LOW);
  45.  
  46. }
  47. void turnMotors(){
  48.   digitalWrite(motorPin1, LOW);
  49.     digitalWrite(motorPin2, HIGH);
  50.     digitalWrite(motorPin3, HIGH);
  51.     digitalWrite(motorPin4, LOW);
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement