Pages: 1 [2]   Go Down
Author Topic: Steering wheel control  (Read 2955 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 514
Posts: 31541
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 514
Posts: 31541
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: 1 [2]   Go Up
Jump to: