-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple.ino
36 lines (30 loc) · 868 Bytes
/
simple.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <L298N.h>
// global constants
const uint8_t PIN_ENABLE = 9;
const uint8_t PIN_INPUT1 = 7;
const uint8_t PIN_INPUT2 = 8;
L298N driver(PIN_ENABLE, PIN_INPUT1, PIN_INPUT2);
void setup()
{
// L298N class instantiation fully handles the motor driver setup
Serial.begin(9600);
}
/**
* Main program for triggering a DC motor using the L298N module.
* The following movement sequence is initiated continuously:
* - Motor rotates clockwise for 3 seconds at max speed (255)
* - Motor stops and stays idle for 2 seconds
* - Motor rotates counterclockwise for 3 seconds at max speed (255)
* - Motor stops and stays idle for 2 seconds
*/
void loop()
{
driver.run(ROTATE_CLOCKWISE, ROTATE_MAX_SPEED);
delay(3000);
driver.stop();
delay(2000);
driver.run(ROTATE_COUNTERCLOCKWISE, ROTATE_MAX_SPEED);
delay(3000);
driver.stop();
delay(2000);
}