-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBikeModule.ino
More file actions
71 lines (67 loc) · 2.55 KB
/
BikeModule.ino
File metadata and controls
71 lines (67 loc) · 2.55 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
59
60
61
62
63
64
65
66
67
68
69
70
int leftin = 1; // Left signal wire connected to pin A1
int rightin = 3; // Right signal wire connected to pin A3
int brakein = 5; // Brake signal wire connected to pin A5
boolean brake = false; // Brake ON initialized as false
int signalSensitivity = 128; // Sensitivity to line being energized or not(lower number more sensitive)
String lastSent = "LL"; // Last value sent(initialized as lights ON)
String leftout = "L"; // Left blinker check results(initialized as light OFF)
String rightout = "L"; // Right blinker check results(initialized as light OFF)
void setup() {
pinMode(leftin, INPUT); // Pin A1 as INPUT
pinMode(rightin, INPUT); // Pin A3 as INPUT
pinMode(brakein, INPUT); // Pin A5 as INPUT
Serial.begin(9600); // Start serial communication at 9600bps
}
void loop() {
// Determine if brake light is ON or OFF
if ( analogRead(brakein) > signalSensitivity )
{
leftout = "H"; // Setting left as High
rightout = "H"; // Setting right as High
brake = true; // Setting Brake ON as true
}
else
{
leftout = "L"; // Setting left as Low
rightout = "L"; //Setting left as low
brake = false; // Setting Brake ON as false
}
// Determine if left blinker is ON or OFF
if ( analogRead(leftin) > signalSensitivity ) // If leftin meets our signalSensitivity threshold
{
if ( brake ) // If brake is true(ON)
{
leftout = "L"; // Set left as Low
}
else // If brake is false(OFF) but signalSensitivity threshold met(Left ON)
{
leftout = "H"; // Set left as High
}
}
else if ( !brake ) // If leftin does not meet the signalSensitivity threshold and brake is false(OFF)
{
leftout = "L"; // Set left as Low
}
// Determine if right binker is ON or OFF
if ( analogRead(rightin) > signalSensitivity ) // If rightin meets our signalSensitivity threshold
{
if ( brake ) // If brake is true(ON)
{
rightout = "L"; // Set right as Low
}
else // If brake is false(OFF) but signalSensitivity threshold met(Right ON)
{
rightout = "H"; // Set right as High
}
}
else if ( !brake ) // If rightin does not meet the signalSensitivity threshold and brake is false(OFF)
{
rightout = "L"; // Set right as Low
}
if ( lastSent != leftout + rightout ) // If current signals do not match what was last sent, send updated signals
{
Serial.print(leftout + rightout + '\n'); // Send signal to receiving unit
lastSent = leftout + rightout; // Update lastSent with what we just sent to the receiving unit
}
delay(10); // Wait 10 nanoseconds before looping
}