Created
February 22, 2016 07:06
-
-
Save logikal/fbfc36d6ba51121f020f to your computer and use it in GitHub Desktop.
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
// http://openenergymonitor.org/emon/node/1267 | |
//inclue lcdLibrary | |
#include | |
//intialize the library with the numbers of the interface pins | |
LiquidCrystal lcd(7, 8, 9, 10, 11, 12); | |
//set input pin | |
int sensorPin = A4; | |
int ledPowerOn = 3; | |
int ledPowerOff = 2; | |
int sensorMax; | |
int sensorMin; | |
int sensorValue; | |
void setup(void) { | |
//set up the LCD | |
lcd.begin(16, 2); | |
//Serial.begin(9600); | |
//set ledPin as an output | |
pinMode(ledPowerOff, OUTPUT); | |
pinMode(ledPowerOn, OUTPUT); | |
} | |
void loop(void) { | |
sensorMin = 1023; | |
sensorMax = 0; | |
sensorValue = 0; | |
for (int n = 0; n<200; n++) | |
{ | |
sensorValue = analogRead(sensorPin); | |
if (sensorMax < sensorValue) | |
sensorMax = sensorValue; | |
if (sensorMin > sensorValue) | |
sensorMin = sensorValue; | |
} | |
if (sensorMax - sensorMin < 100) | |
{ | |
digitalWrite(ledPowerOff, HIGH); | |
digitalWrite(ledPowerOn, LOW); | |
//write to lcd | |
lcd.clear(); | |
lcd.print(sensorMax - sensorMin); | |
//Serial.print(max5 - min5); | |
//Serial.print(" "); | |
delay(1000); | |
} | |
else | |
{ | |
digitalWrite(ledPowerOn, HIGH); | |
digitalWrite(ledPowerOff, LOW); | |
//write to lcd | |
lcd.clear(); | |
lcd.print(sensorMax - sensorMin); | |
//Serial.print(max5 - min5); | |
//Serial.print(" "); | |
delay(1000); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment