I'm doing a project where I need Arduino to send a single line of text to the monitor (eventually to Isadora) when the reading from an FSR goes above a certain threshold, and not print again until the FSR reads over the threshold again.
Example: Someone steps on the FSR, so Arduino prints the text. The person continues standing on the FSR, so arduino does not send another. The person leaves, changing the reading from the FSR, but it's under the threshold, so arduino doesn't print the text. Another person steps on the FSR so Arduino prints the text.
So far this is what I have (code for 4 analog FSR sensors):
void setup(void) {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
int Sens0 = analogRead(A0);
int Sens1 = analogRead(A1);
int Sens2 = analogRead(A2);
int Sens3 = analogRead(A3);
//read Analog inputs for pressure plates and assign them variables
int threshold = 300; //Threshold for how much pressure is applied
int pressure0 = 0; //False
int pressure1 = 0; //False
int pressure2 = 0; //False
int pressure3 = 0; //False
//Changing variables to trigger the "Shuffle" order
int Sensor0State = 0; //Current state of Sensor 0
int lastSensor0State = 0; //Last Recorded state of sensor 0
int Sensor1State = 0; //Current state of Sensor 1
int lastSensor1State = 0; //Last Recorded state of sensor 1
int Sensor2State = 0; //Current state of Sensor 2
int lastSensor2State = 0; //Last Recorded state of sensor 2
int Sensor3State = 0; //Current state of Sensor 3
int lastSensor3State = 0; //Last Recorded state of sensor 3
//Defining current and previous state variables
void loop(void) {
//////////////////////////////////////////////////////////////////////////////////////
//SENSOR 0 PRESSURE PRINT CODE
if (Sens0 > threshold){
pressure0 = 1;
if (Sens0 < threshold) {
pressure0 = 0;
}
}
//Set pressure0 variable to "true" if the sensor is reading higher than the threshold
Sensor0State = pressure0; //Set Sensor state to the current state of the pressure0 variable
if (Sensor0State != lastSensor0State) {
//Check the sensor state against the last previous state
if (Sensor0State == 1){
// Check if the Sensor is reading more than 300
Serial.println(" SHUFFLE ");
// Print the Shuffle Order to Isadora
}
}
delay(50);
// Set a delay to avoid tripping over itself
lastSensor0State = Sensor0State;
// Save current state to previous state
//////////////////////////////////////////////////////////////////////////////////////
// SENSOR 1 PRESSURE PRINT CODE
if (Sens1 > threshold){
pressure1 = 1;
if (Sens1 < threshold) {
pressure1 = 0;
}
}
//Set pressure1 variable to "true" if the sensor is reading higher than the threshold
Sensor1State = pressure1; //Set Sensor state to the current state of the pressure1 variable
if (Sensor1State != lastSensor1State) {
//Check the sensor state against the last previous state
if (Sensor1State == 1){
// Check if the Sensor is reading more than 300
Serial.println(" SHUFFLE ");
// Print the Shuffle Order to Isadora
}
}
delay(50);
// Set a delay to avoid tripping over itself
lastSensor1State = Sensor1State;
// Save current state to previous state
//////////////////////////////////////////////////////////////////////////////////////
// SENSOR 2 PRESSURE PRINT CODE
if (Sens2 > threshold){
pressure2 = 1;
if (Sens2 < threshold) {
pressure2 = 0;
}
}
//Set pressure2 variable to "true" if the sensor is reading higher than the threshold
Sensor2State = pressure2; //Set Sensor state to the current state of the pressure2 variable
if (Sensor2State != lastSensor2State) {
//Check the sensor state against the last previous state
if (Sensor2State == 1){
// Check if the Sensor is reading more than 300
Serial.println(" SHUFFLE ");
// Print the Shuffle Order to Isadora
}
}
delay(50);
// Set a delay to avoid tripping over itself
lastSensor2State = Sensor2State;
// Save current state to previous state
//////////////////////////////////////////////////////////////////////////////////////
// SENSOR 3 PRESSURE PRINT CODE
if (Sens3 > threshold){
pressure3 = 1;
if (Sens3 < threshold) {
pressure3 = 0;
}
}
//Set pressure3 variable to "true" if the sensor is reading higher than the threshold
Sensor3State = pressure3; //Set Sensor state to the current state of the pressure3 variable
if (Sensor3State != lastSensor3State) {
//Check the sensor state against the last previous state
if (Sensor3State == 1){
// Check if the Sensor is reading more than 300
Serial.println(" SHUFFLE ");
// Print the Shuffle Order to Isadora
}
}
delay(50);
// Set a delay to avoid tripping over itself
lastSensor3State = Sensor3State;
// Save current state to previous state
}
/////////////////////
This all follows a logic, but it's not printing to the monitor. Am I missing something?