#include <U8g2lib.h>
#include <U8x8lib.h>
#include<Wire.h>
U8G2_ST7920_128X64_1_HW_SPI u8g2(U8G2_R0, /* CS=/ 10, / reset=*/ 8);
#define pb1 3
#define pb2 4
#define pb3 A2
#define pb4 A1
#define gnd 2
int count=0 , value1=0 , value2=0 , value3=0 , value0=0 ;
void setup()
{
Serial.begin(9600);
u8g2.begin();
u8g2.enableUTF8Print();
u8g2.setFont(u8g2_font_helvB10_tf);
u8g2.setColorIndex(1);
pinMode(pb1,INPUT_PULLUP);//prev
pinMode(pb2,INPUT_PULLUP);//next
pinMode(pb3,INPUT_PULLUP);//decrement
pinMode(pb4,INPUT_PULLUP);//increment
pinMode(gnd,OUTPUT);
}
void loop()
{
digitalWrite(gnd,LOW);
u8g2.firstPage();
do {
draw();
} while( u8g2.nextPage() );
if(digitalRead(pb1)==LOW)
{
delay(10);
while(digitalRead(pb1)==LOW);
count--;
if(count<0) count=0 ;
}
if(digitalRead(pb2)==LOW)
{
delay(10);
while(digitalRead(pb2)==LOW);
count++;
if(count>3) count=3 ;
}
if(digitalRead(pb3)==LOW)
{
delay(200);
if(count==0)
{
value0-- ;
}
if(count==1)
{
value1-- ;
}
if(count==2)
{
value2-- ;
}
if(count==3)
{
value3-- ;
}
}
if(digitalRead(pb4)==LOW)
{
delay(200);
if(count==0)
{
value0++ ;
}
if(count==1)
{
value1++ ;
}
if(count==2)
{
value2++ ;
}
if(count==3)
{
value3++;
}
}
}
void draw()
{
switch(count)
{
case 0 :
u8g2.drawStr( 2, 62,value0 );
Serial.println(value0);
break;
case 1 :
u8g2.drawStr( 2, 62,value1 );
Serial.println(value1);
break;
case 2 :
u8g2.drawStr( 2, 62,value2 );
Serial.println(value2);
break;
case 3 :
u8g2.drawStr( 2, 62,value3 );
Serial.println(value3);
break;
}
}