Hi
Im in the state with my little program where again i don
t know where to go.
Situation is simple.
One analog sensor connected to analogInput1 measures pressure and displaying value on the LCD.
2 touch buttons are connected thru AT42QT1070 goes to analogInput 2,4 and once pressed change state of pin 3 and pin 11 (2->3), (4->11).
Now,as we all know accidental touch is possible with this design.
What i would like to do is:
If no touch is detected (button pressed) within 10sec->inactivate outputs->to reactivate press and hold either button #2 or #4 for minimum 3 sec to enable output(2,11).
/*
ANALOG PRESSURE SENSORS
*/
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
const int buttonPin = A4; // the number of the pushbutton pin
const int buttonPin1 = A2;
const int outPin = 3; // the number of the LED pin
const int outPin1 = 11;
int buttonState = 0;// variable for reading the pushbutton status
int buttonState1 = 0;
int sensorValue = 0;
int val = 0;
int raw;
float voltage;
float pressure; //pressure in psi
void setup() {
Serial.begin(9600);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.setCursor(5, 0);
lcd.print("valve");
lcd.setCursor(3, 1);
lcd.print("control");
delay(500);
lcd.clear();
lcd.print("FL ");
// initialize the LED pin as an output:
pinMode(outPin, OUTPUT);
pinMode(outPin1, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
pinMode(buttonPin1, INPUT);
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
buttonState1 = digitalRead(buttonPin1);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == LOW) {
// turn LED on:
digitalWrite(outPin, HIGH);
}
else {
// turn LED off:
digitalWrite(outPin, LOW);
}
if (buttonState1 == LOW) {
// turn LED on:
digitalWrite(outPin1, HIGH);
}
else {
// turn LED off:
digitalWrite(outPin1, LOW);
}
//Sensor #1
raw = analogRead(A1);
voltage = (float) raw / 1023.0 * 5.0;
pressure = (((float)analogRead(A1) / 1023.0 * 5.0) - 0.5) * 37.5;
if (pressure<-10)
{
lcd.setCursor(3,0);
lcd.print(pressure,0);
}
if (pressure>-10)
{
lcd.setCursor(4,0);
lcd.write(254);
lcd.setCursor(3,0);
lcd.print(pressure,0);
}
if (pressure>-100)
{
lcd.setCursor(5,0);
lcd.write(254);
lcd.setCursor(3,0);
lcd.print(pressure,0);}
}
Moderator edit: CODE TAGS. Why are they so difficult to add?