-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathL293.cpp
More file actions
42 lines (36 loc) · 814 Bytes
/
L293.cpp
File metadata and controls
42 lines (36 loc) · 814 Bytes
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
37
38
39
40
41
42
#include "arduino.h"
#include "L293.h"
L293::L293(uint8_t hiPin, uint8_t loPin, uint8_t pulsePin)
{
positive = hiPin;
negative = loPin;
pwm = pulsePin;
pinMode(positive, OUTPUT);
pinMode(negative, OUTPUT);
pinMode(pwm, OUTPUT);
}
void L293::setState(int8_t speedDigit, float moveDuration)
{
if (speedDigit < 0)
{
digitalWrite(positive, LOW);
digitalWrite(negative, HIGH);
speedy(speedDigit - speedDigit * 2);
}
else if (speedDigit > 0)
{
digitalWrite(negative, LOW);
digitalWrite(positive, HIGH);
speedy(speedDigit);
}
else
{
digitalWrite(negative, LOW);
digitalWrite(positive, LOW);
}
delay(moveDuration * 1000);
}
void L293::speedy(uint8_t outOfTen)
{
analogWrite(pwm, outOfTen * 25 + 5);
}