-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathparticle.c
48 lines (34 loc) · 1.09 KB
/
particle.c
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
// Define the pin to be controlled
int relay_pin = D7;
//temperature sensor attached to pin A7
int temperaturePin = A7; //temperature sensor pin
double temperature = 0.0;
// This routine runs only once upon reset
void setup()
{
//Register the temperature variable so it's available through the Particle Cloud API
Spark.variable("temperature", &temperature, DOUBLE);
//Register the function so it's available through the Particle Cloud API
Spark.function("relay", pinControl);
// Set relay pin to OUTPUT
pinMode(relay_pin,OUTPUT);
//Set temperature pin to INPUT
pinMode(temperaturePin, INPUT);
}
// This routine loops forever
void loop()
{
// Read the temperature periodically:
temperature = (analogRead(temperaturePin) * 3.3) / 4095; //getting the voltage reading from the temperature sensor
temperature = (temperature - 0.5) * 100; //turn the voltage into a Celcius reading
delay(2000);
}
// Control the pin
int pinControl(String command)
{
// Get state
int state = command.toInt();
// Apply command
digitalWrite(relay_pin,state);
return 1;
}