Κώδικας:
#include <LiquidCrystal.h>
const int encoderPinA = 3;
const int encoderPinB = 2;
unsigned int tempset=0; //volatile
volatile int n = LOW;
int encoderPinALast = LOW;
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
void setup() {
lcd.begin(16,2);
// put your setup code here, to run once:
pinMode(encoderPinA, INPUT_PULLUP);
pinMode(encoderPinB, INPUT_PULLUP);
pinMode(13, OUTPUT);
attachInterrupt(digitalPinToInterrupt(encoderPinA), updateEncoder, CHANGE);
attachInterrupt(digitalPinToInterrupt(encoderPinB), updateEncoder, CHANGE);
Serial.begin(9600);
}
void loop() {
//Serial.print("loop");//debug
/*
lcd.setCursor(0, 1);
lcd.print(" set=");
//lcd.print(tempset);//temp=000 set=000 (15)
delay(1000);
*/
}
void updateEncoder() {
n = digitalRead(encoderPinA);
if ((encoderPinALast == LOW) && (n == HIGH)) {
if (digitalRead(encoderPinB) == LOW) {
if(tempset>0 ){
tempset = tempset -1;
}
}
else {
if(tempset<400){
tempset = tempset + 1;
}
}
Serial.println(tempset);
//lcd.clear();
lcd.setCursor(0, 0);
lcd.print("temp=");
lcd.print(" ");
lcd.setCursor(5, 0);
lcd.print(tempset);
}
encoderPinALast = n;
//Serial.println("hi");
//digitalWrite(13,HIGH);
//digitalWrite(13,LOW);
}
ε αντε γεια ! το έφτιαξα ευχαριστώ Πολυ