Advertisement
AverageMan

Wemoto Starter Code

Sep 25th, 2018
611
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. /**
  3. If you motors turn the wrong way, switch the wires over
  4. Pin translation for using the Wemos with the Arduino IDE:
  5. *
  6. Wemos D1 mini Pin Number           Arduino IDE Pin Number
  7. D0                                  16
  8. D1                                  5
  9. D2                                  4
  10. D3                                  0
  11. D4                                  2
  12. D5                                  14
  13. D6                                  12
  14. D7                                  13
  15. D8                                  15
  16. TX                                   1
  17. RX                                   3
  18. **/
  19.  
  20. //Define Pins
  21. //Motor A
  22. int enableA = 0; //D3
  23. int MotorA1 = 4; //D2
  24. int MotorA2 = 5; //D1
  25.  
  26. //Motor B
  27. int enableB = 16; //D0
  28. int MotorB1 = 14; //D5
  29. int MotorB2 = 2; //D4
  30.  
  31. void setup() {
  32.   //configure pin modes
  33.   pinMode (enableA, OUTPUT);
  34.   pinMode (MotorA1, OUTPUT);
  35.   pinMode (MotorA2, OUTPUT);  
  36.   pinMode (enableB, OUTPUT);
  37.   pinMode (MotorB1, OUTPUT);
  38.   pinMode (MotorB2, OUTPUT);  
  39. }
  40.  
  41. void loop() {
  42.   //Enable motors
  43.   digitalWrite (enableA, HIGH);
  44.   digitalWrite (enableB, HIGH);
  45.   delay (1000);
  46.  
  47.   //Go forward for 1 second
  48.   digitalWrite (MotorA1, LOW);
  49.   digitalWrite (MotorA2, HIGH);
  50.   digitalWrite (MotorB1, LOW);
  51.   digitalWrite (MotorB2, HIGH);
  52.  
  53.   delay (1000);
  54.  
  55.   //Go backwards for 2 seconds
  56.   digitalWrite (MotorA1,HIGH);
  57.   digitalWrite (MotorA2,LOW);  
  58.   digitalWrite (MotorB1,HIGH);
  59.   digitalWrite (MotorB2,LOW);  
  60.  
  61.   delay (2000);
  62.  
  63.  
  64.   //Stop all motors then stop for 5 seconds
  65.   digitalWrite (enableA, LOW);
  66.   digitalWrite (enableB, LOW);
  67.   delay (5000);
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement