groworld/xylem/xylem.pde

49 lines
958 B
Text
Raw Normal View History

2009-06-10 15:12:29 +00:00
// part of the groworld HPI prototype
#include <stdio.h>
#define lightpin 1 // light sensor on analog pin 1
#define humidpin 0 // humidity sensor on analog pin 0
#define power 8 // power for sensors
unsigned long then = 0; // timer which will run for < 50 days
unsigned long interval = 1; // interval between reads in seconds
void setup()
{
pinMode(power, OUTPUT);
pinMode(humidpin, INPUT);
pinMode(lightpin, INPUT);
Serial.begin(9600);
}
int lightlevel ()
{
int light = 0;
light = (analogRead(lightpin));
return light;
}
int moisturelevel ()
{
int moist = 0;
digitalWrite(power, HIGH);
moist = (analogRead(humidpin));
digitalWrite(power, LOW);
return moist;
}
char display[64];
void loop()
{
if (millis() - then > interval*1000) {
then = millis();
sprintf(display, "%u,%u,%u\n", (unsigned int)then, lightlevel(), moisturelevel());
Serial.print(display);
}
}