#include <LiquidCrystal.h>
#define DT 10
#define SW 13
int counter = 0; // percentage (0–100)
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// Custom characters (jouw blokjes)
byte char1[] = { B00000,B00000,B00000,B00000,B00000,B00000,B00000,B00000 };
byte char2[] = { B10000,B10000,B10000,B10000,B10000,B10000,B10000,B10000 };
byte char3[] = { B11000,B11000,B11000,B11000,B11000,B11000,B11000,B11000 };
byte char4[] = { B11100,B11100,B11100,B11100,B11100,B11100,B11100,B11100 };
byte char5[] = { B11110,B11110,B11110,B11110,B11110,B11110,B11110,B11110 };
byte char6[] = { B11111,B11111,B11111,B11111,B11111,B11111,B11111,B11111 };
void setup(){
pinMode(DT, INPUT_PULLUP);
pinMode(SW, INPUT_PULLUP);
lcd.begin(16, 2);
lcd.createChar(0, char1);
lcd.createChar(1, char2);
lcd.createChar(2, char3);
lcd.createChar(3, char4);
lcd.createChar(4, char5);
lcd.createChar(5, char6);
lcd.clear();
}
void loop(){
// tellen
if(digitalRead(DT) == LOW){
if(counter < 100) counter++;
delay(150);
}
if(digitalRead(SW) == LOW){
if(counter > 0) counter--;
delay(150);
}
updateLCD();
}
void updateLCD() {
lcd.setCursor(0,0);
lcd.print(" ");
lcd.print(counter);
lcd.print("% ");
int totalBlocks = 16;
float filled = (counter / 100.0) * totalBlocks;
int full = filled;
int rest = (filled - full) * 5;
lcd.setCursor(0,1);
for(int i=0; i < full; i++){
lcd.write(byte(5));
}
if(full < totalBlocks){
lcd.write(byte(rest));
full++;
}
while(full < totalBlocks){
lcd.write(byte(0));
full++;
}
}