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

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

Title Name Language When
Arduino Nano L293D ColdSphinX cpp 7 Years ago.
Arduino Nano L293D ColdSphinX cpp 7 Years ago.