-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrol.cpp
executable file
·70 lines (60 loc) · 1006 Bytes
/
control.cpp
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
59
60
61
62
63
64
65
66
67
68
69
70
/*
* Name: control.cpp
*/
#include "control.h"
void Timer::start(unsigned long delay_mS)
{
timeout = millis() + delay_mS;
}
int Timer::complete()
{
return (millis() > timeout);
}
void Control::setup(void)
{
/* Init protothread state. */
brightOut = 5;
}
int Control::get_brightness()
{
return brightOut;
}
void Control::bump_y(int y)
{
if(y > 5000)
{
Ty.start(500); // 1/2 second
Serial.println("DOWN");
brightOut -= 10;
if (brightOut < 0)
brightOut = 0;
}
else if (y < -1000)
{
Ty.start(500); // 1/2 second
Serial.println("UP");
brightOut += 10;
if (brightOut > 100)
brightOut = 100;
}
}
void Control::bump_x(int x)
{
if(x > 3000)
{
Tx.start(500); // 1/2 second
Serial.println("LEFT");
}
else if (x < -2000)
{
Tx.start(500); // 1/2 second
Serial.println("RIGHT");
}
}
void Control::use_accel(int x, int y)
{
if (Tx.complete())
bump_x(x);
if (Ty.complete())
bump_y(y);
}