Hi all,
Probably a very basic solution will apply here but I would appreciate any help.
I am creating an interface whereby a user can place a physical weight on one of two force sensors (resistive).
When the "vote yes" or "vote no" sensor has weight applied, the resistance drops and my analog pins can read this.
My Arduino then serial prints once, "Vote Yes" or "Vote No" but only if the state of the sensors has changed. Otherwise it will print "Neutral". (From here my macbook has a serial reader app and will run an applescript.)
My question is: How can I include my leds in pins 12 and 13 to indicate when there is weight present on either of the sensors?
For example, if the Vote Yes sensor has weight applied, I would like led12 to light up and stay on so long as weight is present, but only serial print "Vote Yes" once.
I hope this makes more sense with the present code:
int Led_Pin1 = 13; // Yes indicator LED
int Led_Pin2 = 12; // No indicatior LED
int Yes_Pin = A0; // Yes sensor pad
int No_Pin = A1; // No sensor pad
int State = 0;
int State2 = 0;
int lastState2 = 0;
int lastState = 0; // Set all states to zero.
void setup() {
pinMode(Yes_Pin, INPUT); // Declare Yes sensor as an input
pinMode(No_Pin, INPUT); // Declare No sensor as an input
Serial.begin(9600); // Read from serial
}
void loop() { // Begin loop
State = analogRead(No_Pin); // Read state from No Pin
State2 = analogRead(Yes_Pin); // Read state from Yes Pin
if (State != lastState) { // Compare states
if (State == 1023) { // If pad is compressed
Serial.println("Vote No"); // Vote No sent via USB
} else { // If pad is de-compressed
Serial.println("Neutral"); // Neutral is sent via USB
} delay(200); // Wait 0.2s
} if (State2 != lastState2) { // Compare states
if (State2 == 1023) { // If pad is compressed
Serial.println("Vote Yes"); // Vote Yes is sent via USB
} else { // If pad is de-compressed
Serial.println("Neutral"); // Neutral is sent via USB
} delay(200); // Wait 0.2s
} lastState = State; // Remember No pad state
lastState2 = State2; // Remember Yes pad state
}
I know how to use the LEDs as indicators without the state of change, but I can't figure out the code that can do both.
Many Thanks