Go Down

Topic: Steering wheel control (Read 4463 times) previous topic - next topic

themlruts


For what? It dosn't look like a case statement is sutiable here.

Mike i was thinking that i could used case for the different resistances I was looking for.  If you look at my first post those are the Resistances i need to detect

Grumpy_Mike

The thing is that if you do an analogue measurement you are not going to get a precise repeatable result.
A case statement will only work with integers and not with ranges. What you need to do is to have a look up table (an array) with a range of values in it. Then search through the array until you find the entry that fits your value. Then use that array entry number in the case statement.

However, if you only have a few values then use a sequence of if statements with two values, greater than and less than like you had but with a much greater range. Do some measurements and print them out to get an idea of the real values, then set the range limits between the readings you get.

themlruts


The thing is that if you do an analogue measurement you are not going to get a precise repeatable result.
A case statement will only work with integers and not with ranges. What you need to do is to have a look up table (an array) with a range of values in it. Then search through the array until you find the entry that fits your value. Then use that array entry number in the case statement.

However, if you only have a few values then use a sequence of if statements with two values, greater than and less than like you had but with a much greater range. Do some measurements and print them out to get an idea of the real values, then set the range limits between the readings you get.

How would you recommend doing it?  Can I measure it digitally instead?  I want to make the code as streamed line as i can so it is responsive

Grumpy_Mike

Take the output of the switch and connect it between an analogue input pin and ground, have a pull resistor from the input to +5V of approximately one quarter of the maximum resistance you get from pushing the buttons.
Then make a note of the values you read when pushing all the buttons.

Go Up