Hardware Reference
In-Depth Information
Sketch
Use the code in Listing 19-1 for this sketch.
Listing 19-1: Sketch (fi lename: Chapter19.ino )
1 #include <Scheduler.h>
2
3 const int sensorPin = A0; // The analog input pin
4 const int powerPin = 7; // The power socket output pin
5
6 const int rPin = 4; // Red color component
7 const int gPin = 3; // Green color component
8 const int bPin = 2; // Blue color component
9
10 const int maxTemp = 26; // Turn off heater when above this temp
11 const int minTemp = 24; // Turn on heater when below this temp
12
13 int powerPinStatus = LOW; // By default, no power on the AC circuit
14
15 int i; // Temporary variable for if statements
16
17 void setup()
18 {
19 // Serial output at 9600 baud
20 Serial.begin(9600);
21
22 // Configure sensor pin
23 pinMode(sensorPin, INPUT);
24
25 // Start heater and lighting treads
26 Scheduler.startLoop(heatloop);
27 Scheduler.startLoop(lightloop);
28 }
29
30 void loop()
31 {
32 yield(); // Releases the Arduino from the main loop
33 }
34
35 // The loop responsible for checking water temperature
36 void heatloop()
37 {
38 // Get a temperature reading from the temperature sensor
39 // 3.3V on the due
40 int tempC = ( 3.3 * analogRead(sensorPin) * 100.0) / 1024.0;
41
42 // Send the temperature reading out the serial port
43 Serial.print("Temperature: ");
44 Serial.println(tempC);
45
46 // Check to see if we need to change the output
47 if (powerPinStatus == LOW)
 
Search WWH ::




Custom Search