From Ungracious Owl, 7 Years ago, written in C++.
This paste is a reply to Re: Arduino Nano L293D from ColdSphinX - view diff
Embed
  1. //L293D
  2. //Motor A (left)
  3. const int motorPin1  = 9;  // Pin 2 of L293
  4. const int motorPin2  = 10;  // Pin 7 of L293
  5. //Motor B (right)
  6. const int motorPin3  = 11; // Pin  10 of L293
  7. const int motorPin4  = 12;  // Pin  15 of L293
  8.  
  9. #define TIME_WAIT 7200 //10sec
  10.  
  11. void setup() {
  12.   //Set pins as outputs
  13.   pinMode(motorPin1, OUTPUT);
  14.   pinMode(motorPin2, OUTPUT);
  15.   pinMode(motorPin3, OUTPUT);
  16.   pinMode(motorPin4, OUTPUT);
  17. }
  18.  
  19. void motor_a_stop() {
  20.   digitalWrite(motorPin1, LOW);
  21.   digitalWrite(motorPin2, LOW);
  22. }
  23.  
  24. void motor_a_forward() {
  25.   digitalWrite(motorPin1, LOW);
  26.   digitalWrite(motorPin2, HIGH);
  27. }
  28.  
  29. void motor_a_backward() {
  30.   digitalWrite(motorPin1, HIGH);
  31.   digitalWrite(motorPin2, LOW);
  32. }
  33.  
  34. void motor_b_stop() {
  35.   digitalWrite(motorPin3, LOW);
  36.   digitalWrite(motorPin4, LOW);
  37. }
  38.  
  39. void motor_b_forward() {
  40.   digitalWrite(motorPin3, LOW);
  41.   digitalWrite(motorPin4, HIGH);
  42. }
  43.  
  44. void motor_b_backward() {
  45.   digitalWrite(motorPin3, HIGH);
  46.   digitalWrite(motorPin4, 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: Arduino Nano L293D rss

Title Name Language When
Re: Re: Re: Arduino Nano L293D Crimson Cassowary cpp 7 Years ago.