Hi, I'm trying to create a app to read 2 Pot values. There will be 3 buttons. I'd like to hit a button, save the values-then move the pots, save the values-then utilize that data later...But I can't seem to make it work. Button 1 will save the 2 pot values to start1, start2. Button 2 will save save the pot values to start2, end2. Then Button 3 currently just displays the data. Also, besides the point, I can't figure out how to make it stop displaying data. Would a function be useful here? I tried that, but had much bad luck...
So far, all I can get out are the same pot values on start1, start2 as end1, end2. What the??? I must be missing something basic. I'm a newbie, so please bear with me. Any thoughts here?
int potPin1 = 0;
int potPin2 = 1;
int potVal1 = 0;
int potVal2 = 0;
int panVal = 0;
int tiltVal = 0;
int startPin = 11; // start pin
int endPin = 12; // end pin
int runPin = 8; // run pin
void setup()
{
Serial.begin(9600);
pinMode(startPin, INPUT); // declare pushbutton as input
pinMode(endPin, INPUT); // declare pushbutton as input
pinMode(runPin, INPUT); // declare pushbutton as input
}
void loop()
{
// Control servos with Pots
potVal1 = analogRead(potPin1);
potVal2 = analogRead(potPin2);
// Read button 1
int startVal;
int endVal;
int start1 = 0;
int start2 = 0;
startVal = digitalRead(startPin); // read input value
if (startVal == HIGH) { // check if the input is HIGH
start1 = potVal1; // Set start point for pan
start2 = potVal2; // Set start point for pan
}
// Read button 2
int end1=0;
int end2=0;
endVal = digitalRead(endPin); // read input value
if (endVal == HIGH) { // check if the input is LOW
end1 = potVal1; // Set end point for pan
end2 = potVal2; // Set end point for tilt
}
// Read 3rd button and display results
int runVal = 0;
runVal = digitalRead(runPin); // read input value
if (runVal == HIGH) { // check if the input is HIGH
Serial.println("start1 = ");
Serial.println(start1, DEC);
Serial.println("start2 = ");
Serial.println(start2, DEC);
Serial.println("end1 = ");
Serial.println(end1, DEC);
Serial.println("end2 = ");
Serial.println(end2, DEC);
}
}