-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserial.ino
More file actions
57 lines (50 loc) · 1.88 KB
/
serial.ino
File metadata and controls
57 lines (50 loc) · 1.88 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
void SerialLoop() {
// if (print) {
// print = false;
// if (workingCapacitives == body) {
// Serial.println("");
// Serial.print(millis()); Serial.print(",");
// for(int i=0;i<N_BODY_SENSORS-1;i++){
// Serial.print(bodySensorValue[i]); Serial.print(","); //Serial.print(calibration[i]); Serial.print(",");
// }
// Serial.print(bodySensorValue[N_BODY_SENSORS-1]);
// Serial.print(",");
// Serial.print(touchState);
// //Serial.print(millis() - startTouchingTime);
// }
// }
// if (workingCapacitives == head) {
// Serial.print(headSensorValue[0]); Serial.print(" "); Serial.print(headSensorValue[1]); Serial.print(" ");
// Serial.print(headSensorValue[2]); Serial.print(" "); Serial.print(headSensorValue[3]); Serial.print(" "); Serial.println(pressedButton);
// }
reciveSerial();
sendSerial();
}
void reciveSerial() {
if (Serial.available()) {
int b = Serial.read();
switch (b) {
case 0: workingCapacitives = noOne; capStateStartTime=millis();break;
case 1: workingCapacitives = head;resetHeadCapacitives();capStateStartTime=millis(); break;
case 2: resetCapacitives(); bodyStartTime=millis(); workingCapacitives = body;capStateStartTime=millis();chooseThreshold(); break;
case 3: workingCapacitives = both;capStateStartTime=millis(); break;
}
}
}
void sendSerial() {
if (workingCapacitives == head && pressedButton != -1) {
Serial.write(4);
Serial.write(pressedButton);
}
//i vari abbracci , carezze e colpi vengono scritti su seriale direttamente dalle funzioni di body_capacitives
//scrivo 1 per abbraccio, 2 per carezza, 3 per colpo e 4 per bottone
}
void chooseThreshold(){
if(Serial.read()==5) setThreshold(400);
else if(Serial.read()==4) setThreshold(150);
}
void setThreshold(int value){
for(int i=0; i<N_BODY_SENSORS;i++){
lowBodyThreshold[i]=value;
}
}