Skip to content

Commit 2939c82

Browse files
committed
Created StopTest
1 parent 763b651 commit 2939c82

File tree

3 files changed

+104
-0
lines changed

3 files changed

+104
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#include "MotorControls.h"
2+
3+
#include <Arduino.h>
4+
5+
MotorControls::MotorControls() {
6+
pinMode(bcc_pin, OUTPUT);
7+
digitalWrite(bcc_pin, LOW);
8+
delay(20);
9+
stop();
10+
}
11+
12+
void MotorControls::write(short duration) const {
13+
if (duration > 20) {
14+
return;
15+
}
16+
digitalWrite(bcc_pin, HIGH);
17+
delay(duration);
18+
digitalWrite(bcc_pin, LOW);
19+
delay(20 - duration);
20+
}
21+
22+
void MotorControls::leftOverride() {
23+
state = LEFT_OVERRIDE;
24+
write(6);
25+
}
26+
27+
void MotorControls::rightOverride() {
28+
state = RIGHT_OVERRIDE;
29+
write(8);
30+
}
31+
32+
void MotorControls::go() {
33+
state = GOING;
34+
write(4);
35+
}
36+
37+
void MotorControls::stop() {
38+
state = STOPPED;
39+
write(2);
40+
}
41+
42+
void MotorControls::reducePower() {
43+
write(12);
44+
}
45+
46+
void MotorControls::halfPower() {
47+
write(16);
48+
}
49+
50+
void MotorControls::fullPower() {
51+
write(18);
52+
}
53+
54+
MotorState MotorControls::getState() const {
55+
return state;
56+
}
57+

ArduinoTest/StopTest/MotorControls.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#pragma once
2+
3+
enum MotorState {
4+
STOPPED,
5+
GOING,
6+
LEFT_OVERRIDE,
7+
RIGHT_OVERRIDE
8+
};
9+
10+
class MotorControls {
11+
private:
12+
static const short bcc_pin = 3;
13+
14+
MotorState state = STOPPED;
15+
16+
void write(short duration) const;
17+
18+
public:
19+
MotorControls();
20+
void leftOverride();
21+
void rightOverride();
22+
void go();
23+
void stop();
24+
void reducePower();
25+
void halfPower();
26+
void fullPower();
27+
MotorState getState() const;
28+
};

ArduinoTest/StopTest/StopTest.ino

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "MotorControls.h"
2+
3+
void setup()
4+
{
5+
delay(1000);
6+
MotorControls motor;
7+
motor.go();
8+
motor.fullPower();
9+
delay(500);
10+
motor.halfPower();
11+
delay(500);
12+
motor.reducePower();
13+
motor.reducePower();
14+
motor.reducePower();
15+
delay(100);
16+
motor.stop();
17+
}
18+
19+
void loop() { }

0 commit comments

Comments
 (0)