From ColdSphinX, 3 Years ago, written in C++.
This paste is a reply to Arduino Nano L293D from ColdSphinX - view diff
Embed
  1. //L293D
  2. //Motor A
  3. const int motorPin1  = 9;  // Pin 14 of L293
  4. const int motorPin2  = 10;  // Pin 10 of L293
  5. //Motor B
  6. const int motorPin3  = 12; // Pin  7 of L293
  7. const int motorPin4  = 11;  // Pin  2 of L293
  8.  
  9. #define TIME_WAIT 15000
  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 left_stop() {
  20.   digitalWrite(motorPin1, LOW);
  21.   digitalWrite(motorPin2, LOW);
  22. }
  23.  
  24. void right_stop() {
  25.   digitalWrite(motorPin3, LOW);
  26.   digitalWrite(motorPin4, LOW);
  27. }
  28.  
  29. void stop() {
  30.   left_stop();
  31.   right_stop();
  32. }
  33.  
  34. void left_forward() {
  35.   digitalWrite(motorPin1, LOW);
  36.   digitalWrite(motorPin2, HIGH);
  37. }
  38.  
  39. void left_backward() {
  40.   digitalWrite(motorPin1, HIGH);
  41.   digitalWrite(motorPin2, LOW);
  42. }
  43.  
  44. void right_forward() {
  45.   digitalWrite(motorPin3, LOW);
  46.   digitalWrite(motorPin4, HIGH);
  47. }
  48.  
  49. void right_backward() {
  50.   digitalWrite(motorPin3, HIGH);
  51.   digitalWrite(motorPin4, LOW);
  52. }
  53.  
  54. void forward() {
  55.   left_forward();
  56.   right_forward();
  57. }
  58.  
  59. void backward() {
  60.   left_backward();
  61.   right_backward();
  62. }
  63.  
  64. void left_rotate() {
  65.   left_backward();
  66.   right_forward();
  67. }
  68.  
  69. void right_rotate() {
  70.   left_forward();
  71.   right_backward();
  72. }
  73.  
  74. void left_circle() {
  75.   left_stop();
  76.   right_forward();
  77. }
  78.  
  79. void right_circle() {
  80.   right_stop();
  81.   left_forward();
  82. }
  83.  
  84. void wait() {
  85.   delay(TIME_WAIT);
  86.   stop();
  87. }
  88.  
  89. void loop() {
  90.   forward();
  91.   wait();
  92.   backward();
  93.   wait();
  94.   left_rotate();
  95.   wait();
  96.   right_rotate();
  97.   wait();
  98.   left_circle();
  99.   wait();
  100.   right_circle();
  101.   wait();
  102.   stop();
  103.   delay(2000);
  104. }

Replies to Re: Arduino Nano L293D rss

Title Name Language When
Re: Re: Arduino Nano L293D Ungracious Owl cpp 3 Years ago.