/*
LiquidCrystal Library - display() and noDisplay()
Demonstrates the use a 16x2 LCD display. The LiquidCrystal
library works with all LCD displays that are compatible with the
Hitachi HD44780 driver. There are many of them out there, and you
can usually tell them by the 16-pin interface.
This sketch prints "Hello World!" to the LCD and uses the
display() and noDisplay() functions to turn on and off
the display.
The circuit:
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
Library originally added 18 Apr 2008
by David A. Mellis
library modified 5 Jul 2009
by Limor Fried (http://www.ladyada.net)
example added 9 Jul 2009
by Tom Igoe
modified 22 Nov 2010
by Tom Igoe
modified 7 Nov 2016
by Arturo Guadalupi
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/LiquidCrystalDisplay
*/
// include the library code:
#include <LiquidCrystal.h>
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
//for doMode using int increments
const int intMode = 6; // mode
///////
const int intRelay = 7; // trigger relay
int pot1 = A0; //simulate voltage measure
int pot2= A1; //simulate luminecence
//not used in this version
//int pot3 = A2; //change LCD mode using logic code monitoring pin D6
int out1 = 0;
int out2 = 0;
int intMode = 0;
int varMode = 0;
int doMode = 0;
String strOut1;
String strOut2;
String line1;
String line2;
String lineTEST;
// setup User characters
uint8_t pc10[8] = {
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
};
uint8_t pc08[8] = {
0b11110,
0b11110,
0b11110,
0b11110,
0b11110,
0b11110,
0b11110,
0b11110,
};
uint8_t pc06[8] = {
0b11100,
0b11100,
0b11100,
0b11100,
0b11100,
0b11100,
0b11100,
0b11100,
};
uint8_t pc04[8] = {
0b11000,
0b11000,
0b11000,
0b11000,
0b11000,
0b11000,
0b11000,
0b11000,
};
uint8_t pc02[8] = {
0b10000,
0b10000,
0b10000,
0b10000,
0b10000,
0b10000,
0b10000,
0b10000,
};
uint8_t barTwo[8] = {
0b11111,
0b11111,
0b11111,
0b00000,
0b00000,
0b11111,
0b11111,
0b11111,
};
uint8_t barThree[8] = {
0b11111,
0b11111,
0b00000,
0b11111,
0b11111,
0b00000,
0b11111,
0b11111,
};
void setup() {
lcd.createChar(1, pc02);
lcd.createChar(2, pc04);
lcd.createChar(3, pc06);
lcd.createChar(4, pc08);
lcd.createChar(5, pc10);
lcd.createChar(6, barTwo);
lcd.createChar(7, barThree);
//lcd.print(" I \x03 Arduino");
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
pinMode(intRelay, OUTPUT);
digitalWrite(intRelay, LOW);
pinMode(intMode, INPUT); //for doMode incrmenter
}
void loop() {
//doMode = digitalRead(intMode);
// read the value from the sensor:
out1 = analogRead(pot1);
// read the value from the sensor:
out2 = analogRead(pot2);
//not in this version varMode = analogRead(pot3);
long out11 = out1 * (100.0 / 1023.0);
long out22 = out2 * (100.0 / 1023.0);
//int doMode = varMode * (100.0 / 1023.0);
strOut1 = String(out11);
strOut2 = String(out22);
line1.reserve(60);
line2.reserve(60);
line1 = String("\x01 Volts ") + strOut1 +String(" %");
line2 = String("\x07 Solar ") + strOut2 +String(" %");
lineTEST = "DEFAULT";
lcd.clear();
//check LCD mode button
if(doMode <= 10) {
digitalWrite(intRelay, LOW); //do something when var == 0
lcd.clear();
lcd.print(line1);
lcd.setCursor(0,2);
lcd.print(line2);
lcd.display();// Turn on the display:
delay(1000);
} if( doMode > 10 && doMode < 20) {
digitalWrite(intRelay, HIGH);
lcd.clear();
lcd.print(line2);
lcd.setCursor(0,2);
lcd.print(line1);
lcd.display();
delay(1000);
} if(doMode >= 20 && doMode < 30) {
digitalWrite(intRelay, HIGH);
lcd.clear();
lcd.print("\x05 greater than 20");
lcd.setCursor(0,2);
lcd.print(line1);
lcd.display();
delay(1000);
} else {
// default is optional
lcd.clear();
lcd.setCursor(0,1);
lcd.print("doMode");
lcd.display();
delay(1000);
}
}