Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define encoderPinA 6
- #define encoderPinB 7
- #include <LiquidCrystal.h>
- LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
- int n = LOW;
- int encoderPinALast = LOW;
- int encoderPos = 0;
- byte load0[8] = {
- B00000,
- B00000,
- B00000,
- B00000,
- B00000,
- B00000,
- B00000,
- B00000
- };
- byte load1[8] = {
- B10000,
- B10000,
- B10000,
- B10000,
- B10000,
- B10000,
- B10000,
- B10000
- };
- byte load2[8] = {
- B11000,
- B11000,
- B11000,
- B11000,
- B11000,
- B11000,
- B11000,
- B11000
- };
- byte load3[8] = {
- B11100,
- B11100,
- B11100,
- B11100,
- B11100,
- B11100,
- B11100,
- B11100
- };
- byte load4[8] = {
- B11110,
- B11110,
- B11110,
- B11110,
- B11110,
- B11110,
- B11110,
- B11110
- };
- byte load5[8] = {
- B11111,
- B11111,
- B11111,
- B11111,
- B11111,
- B11111,
- B11111,
- B11111
- };
- void setup() {
- // put your setup code here, to run once:
- Serial.begin(9600);
- lcd.begin(16, 2);
- lcd.createChar(0, load0);
- lcd.createChar(1, load1);
- lcd.createChar(2, load2);
- lcd.createChar(3, load3);
- lcd.createChar(4, load4);
- lcd.createChar(5, load5);
- pinMode(encoderPinA, INPUT_PULLUP);
- pinMode(encoderPinB, INPUT_PULLUP);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- encoderStand();
- printPercentage();
- printBlokjes();
- double waardeTachtig = (encoderPos / 100) * 80;
- int volKarakter = waardeTachtig / 16;
- lcd.setCursor(0, 1);
- }
- void printBlokjes(){
- int temp = encoderPos;
- int groteGetallen = temp/5;
- int kleinegetallen = temp%5;
- for(int i = 0; i < groteGetallen; i++){
- lcd.write(byte(5));
- }
- lcd.write(byte(kleinegetallen));
- }
- void printPercentage(){
- lcd.setCursor(0, 0);
- if (encoderPos < 10) {
- lcd.print(" ");
- }
- if (encoderPos < 100) {
- lcd.print(" ");
- }
- lcd.print(encoderPos);
- lcd.print("%");
- }
- void encoderStand() {
- n = digitalRead(encoderPinA);
- if ((encoderPinALast == LOW) && (n == HIGH)) {
- if (digitalRead(encoderPinB) == LOW) {
- if (encoderPos >= 100) {
- encoderPos = 100;
- } else {
- encoderPos ++;
- }
- } else if (!(encoderPos <= 0)) {
- encoderPos --;
- }
- }
- encoderPinALast = n;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement