I'm using an OLED 128x64 display and using the u8g library. I'm trying to change the display yung two buttons. One for the previous and one for the next display.
I have this code to change display:
void changeDisplay()
{
buttonStateA1 = digitalRead(btnNextPage);
buttonStateB1 = digitalRead(btnPreviousPage);
if (buttonStateA1 == HIGH)
{
u8g.firstPage();
do
{
fluidLevel(); //function to display level if fluid
}
while (u8g.nextPage());
}
if (buttonStateB1 == HIGH)
{
u8g.firstPage();
do
{
dripRate(); //function to display fluid drip rate
}
while (u8g.nextPage());
}
}
I can switch display but only when I'm pressing down on the button. I want it to display the other one when I press it once and change when I press the other one.
This function is also in the void loop() of my code.
I can switch display but only when I'm pressing down on the button. I want it to display the other one when I press it once and change when I press the other one.
You need to detect when buttons become pressed rather than when they are pressed. Take a look at the StateChangeDetction example in the IDE
UKHeliBob:
You need to detect when buttons become pressed rather than when they are pressed. Take a look at the StateChangeDetction example in the IDE
Thank you. I still have a problem. I tried using bool functions to each button, I can change displays but the timer on the other display stops displaying the real time rather, it stops until I change display and return to the previous display with the timer in it.
It's the same as the first one but with the buttonState ! lastButtonState decision.
If I enclose the function in do while loop in void loop, I can change displays but only when I hold press on the button. If I don't, I can change display. the display doesn't get cleared but the time on the display stops, until I change to the next display and go back. It is just then where the timer updates but stops again until I change display and go back again.
if (buttonStateA1 != lastButtonStateA1)
{
if (buttonStateA1 == HIGH && dispState)
{
u8g.firstPage();
do
{
fluidLevel(); //function to display level if fluid
}
while (u8g.nextPage());
dispState = false;
}
}
if (buttonStateA1 != lastButtonStateA1)
{
if (buttonStateB1 == HIGH && !dispState)
{
u8g.firstPage();
do
{
dripRate(); //function to display fluid drip rate
}
while (u8g.nextPage());
dispState = true;
}
}
}
sorry it took some time. I'm using my phone to reply. We don't have wifi at home so I'm using mobile data to access the internet.