I want it to set the value of the current position when the button is pressed or when powered up then use that value as the "boundary" point where if that's met or exceeded then the alarm sounds and continues to sound until the button is pressed to reset the value or the flex sensor is moved to the "safe" position.
My code is kinda hacked now, not sure things are necessary or even in the right places. Please bear with me, I'm still thinking in basic and q basic. Am new to C++ and as you can see i'm lost. Anyways I have it set to go off greater than 250. That's the spot where I want the remembered "string" to be the boundary (replaces the 250 with an integer or string). It doesn't seem like the button even registers at this point.
int flexSensorPin = A0;//analog pin 7= tiny2=A1
int LoggedPosition = flexSensorPin;
const int Piezo = 3; //digital pin 3 = tiny0
const int inPin = 2; // Push Button to set current Bend Status
int val = 0;
void setup() {
pinMode (Piezo, OUTPUT);
pinMode(inPin, INPUT); // declare pushbutton as input
Serial.begin(9600);
val = digitalRead(inPin);
}
void loop() {
int flexSensorReading = analogRead(flexSensorPin);
;
Serial.println(flexSensorReading);
if (flexSensorReading > 250) {
Serial.println("Alarm! Set Angle Exceeded");
digitalWrite(Piezo, HIGH);
// if(digitalRead(inPin)){
LoggedPosition=flexSensorReading;
delay(100);
digitalWrite(Piezo, LOW);
}
delay(250);
}
