-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindow_controller.ino
More file actions
106 lines (92 loc) · 2.38 KB
/
window_controller.ino
File metadata and controls
106 lines (92 loc) · 2.38 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <EEPROM.h>
#define POSITIVE_PIN 9
#define NEGATIVE_PIN 11
#define STORE_ADDRESS 0
const int postiveValue = 50;
const int stopValue = 25;
const int negativeValue = 10;
const String postiveReceiveCommand = "@POSITIVE$";
const String stopReceiveCommand = "@STOP$";
const String negativeReceiveCommand = "@NEGATIVE$";
const String queryReceiveCommand = "@???$";
const String postiveReturnCommand = "!POSITIVE$";
const String stopReturnCommand = "!STOP$";
const String negativeReturnCommand = "!NEGATIVE$";
int currentState;
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
pinMode(POSITIVE_PIN, OUTPUT);
pinMode(NEGATIVE_PIN, OUTPUT);
Serial1.begin(9600);
reset();
switch (currentState) {
case postiveValue:
positive();
break;
case stopValue:
stop();
break;
default:
negative();
break;
}
}
void reset() {
currentState = EEPROM.read(STORE_ADDRESS);
digitalWrite(LED_BUILTIN, LOW);
digitalWrite(POSITIVE_PIN, LOW);
digitalWrite(NEGATIVE_PIN, LOW);
}
void stop() {
digitalWrite(LED_BUILTIN, LOW);
digitalWrite(POSITIVE_PIN, LOW);
digitalWrite(NEGATIVE_PIN, LOW);
currentState = stopValue;
EEPROM.update(STORE_ADDRESS, currentState);
Serial1.println(stopReturnCommand);
}
void positive() {
digitalWrite(LED_BUILTIN, HIGH);
digitalWrite(POSITIVE_PIN, HIGH);
digitalWrite(NEGATIVE_PIN, LOW);
currentState = postiveValue;
EEPROM.update(STORE_ADDRESS, currentState);
Serial1.println(postiveReturnCommand);
}
void negative() {
digitalWrite(LED_BUILTIN, LOW);
digitalWrite(POSITIVE_PIN, LOW);
digitalWrite(NEGATIVE_PIN, HIGH);
currentState = negativeValue;
EEPROM.update(STORE_ADDRESS, currentState);
Serial1.println(negativeReturnCommand);
}
void loop()
{
while (Serial1.available()) {
String command = Serial1.readString();
if (command.startsWith(postiveReceiveCommand)) {
positive();
}
if (command.startsWith(negativeReceiveCommand)) {
negative();
}
if (command.startsWith(stopReceiveCommand)) {
stop();
}
if (command.startsWith(queryReceiveCommand)) {
switch (currentState) {
case postiveValue:
Serial1.println(postiveReturnCommand);
break;
case stopValue:
Serial1.println(stopReturnCommand);
break;
default:
Serial1.println(negativeReturnCommand);
break;
}
}
}
}