Help with SELECT-CASE
Cogburn
Posts: 62
Hey guys,
I am using a linear taper potentiometer and the RC-Time command to obtain readings for a wind direction indicator.· The pot has been modified by removing the stop so that it is free to move in all directions.· I have mapped out the values that are stored in my variable "result" for 8 compass directions.· I am trying to use "select case " as the basis for the debug output.· I am getting proper readings as I am temporarily displaying the DEC result along side of the direction so I know the variable is being updated properly but I cannot seem to get the direction to debug correctly.· I am only getting "SOUTHEAST" and "NORTH" no matter what the value of "result" is.· I am including my code here and I wonder if someone might be kind enough to make a suggestion as to a fix for it.
'{$STAMP BS2}································ ' specifies a BS2
' {$PBASIC 2.5}
result· VAR Word······························· ' Word to hold result
Main:
· DO
··· HIGH 7····································· ' Discharge the cap
··· PAUSE 1000·······························'·· for 1 s
··· RCTIME 7, 1, result······················' Measure RC charge time
·SELECT result
· CASE result = 0
· DEBUG "WIND FROM EAST·· " , DEC result
· CASE· result = 1
· DEBUG "WIND FROM NORTHEAST·· ", DEC result
· CASE 1 < result < 200
· DEBUG· "WIND FROM NORTH·· " , DEC result
· CASE 200 < result < 420
· DEBUG "WIND FROM NORTHWEST·· "· , DEC result
· CASE 420 <· result < 550
· DEBUG "WIND FROM WEST·· "· , DEC result
· CASE 550 <· result < 700
· DEBUG "WIND FROM SOUTHWEST·· " , DEC result
· CASE 700 <· result < 722
· DEBUG "WIND FROM SOUTH·· "· ,DEC result
· CASE·· result > 723
· DEBUG "WIND FROM SOUTHEAST·· " , DEC result
· CASE ELSE
· DEBUG "OBTAINING WIND DIRECTION·· " , DEC result
· ENDSELECT
······················· ' Show value on screen
· LOOP
Post Edited By Moderator (Jon Williams) : 1/20/2005 8:18:31 PM GMT
I am using a linear taper potentiometer and the RC-Time command to obtain readings for a wind direction indicator.· The pot has been modified by removing the stop so that it is free to move in all directions.· I have mapped out the values that are stored in my variable "result" for 8 compass directions.· I am trying to use "select case " as the basis for the debug output.· I am getting proper readings as I am temporarily displaying the DEC result along side of the direction so I know the variable is being updated properly but I cannot seem to get the direction to debug correctly.· I am only getting "SOUTHEAST" and "NORTH" no matter what the value of "result" is.· I am including my code here and I wonder if someone might be kind enough to make a suggestion as to a fix for it.
'{$STAMP BS2}································ ' specifies a BS2
' {$PBASIC 2.5}
result· VAR Word······························· ' Word to hold result
Main:
· DO
··· HIGH 7····································· ' Discharge the cap
··· PAUSE 1000·······························'·· for 1 s
··· RCTIME 7, 1, result······················' Measure RC charge time
·SELECT result
· CASE result = 0
· DEBUG "WIND FROM EAST·· " , DEC result
· CASE· result = 1
· DEBUG "WIND FROM NORTHEAST·· ", DEC result
· CASE 1 < result < 200
· DEBUG· "WIND FROM NORTH·· " , DEC result
· CASE 200 < result < 420
· DEBUG "WIND FROM NORTHWEST·· "· , DEC result
· CASE 420 <· result < 550
· DEBUG "WIND FROM WEST·· "· , DEC result
· CASE 550 <· result < 700
· DEBUG "WIND FROM SOUTHWEST·· " , DEC result
· CASE 700 <· result < 722
· DEBUG "WIND FROM SOUTH·· "· ,DEC result
· CASE·· result > 723
· DEBUG "WIND FROM SOUTHEAST·· " , DEC result
· CASE ELSE
· DEBUG "OBTAINING WIND DIRECTION·· " , DEC result
· ENDSELECT
······················· ' Show value on screen
· LOOP
Post Edited By Moderator (Jon Williams) : 1/20/2005 8:18:31 PM GMT
Comments
And don't forget to add a subject title to your threads (I fixed this one).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas, TX· USA
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Showing up to school doesn't·mean you are a student any more than crawling up in an oven means that·you are a biscuit.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas, TX· USA
Mike S.
Thanks to all for the help.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Showing up to school doesn't·mean you are a student any more than crawling up in an oven means that·you are a biscuit.
you could try the Parallax Boe-Bot encoders and design your own disk.
bugg
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
So many projects, so little time.
They all have deadzones...but it's nice to find them with a very small deadzone.
I work for Environment Canada and I think our sensors are rated for a 5deg deadband...but they are sometimes less!
On one of our newer sensors we use an optical mask that rotates with the vane and masks out different LEDs for a given direction (very fancy looking mask!).
Our newest sensor looks nearly like a trident...but picture each point making up a triangle.· This one uses ultrasonic vibrations and temperature to determine direction and speed.· It's nice because there are no moving parts and we don't have to worry about it icing up (has a built in heater).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·
Steve
http://members.rogers.com/steve.brady
"Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."
I have used them in the past, both carbon which wore pretty bad and wire used in azmuth indicators.
73
spence
k4kep
In our radars we use synchro's for angle readback....more like a motor/gen...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·
Steve
http://members.rogers.com/steve.brady
"Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."
www.fascinatingelectronics.com/weatherinst.html#windvane
Cogburn,
Another way to skin the original problem is to use the LOOKDOWN command:
LOOKDOWN result,<=[noparse][[/noparse]0,1,2,200,420,550,700,65535],index
that leaves values from 0 to 7 in the variable, index, corresponding to the 8 directions. That simplifies the SELECT CASE statements, or the index can be used to address the strings to print stored more efficiently in DATA eeprom.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com