-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBentobot.cpp
More file actions
executable file
·58 lines (51 loc) · 1.28 KB
/
Bentobot.cpp
File metadata and controls
executable file
·58 lines (51 loc) · 1.28 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
#include <wiringPi.h>
using namespace std;
void MotorControl(int p1);
int main()
{
int pulse1;
cout << "Input value for motor 1: ";
cin >> pulse1;
MotorControl(pulse1);
}
void MotorControl(int p1)
{
// Control the motors
// pin1 = direction of motor 1
// pin2 = steps of motor 1
// pin3 = direction of motor 2
// pin4 = steps of motor 2
wiringPiSetup();
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
bool isP1On = false;
// Directions for motors
// assume that pin 1/pin 3 on is cw
if (p1 > 0 && !isP1On)
{
//turn on pin 1
digitalWrite(1, HIGH); // turn on pin1
// turn on pin 3
digitalWrite(3, HIGH); // turn on pin3
isP1On = true;
}
else if (p1 < 0 && isP1On)
{
digitalWrite(1, HIGH);
digitalWrite(3, HIGH);
isP1On = false;
}
// Steps for motor
for (int i = 0; i < abs(p1); i++)
{
// motor 1
digitalWrite(2, HIGH); delay(2.5); // turn on pin2
digitalWrite(2, LOW); delay(2.5); // turn off pin2
// motor 2
digitalWrite(4, HIGH); delay(2.5); // turn on pin4
digitalWrite(4, LOW); delay(2.5); // turn off pin4
}
}