hello guys
i want to do a project with arduino and an oled 128*32 so i want to do a menu with only one button and with only 3 pages but i'm stuck
i want to do first welcoming page that says press the button then second page ask to select a value using a potentiometer than the third page i want it to show that value and clock counter
i'm really stuck because i'm new to this
so if there anyone that could help and write me a simple code i would appreciate it a lot :-[ :-[
Post what code you have tried and where you are stuck.
here is my code every time i get on a screen i doesn’t refresh the numbers i have to go back and enter again to see the new value
can you please help i can’t finf anything on the internet helpful
#include <SPI.h>
#include<Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
#define startbutton 2
int currentscreen ;
unsigned long time;
float u;
float z;
float i;
float f; // reading battery value
long int seconds=0;
int minutes=0;
int hours=0;
long int c;
int a=1;
float v;
unsigned long previousmillis =0;
unsigned long interval = 1000;
volatile boolean startt ;
volatile boolean sb ;
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
void isr0() {
sb= digitalRead(startbutton);
startt = true;
}
void setup() {
Serial.begin(115200);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
display.clearDisplay();
delay(2000);
attachInterrupt (digitalPinToInterrupt(2), isr0, CHANGE);
display.setTextSize(1);
display.setTextColor(WHITE);
screen1();
display.clearDisplay();
screen2();
}
void loop() {
u =analogRead(A1);
f =analogRead(A0);
z =(u/1023)*5; //voltage across resistor
i = z/2.2 ; // current passing through resistor
c= (hours*1000*a)+(minutes*1000*a)/60;
v=(f/1023)*5 ; // battery voltage
if (startt ){
delay(200);
switch (currentscreen){
case 2:
screen3();
startt=false;
break;
case 3:
screen4();
startt=false;
break;
case 4:
screen5();
startt=false;
break;
case 5:
screen2();
startt=false;
break;
}
}
}
void setClock()
{
if(millis() > previousmillis + interval){
previousmillis = millis();
seconds++;}
if (seconds>59)
{
seconds=0;
minutes++;
}
if (minutes>59)
{hours++;
minutes=0;
}
if(hours>23)
{
hours=0;
}
}
void screen1(){
display.clearDisplay();
display.setCursor(15,5);
display.println("battery discharger");
display.setCursor(15,20);
display.println("by SKANDER BELHAJ");
display.display();
delay (4000);
currentscreen=1;
}
void screen2() {
display.clearDisplay();
display.setCursor(15,5);
display.println("PLACE BATTERY ");
display.setCursor(15,20);
display.println("AND PRESS START ");
display.display();
currentscreen=2;
}
void screen3 (){
display.clearDisplay();
display.setCursor(35,15);
display.print("SELECT AMPS");
display.setCursor(50,25);
display.print(f);
display.display();
currentscreen=3;
}
void screen4(){
display.clearDisplay();
display.setCursor(30,5);
display.print("LOW VOLTAGE");
display.setCursor(60,15);
display.print("/");
display.setCursor(30,25);
display.print("NO BATTERY");
display.display();
currentscreen=4;
}
void screen5(){
display.clearDisplay();
display.setCursor(0,0);
display.println("V = ");
display.setCursor(20,0);
display.println(u,1);
display.setCursor(80,0);
display.println("A =");
display.setCursor(100,0);
display.println(i,1);
display.setCursor(0,25);
display.println("T =");
display.setCursor(80,25);
display.println("C =");
display.setCursor(100,25);
display.print(c);
display.display();
setClock();
display.setCursor(20,25);
if(hours<10)
{
display.print("0");
display.print(hours);
}
else
{
display.setCursor(20,25);
display.print(hours);
}
display.setCursor(30,25);
display.print(":");
if(minutes<10)
{
display.setCursor(30,25);
display.print(":");
display.print("0");
display.print(minutes);
display.print(":");
}
else
{
display.print(minutes);
display.print(":");
}
if(seconds<10)
{
display.print("0");
display.print(seconds);
}
else
{display.print(seconds);}
display.display();
currentscreen=5;
}