-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVarmetest.ino
113 lines (94 loc) · 2.91 KB
/
Varmetest.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
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
#include <Adafruit_NeoPixel.h>
char intBuffer[12];
String intData = "";
int delimiter = (int) '\n';
const int sensorPin0 = A0;
const int sensorPin1 = A1;
const int sensorPin2 = A2;
const int sensorPin3 = A3;
int temp0;
int temp1;
int temp2;
int temp3;
int userHeat;
unsigned int integerValue= 0;
char incomingByte;
long time;
long timeSystem;
#define PIN 6
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);
void setup()
{
Serial.begin(9600);
//Serial.print("AT+BAUD4");
pinMode(4,OUTPUT);
strip.begin();
strip.show();
timeSystem = millis();
}
void loop() {
temp0 = getTemp(sensorPin0); //Left arm
temp1 = getTemp(sensorPin1); //Left side
temp2 = getTemp(sensorPin2); //Right arm
temp3 = getTemp(sensorPin3); //Right side
int tempFinal = (temp0 + temp1 + temp2 + temp3) / 4; //Average temp
char input = Serial.read();
if (input == 'a') {
while(Serial.read() != 'b') {
theaterChase(strip.Color(255, 0, 0), 10);
tone(8, 1000, 50);
}
strip.show();
}
if (input == 'c') {
while (Serial.available() == 0) {
}
integerValue = 0; // throw away previous integerValue
while(1) { // force into a loop until 'n' is received
incomingByte = Serial.read();
if (incomingByte == '!') break; // exit the while(1), we're done receiving
if (incomingByte == -1) continue; // if no characters are in the buffer read() returns -1
integerValue *= 10; // shift left 1 decimal place
// convert ASCII to integer, add, and shift left 1 decimal place
integerValue = ((incomingByte - 48) + integerValue);
}
// Do something with the value
userHeat = integerValue;
}
/*tempFinal*/
if (tempFinal <= userHeat && userHeat != 0) { //If the average temperature is below 35C, then the heating pads will be turned on
digitalWrite(4, HIGH);
} else {
digitalWrite(4, LOW);
}
time = millis();
if ((time - timeSystem) >= 1000) {
Serial.print("c" + String(tempFinal) + "!");
timeSystem = millis();
}
}
int getTemp(int pin) {
//getting the voltage reading from the temperature sensor
int reading = analogRead(pin);
// converting that reading to voltage, for 3.3v arduino use 3.3
float voltage = (reading/1024.0) * 5.0;
// now print out the temperature
float temperatureC = (voltage - .5) * 100 ; //converting from 10 mv per degree wit 500 mV offset
//to degrees ((voltage - 500mV) times 100)
return temperatureC;
}
//Theatre-style crawling lights.
void theaterChase(uint32_t c, uint8_t wait) {
for (int j=0; j<10; j++) { //do 10 cycles of chasing
for (int q=0; q < 3; q++) {
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, c); //turn every third pixel on
}
strip.show();
delay(wait);
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, 0); //turn every third pixel off
}
}
}
}