From Crimson Cassowary, 3 Years ago, written in C++.
This paste is a reply to Re: Re: Arduino Nano L293D from Ungracious Owl - view diff
Embed
  1. //L293D
  2. //Motor A (left)
  3. #define MOTOR_PIN1 9
  4. #define MOTOR_PIN2 10
  5. //Motor B (right)
  6. #define MOTOR_PIN3 11
  7. #define MOTOR_PIN4 12
  8.  
  9. #define TIME_WAIT 7200 //10sec
  10.  
  11. void setup() {
  12.   //Set pins as outputs
  13.   pinMode(MOTOR_PIN1, OUTPUT);
  14.   pinMode(MOTOR_PIN2, OUTPUT);
  15.   pinMode(MOTOR_PIN3, OUTPUT);
  16.   pinMode(MOTOR_PIN4, OUTPUT);
  17. }
  18.  
  19. void motor_a_stop() {
  20.   digitalWrite(MOTOR_PIN1, LOW);
  21.   digitalWrite(MOTOR_PIN2, LOW);
  22. }
  23.  
  24. void motor_a_forward() {
  25.   digitalWrite(MOTOR_PIN1, LOW);
  26.   digitalWrite(MOTOR_PIN2, HIGH);
  27. }
  28.  
  29. void motor_a_backward() {
  30.   digitalWrite(MOTOR_PIN1, HIGH);
  31.   digitalWrite(MOTOR_PIN2, LOW);
  32. }
  33.  
  34. void motor_b_stop() {
  35.   digitalWrite(MOTOR_PIN3, LOW);
  36.   digitalWrite(MOTOR_PIN4, LOW);
  37. }
  38.  
  39. void motor_b_forward() {
  40.   digitalWrite(MOTOR_PIN3, LOW);
  41.   digitalWrite(MOTOR_PIN4, HIGH);
  42. }
  43.  
  44. void motor_b_backward() {
  45.   digitalWrite(MOTOR_PIN3, HIGH);
  46.   digitalWrite(MOTOR_PIN4, LOW);
  47. }
  48.  
  49. void left_stop() {
  50.   motor_a_stop();
  51. }
  52.  
  53. void right_stop() {
  54.   motor_b_stop();
  55. }
  56.  
  57. void stop() {
  58.   left_stop();
  59.   right_stop();
  60. }
  61.  
  62. void left_forward() {
  63.   motor_a_backward();
  64. }
  65.  
  66. void left_backward() {
  67.   motor_a_forward();
  68. }
  69.  
  70. void right_forward() {
  71.   motor_b_forward();
  72. }
  73.  
  74. void right_backward() {
  75.   motor_b_backward();
  76. }
  77.  
  78. void forward() {
  79.   left_forward();
  80.   right_forward();
  81. }
  82.  
  83. void backward() {
  84.   left_backward();
  85.   right_backward();
  86. }
  87.  
  88. void left_rotate() {
  89.   left_backward();
  90.   right_forward();
  91. }
  92.  
  93. void right_rotate() {
  94.   left_forward();
  95.   right_backward();
  96. }
  97.  
  98. void left_circle() {
  99.   left_stop();
  100.   right_forward();
  101. }
  102.  
  103. void right_circle() {
  104.   right_stop();
  105.   left_forward();
  106. }
  107.  
  108. void wait() {
  109.   delay(TIME_WAIT);
  110.   stop();
  111. }
  112.  
  113. void loop() {
  114.   forward();
  115.   wait();
  116.   backward();
  117.   wait();
  118.   left_rotate();
  119.   wait();
  120.   right_rotate();
  121.   wait();
  122.   left_circle();
  123.   wait();
  124.   right_circle();
  125.   wait();
  126.   stop();
  127.   delay(1800);
  128. }

Replies to Re: Re: Re: Arduino Nano L293D rss

Title Name Language When
Re: Re: Re: Re: Arduino Nano L293D Tiny Earthworm cpp 3 Years ago.