Both - stalk and knob are connected to analog inputs. What difference does it make?
What difference does it make? Are you seriously asking that?
Whats wrong with setting pinMode?
Analog pins are, by definition, output only. There is no need to tell an analog pin that it is an output pin. As a result, the pinMode command applies only to digital pins. Setting the mode of digital pins 0 and 1, and using Serial at the same time, is generally not a good idea. Digital pins 0 and 1 ARE the hardware serial port.
the stalk is like momentary switch. after each press it returns to ''0''
Then, you need to store its value when it is not 0, and do not overwrite that value when it is 0.
so I need to monitor the previous state? I dont get this part.
int nonZeroVal = 0;
int val = analogRead(stalkPin);
if(val > 0)
npnZeroVal = val;
if(nonZeroVal > 940 && nonZeroVal < 980)
// Move the servo
else // Remaining clauses...
''Why do you not print the value from the map function (with some prefix so you know what the value being printed is?''
this I dont understand either
You have Serial.println(val); in your code now. So, in the serial monitor, you see a series of numbers, one per line. What do those numbers mean?
If you add Serial.println(pos); to the code, now you see two series of numbers, mixed. Which is which? What do any of the numbers mean?
If you had:
Serial.print("stalk val: ");
Serial.print("servo pos: ");
you would still have two series of values, mixed together, but you would know what each number meant.