I uploaded this in Arduino DUE but it seems that the up and down button is not properly triggering the Arduino DUE pins.
I dont know if there is a problem in the board, but when i tried this one in Arduino Atmega, it is working properly.
#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7); //Pines arduino a lcd
//Counter to change positions of pages
int page_counter = 1 ; //To move beetwen pages
int break_counter_pin36 = 0;
int break_counter_pin38 = 0;
//Variables for auto scroll
unsigned long previousMillis = 0;
unsigned long interval = 10000; //Desired wait time 10 seconds
//-------Pins-----//
int up = 8; //Up button
int down = 9; //Down button
int up1 = 36;
int up2 = 38;
const int counter = 13;
int hits = 0;
int hits1 = 0;
int switchState = 0;
int prevSwitchState = 0;
//---------Storage debounce function-----//
boolean current_up = LOW;
boolean current_up1 = LOW;
boolean current_up2 = LOW;
boolean last_up = LOW;
boolean last_up1 = LOW;
boolean last_up2 = LOW;
boolean last_down = LOW;
boolean current_down = LOW;
void setup() {
lcd.begin(16, 2);
}
//---- De-bouncing function for all buttons----//
boolean debounce(boolean last, int pin)
{
boolean current = digitalRead(pin);
if (last != current)
{
delay(5);
current = digitalRead(pin);
}
return current;
}
void loop() {
current_up = debounce(last_up, up); //Debounce for Up button
current_up1 = debounce(last_up1, up1); //Debounce for Up button
current_up2 = debounce(last_up2, up2); //Debounce for Up button
current_down = debounce(last_down, down); //Debounce for Down button
//----Page counter function to move pages----//
//Page Up
if (last_up == LOW && current_up == HIGH) {
lcd.clear(); //When page is changed, lcd clear to print new page
if (page_counter < 4) { //Page counter never higher than 4(total of pages)
page_counter = page_counter + 1; //Page up
}
}
last_up = current_up;
if (last_up1 == LOW && current_up1 == HIGH && page_counter==1 && break_counter_pin36 == 0) {
lcd.clear(); //When page is changed, lcd clear to print new page
if (page_counter < 4) { //Page counter never higher than 4(total of pages)
page_counter = page_counter + 1; //Page up
break_counter_pin36 = break_counter_pin36 +1;
}
}
last_up1 = current_up1;
if (last_up2 == LOW && current_up2 == HIGH && break_counter_pin38 == 0) {
lcd.clear(); //When page is changed, lcd clear to print new page
if (page_counter < 4) { //Page counter never higher than 4(total of pages)
page_counter = page_counter + 1; //Page up
break_counter_pin38 = break_counter_pin38 +1;
}
}
last_up2 = current_up2;
//Page Down
if (last_down == LOW && current_down == HIGH) {
lcd.clear(); //When page is changed, lcd clear to print new page
if (page_counter > 1) { //Page counter never lower than 1 (total of pages)
page_counter = page_counter - 1; //Page down
}
else {
page_counter = 4; //return to page 4
}
}
last_down = current_down;
//------- Switch function to write and show what you want---//
switch (page_counter) {
case 1: { //Design of home page 1
lcd.setCursor(2, 0);
lcd.print("Bending Test");
lcd.setCursor(4, 1);
lcd.print("Counter");
}
break;
case 2: { //Design of page 2
lcd.setCursor(2, 0);
lcd.print("1st Breakage");
lcd.setCursor(4, 1);
lcd.print(hits);
switchState = digitalRead(counter);
if (switchState != prevSwitchState) {
if (switchState == LOW) {
hits = hits + 1;
lcd.setCursor(2, 0);
lcd.print("1st Breakage");
lcd.setCursor(4, 1);
lcd.print(hits);
}
}
prevSwitchState = switchState;
}
break;
case 3: { //Design of page 3
lcd.setCursor(2, 0);
lcd.print("2nd Breakage");
lcd.setCursor(4, 1);
lcd.print(hits1);
switchState = digitalRead(counter);
if (switchState != prevSwitchState) {
if (switchState == LOW) {
hits1 = hits1 + 1;
lcd.setCursor(2, 0);
lcd.print("2nd Breakage");
lcd.setCursor(4, 1);
lcd.print(hits1);
}
}
prevSwitchState = switchState;
}
break;
case 4: { //Design of page 4
lcd.setCursor(2, 0);
lcd.print("(2) samples");
lcd.setCursor(2, 1);
lcd.print("was finished");
}
break;
}//switch end
}//loop end