Hi Everyone !
I wish to display a lcd bargraph for liquid level. The code does not compile gives an error 'Void' does not name type.
This is the first problem I am facing, I know there are lot more waiting.....
Kindly help me =(
//includes
#include <LiquidCrystal.h>
#include <EEPROM.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12,11,6,7,8,9) when LCD is used
//pins
const byte buttonpin1 = 2; // reed switch 1
const byte buttonpin2 = 3; // reed switch 2
const byte buttonpin3 = 4; // reed switch 3
const byte buttonpin4 = 5; // reed switch 4
const byte buttonpin5 = 5; // reed switch 5
byte state1 = 0;
byte state2 = 0;
byte state3 = 0;
byte state4 = 0;
byte state5 = 0;
int Level = 0;
void setup() {
//configure pins
pinMode(buttonpin1, INPUT);
pinMode(buttonpin2, INPUT);
pinMode(buttonpin3, INPUT);
pinMode(buttonpin4, INPUT);
pinMode(buttonpin5, INPUT);
//setup LCD, when lcd used
lcd,begin (16,2);
//intitial message
lcd.SetCursor (0,0);
lcd.print ("Hello");
Level = EEPROM.read(0); // read level value from eeprom.
//Recalling the Level from eeprom
lcd.setCursor (0,1);
lcd.print ("Last level: ");
lcd.print (Level);
delay(5000);
lcd.clear();
// Create custom characters to make a ramp
byte clrChar[8] = { // character needed to clear others
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000
};
lcd.createChar(0, clrChar);
byte newChar[8] = { // // black character
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111
};
lcd.createChar(1, newChar);
} // end setup()
// the display a single function called from inside loop
Void display() {
switch (Level) {
case 1:
state1 = 0;state2 = 1;state3 = 1;state4 = 1;state4 = 1;
lcd.setCursor(0, 0); // set cursor position.
lcd.write(1); // write to screen the custom graph character.
lcd.setCursor(1, 0); // set cursor position.
lcd.write(0); // write to screen the custom clear character.
lcd.setCursor(2, 0); // set cursor position.
lcd.write(0); // write to screen the custom clear character.
lcd.setCursor(3, 0); // set cursor position.
lcd.write(0); // write to screen the custom clear character.
lcd.setCursor(4, 0); // set cursor position.
lcd.write(0); // write to screen the custom clear character.
lcd.setCursor(6, 0); // set cursor position.
lcd.print("MIN");// write text next to graph
break;
case 2:
state1 = 0;state2 = 0;state3 = 1;state4 = 1;state4 = 1;
lcd.setCursor(0, 0); // set cursor position.
lcd.write(1); // write to screen the custom graph character.
lcd.setCursor(1, 0); // set cursor position.
lcd.write(1); // write to screen the custom graph character.
lcd.setCursor(2, 0); // set cursor position.
lcd.write(0); // write to screen the custom clear character.
lcd.setCursor(3, 0); // set cursor position.
lcd.write(0); // write to screen the custom clear character.
lcd.setCursor(4, 0); // set cursor position.
lcd.write(0); // write to screen the custom clear character.
lcd.setCursor(6, 0); // set cursor position.
lcd.print("25%");// write text next to graph
break;
case3:
state1 = 0;state2 = 0;state3 = 0;state4 = 1;state4 = 1;
lcd.setCursor(0, 0); // set cursor position.
lcd.write(1); // write to screen the custom graph character.
lcd.setCursor(1, 0); // set cursor position.
lcd.write(1); // write to screen the custom graph character.
lcd.setCursor(2, 0); // set cursor position.
lcd.write(1); // write to screen the custom graph character.
lcd.setCursor(3, 0); // set cursor position.
lcd.write(0); // write to screen the custom clear character.
lcd.setCursor(4, 0); // set cursor position.
lcd.write(0); // write to screen the custom clear character.
lcd.setCursor(6, 0); // set cursor position.
lcd.print("50%");// write text next to graph
break;
case4:
state1 = 0;state2 = 0;state3 = 0;state4 = 0;state4 = 1;
lcd.setCursor(0, 0); // set cursor position.
lcd.write(1); // write to screen the custom graph character.
lcd.setCursor(1, 0); // set cursor position.
lcd.write(1); // write to screen the custom graph character.
lcd.setCursor(2, 0); // set cursor position.
lcd.write(1); // write to screen the custom graph character.
lcd.setCursor(3, 0); // set cursor position.
lcd.write(1); // write to screen the custom graph character.
lcd.setCursor(4, 0); // set cursor position.
lcd.write(0); // write to screen the custom clear character.
lcd.setCursor(6, 0); // set cursor position.
lcd.print("75%");// write text next to graph
break;
case5:
state1 = 0;state2 = 0;state3 = 0;state4 = 0;state4 = 0;
lcd.setCursor(0, 0); // set cursor position.
lcd.write(1); // write to screen the custom graph character.
lcd.setCursor(1, 0); // set cursor position.
lcd.write(1); // write to screen the custom graph character.
lcd.setCursor(2, 0); // set cursor position.
lcd.write(1); // write to screen the custom graph character.
lcd.setCursor(3, 0); // set cursor position.
lcd.write(1); // write to screen the custom graph character.
lcd.setCursor(4, 0); // set cursor position.
lcd.write(1); // write to screen the custom graph character.
lcd.setCursor(6, 0); // set cursor position.
lcd.print("MAX%”";// write text next to graph
break;
default:
// if nothing else matches, do the default
// default is optional
}
}
void loop(){
display(); // display is called at everyloop and at beginning of it.
So at first time will restore the Display and states from the Level stored at eeprom.
if (digitalRead(buttonpin1) == LOW){ // min
int state1= digitalRead(buttonpin1);
Level=1;
delay(500); // debounce
}
if (digitalRead(buttonpin2) == LOW) // 25%
{
state2 = !state2; // toggle state
if (state2 >0 ){
Level = 2;
if (state2 ==0 ){
Level =1;
}
delay(500); // debounce
}
if (digitalRead(buttonpin3) == LOW) //50%
{
state3 = !state3; // toggle state
if (state3 >0 ){
Level = 3;
}
if (state3 ==0 ){
Level = 2;
}
delay(500); // debounce
}
if (digitalRead(buttonpin4) == LOW) // 75%
{
state4 = !state4; // toggle state
if (state4 >0 ){
Level = 4;
}
if (state4 ==0 ){
Level = 3;
}
delay(500); // debounce
}
if (digitalRead(buttonpin5) == LOW) { // max
state5 = !state5; // toggle state
Level = 5;
// CUT POWER SUPPLY TO PUMP.
delay(500); // debounce
}
if (digitalRead(buttonpin5) == HIGH) { // max reed off
state5 = !state5; // toggle state
if (state5>1) {
Level = 4;
}
delay(500); // debounce
}
EEPROM.write(0, Level); // Write to eeprom memory position 0 the Level value.
delay(100); // small delay at each loop.
}