kunna ändra öppningstiden på magnetventiler och även intervallen mellan öppningstiderna
tiderna ligger i variabeln ValveTime[]
har en rutin som skriver ut tiderna på en display och man kan med tryckknappen flytta cursorn mellan de olika positionerna
behöver hjälp med att förändra värdet i positionen med encodern hittar ingen tutorial för detta
någon som kan knuffa mig i rätt riktning?
//Ola
Kod: Markera allt
/*
DNU= Display Needs Update
*/
// include the library code:
#include <LiquidCrystal.h>
#include <EEPROM.h>
#include <Encoder.h>
Encoder myEnc(2, 3);
//ValveTime[0-2] = opentime
//ValveTime[3-5] = delaytime
int ValveTime[] = {00, 01, 02, 03, 04, 05}; //read from eeprom later
int count = 0;
/*
for (count=0;count<6;count++) {
int ValveTime[count] =EEPROM.read(count)
}
*/
int DNU=1;
const int buttonPin = 4;
int CursorPos = 0;
int buttonState = 0;//state of button pressed
int oldencpos = 0;
int lastButtonState = 0;
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = A0, en = A1, d4 = A2, d5 = A3, d6 = A4, d7 = A5;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
//***************************************************************************
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
Serial.begin(115200);//for debug
// set up the LCD's number of columns and rows:
lcd.begin(20,4); //setup display
digitalWrite(LED_BUILTIN, LOW);
}
//*********************************************************
void loop() {
if (DNU == 1){
PrintDisplay();
DNU=0;
}
buttonread();
int neWpos =myEnc.read();
Serial.print(neWpos);
Serial.print("\t");
Serial.print(CursorPos);
Serial.print("\t");
Serial.println(ValveTime[CursorPos]);
if (neWpos != ValveTime[CursorPos]) {
ValveTime[CursorPos]=neWpos;
/* if (ValveTime[CursorPos] < 0){
ValveTime[CursorPos] = 0;
}*/
DNU = 1;
}
}
//**********************************************************
void SetCursor(void){
CursorPos ++;
lcd.cursor();
lcd.blink();
// Serial.println("setcursor");
Serial.println(CursorPos);
switch (CursorPos) {
case 0:
lcd.noBlink();
break;
case 1:
lcd.setCursor(1, 1);
break;
case 2:
lcd.setCursor(9, 1);
break;
case 3:
lcd.setCursor(17, 1);
break;
case 4:
lcd.setCursor(1, 3);
break;
case 5:
lcd.setCursor(9, 3);
break;
case 6:
lcd.setCursor(17, 3);
break;
case 7:
lcd.noCursor();
lcd.noBlink();
CursorPos=0;
break;
}
}
//******************************************************************
void PrintDisplay(void) {
lcd.clear();
lcd.setCursor(1, 0);
lcd.print("opentime");
lcd.setCursor(1, 1);
lcd.print(ValveTime[0]);
lcd.setCursor(9, 1);
lcd.print(ValveTime[1]);
lcd.setCursor(17, 1);
lcd.print(ValveTime[2]);
lcd.setCursor(1, 2);
lcd.print("delaytime");
lcd.setCursor(1, 3);
lcd.print(ValveTime[3]);
lcd.setCursor(9, 3);
lcd.print(ValveTime[4]);
lcd.setCursor(17, 3);
lcd.print(ValveTime[5]);
}
//****************************************************************
void buttonread (void)
{
// read the pushbutton input pin:
buttonState = digitalRead(buttonPin);
// compare the buttonState to its previous state
if (buttonState != lastButtonState) {
// if the state has changed, increment the counter
if (buttonState == HIGH) {
// if the current state is HIGH then the button
// wend from off to on:
SetCursor();
// valvepos
}
// save the current state as the last state,
//for next time through the loop
lastButtonState = buttonState;
}
}