Simple input reading
francis_L_H
Posts: 10
I am having a small task that is turning out to be a bigger problem than needs to be and taking up too much time. I am simply trying to assign a certain value to a variable based on a given user input.
I have three possible user inputs, pins 21, 22, and 23. The program awaits for the user to make a choice between 1 of 3 push buttons assigned to the mentioned pins, based on which button is pushed determines what the value of the variable should be. The section of code at hand follows:
dira[23..21] := outa[23..21] := %000
LCD.Str(String("Select Length",13))
repeat until ina[21] or ina[22] or ina[23]
Temp := ina[23..21]
if Temp[0] := 1
th := 96
elseif Temp[1] := 1
th := 120
elseif Temp[2] := 1
th := 180
The code will wait for the user to push one of the buttons, but regardless of which is pushed, it will always use the first statement to assign the value of the variable. In this case th = 96. Why can I not look at each bit and assign the corresponding value if the corresponding button was pushed?
I have three possible user inputs, pins 21, 22, and 23. The program awaits for the user to make a choice between 1 of 3 push buttons assigned to the mentioned pins, based on which button is pushed determines what the value of the variable should be. The section of code at hand follows:
dira[23..21] := outa[23..21] := %000
LCD.Str(String("Select Length",13))
repeat until ina[21] or ina[22] or ina[23]
Temp := ina[23..21]
if Temp[0] := 1
th := 96
elseif Temp[1] := 1
th := 120
elseif Temp[2] := 1
th := 180
The code will wait for the user to push one of the buttons, but regardless of which is pushed, it will always use the first statement to assign the value of the variable. In this case th = 96. Why can I not look at each bit and assign the corresponding value if the corresponding button was pushed?
Comments
if Temp[0] == 1
not
if Temp[0] := 1
:= would set the variable to 1 no?
Where as == would check to see if its equal to 1?
Correct. You are assigning the value of 1 to each test, not checking to see what the value is.
It would be best to work with individual pins instead of trying to read all 3 like that.
Another thing to do when having these kinds of problems, is to see what you are really getting prior to assigning the inputs to variables:
Push each button and make sure the system is seeing what it should. Then assign the inputs to variables, print out the variables too and make sure they are what they should be.
Thanks again.
I wish I could figure out the 'best way to learn' myself, things would then get a lot easier.
If you think about it when you are a child you only have to burn yourself once on the oven to know that you shouldn't touch it again. Your mother could tell you a hundred times but until you learn the lesson through pain it will never stick.