-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhardwareactuation.cpp
119 lines (104 loc) · 2.11 KB
/
hardwareactuation.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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
// Written by Alex Yoon
// Use for CMU Build18 Hackathon 2022 Magic Bin Project
#include <Servo.h>
#include <Wire.h>
#include <SerLCD.h>
Servo left;
Servo right;
SerLCD lcd;
const int button1 = 2;
const int button2 = 1;
int buttonstate1 = 0;
int buttonstate2 = 0;
int pos = 95;
String nom = "Arduino";
String msg;
void setup() {
Wire.begin();
lcd.begin(Wire);
left.attach(9);
right.attach(10);
pinMode(button1, INPUT);
pinMode(button1, INPUT);
Serial.begin(9600);
}
void readSerialPort() {
msg = "";
if (Serial.available()) {
delay(10);
while (Serial.available() > 0) {
msg += (char)Serial.read();
lcd.print(Serial.read());
}
Serial.flush();
delay(5000);
lcd.clear();
}
}
void printSerialChar() {
if (Serial.available()) {
delay(10);
while (Serial.available() > 0) {
Serial.print((char)Serial.read());
}
delay(8000);
Serial.flush();
}
}
void sendData() {
//write data
Serial.print(nom);
Serial.print(" received : ");
Serial.print(msg);
}
void loop() {
readSerialPort();
buttonstate1 = digitalRead(button1);
buttonstate2 = digitalRead(button2);
/*
if (Serial.available()) {
delay(100);
lcd.clear();
while (Serial.available()>0) {
lcd.write(Serial.read());
}
delay(3000);
}
*/
if ((msg != "B" and msg != "") || buttonstate1 == HIGH)
{
sendData();
for (pos = 95; pos <= 180; pos += 1)
{
left.write(pos);
right.write(180-pos);
delay(10);
}
delay(1500);
for (pos = 180; pos >= 95; pos -= 1)
{
left.write(pos);
right.write(180-pos);
delay(10);
}
//printSerialChar();
// added
}
else if (msg == "B" || buttonstate2 == HIGH)
{
sendData();
for (pos = 95; pos >= 0; pos -= 1)
{
left.write(pos);
right.write(180-pos);
delay(10);
}
delay(1500);
for (pos = 0; pos <= 95; pos += 1)
{
left.write(pos);
right.write(180-pos);
delay(10);
}
}
}