Created
August 8, 2011 17:35
-
-
Save davisford/1132256 to your computer and use it in GitHub Desktop.
Hygro Petal => Useful Sensor Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// __________________ FUNCTION DECLARATIONS _________________________________ | |
void led_on(); | |
void led_off(); | |
void readDataOnce(); | |
char * readSensors(); | |
messengerCallbackFunction messengerCallbacks[] = | |
{ | |
led_on, // 004 | |
led_off, // 005 | |
readDataOnce, // 006 | |
NULL | |
}; | |
// __________________ PROGRAM CONSTANTS _____________________________________ | |
const int power = A2; | |
const int moisture = A5; | |
const int light = A4; | |
const int temp = A6; | |
// __________________ C A L L B A C K M E T H O D S __________________________ | |
// command 4 | |
void led_on() | |
{ | |
digitalWrite(5, HIGH); | |
cmdMessenger.sendCmd(kACK, "LED should be on"); | |
} | |
// command 5 | |
void led_off() | |
{ | |
digitalWrite(5, LOW); | |
cmdMessenger.sendCmd(kACK, "LED should be off"); | |
} | |
// command 6 | |
void readDataOnce() { | |
cmdMessenger.sendCmd(kACK, readSensors()); | |
} | |
char *readSensors() { | |
digitalWrite(power, LOW); // on | |
delay(500); | |
static char data[15]; | |
char val[4]; | |
// read light | |
itoa(analogRead(light), data, 10); | |
// read moisture | |
itoa(analogRead(moisture), val, 10); | |
strcat(data, ","); | |
strcat(data, val); | |
// read temp | |
itoa(analogRead(temp), val, 10); | |
strcat(data, ","); | |
strcat(data, val); | |
// turn off power to save power; avoid heating, corrosion | |
digitalWrite(power, HIGH); // off | |
return data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment