Hello, i need your help.
i am trying to make a code that sets up a value, reads sensor and then it does something if sensor value is greater than the value.
i am stuck at setting up value. I want minimum value to be 960. i have set this up. But how to increase and decrease value? i've planned to use OneWireKeypad.getkey and in case '1' it would increase value and in case '2' it would decrease value. i've planned to use maxvalue++ and maxvalue --.
My question is where it should be? i've planned to put it in void loop but then i would have to set up the value all the time, if i am right.
And another question, if i press '1', would it increase my value only for 1? i mean do i have to press it all the time or it reads multiple presses if i hold the '1' key pressed?
include <OnewireKeypad.h>
#include <LiquidCrystal.h>
#define Rows 4
#define Cols 4
#define Pin A0
#define Col_Res 4700
#define Row_Res 1000
char KEYS[]= {
'1','2','3','A',
'4','5','6','B',
'7','8','9','C',
'*','0','#','D'
};
OnewireKeypad <Print, 16> KeyPad(Serial, KEYS, Rows, Cols, Pin, Col_Res, Row_Res );
int sensor1 = 2; // pin za senzor 1
int sensorValue1 = 0;
int mappedValue1;
LiquidCrystal lcd(7, 8, 9, 10, 11, 12, 13);
#define RELAY1 3
int maxvalue = 960;
void setup(){
lcd.begin(16, 2);
Serial.begin(9600);
lcd.print("odredite");
}
void loop(){
sensorValue1 = analogRead(sensor1);
delay(1000);
lcd.print("sensor 1 = " );
lcd.println();
lcd.println(sensorValue1);
lcd.println();
if (sensorValue1 < maxvalue )
{
digitalWrite(RELAY1, LOW);
}
if (sensorValue1 > maxvalue)
{
digitalWrite(RELAY1, HIGH);
}
}