Hi.
Im looking for a way to program a seesaw switch.
The switch that i have is not standard like a potentiometer but the resistance is pretty simple.
When im in the middle (i want the arduino do nothing) im at almost 2k omhs.
When im full on one side im around 7.5k and when im at the oposite im at 1.2k.
How can i set the arduino to do one thing at let say bellow 1.8 and more than 3?
How can i set the arduino to do one thing at let say bellow 1.8 and more than 3?
1.8 what? 3 what? The analogRead() function returns value between 0 and 1023. Some value represents the threshold where you want one thing to happen, and some other value represents the other threshold.
int val = analogRead(somePin);
if(val < lowerThreshold)
doLowThing();
else if(val > upperThreshold)
doHighThing();
Sorty my mistake its omhs. I mesure with a multimeter and this is the value that i have. The switch act like a potentiometer.
I understand the map value but i dont know how to map it with these number. Or i dont know how to program to have a specific treshold
Create a sketch that does nothing but read the analog pin, and print the result. Rotate the switch to the point that defines the boundary between too low and just right. Notice the value that is printed when the switch is there. That is the lower threshold. Keep rotating the switch until to the point that defines the boundary between just right and too high. Notice the value that is printed when the switch is there. That is the upper threshold.
meilleur102:
Ok good. I do that with serial print i guest??
Yes, and when you have the values just use a series of ifs to determine which range the switch is currently providing and hence the action to take. There is no need to map() the value, just use it as it is.