-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGlove.ino
84 lines (62 loc) · 1.65 KB
/
Glove.ino
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
#include <SoftwareSerial.h>
SoftwareSerial bluetooth(2, 3); // RX, TX
const int motorPin = 4;
const int buzzerPin = 5;
const int ringInterruptPin = 12;
bool interruptButtonState = false;
int ring[][2] = {
{1000,200},
{600,200},
{300,100},
{200,100},
{100,100},
{50,100}};
int intensity = 0;
void setup() {
pinMode(motorPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
pinMode(ringInterruptPin, INPUT);
Serial.begin(115200);
bluetooth.begin(115200);
digitalWrite(buzzerPin, HIGH);
}
void loop() {
if (bluetooth.available()) {
char bluetoothRead = bluetooth.read();
intensity = bluetoothRead - ‘0’;
Serial.println(String(intensity));
updateInterrupState();
if (intensity <= 5 && intensity >= 0 && !interruptButtonState) {
ringWithIntensity(intensity);
} else if (interruptButtonState) {
bluetooth.write(“Giozinho”);
while(bluetooth.read() != ‘e’){}
interruptButtonState = false;
}
}
}
void ringWithIntensity(int intensity) {
Serial.println(String(intensity));
digitalWrite(motorPin, HIGH);
slicedDelay(ring[intensity][1]);
digitalWrite(motorPin, LOW);
slicedDelay(ring[intensity][0]);
}
void updateInterrupState() {
if (digitalRead(ringInterruptPin) == HIGH) {
interruptButtonState = true;
}
}
void slicedDelay(int timeInterval) {
int timeSlice = timeInterval/5;
delay(timeSlice);
updateInterrupState();
delay(timeSlice);
updateInterrupState();
delay(timeSlice);
updateInterrupState();
delay(timeSlice);
updateInterrupState();
delay(timeSlice);
updateInterrupState();
}