Issue with PS2 controller being output to terminal
Chemikal
Posts: 32
Ok, I am using the PS2 controller object from the exchange, and I can't figure out the following:
With the code below, both numbers output to the terminal are output as the exact same axis value... But if I either "rightX :=" or "rightY :=" statement is removed, then the proper values are displayed in the terminal.
It seems as if it is writing the same thing to both variables ("rightX" and "rightY")..?
The code:
** Num = Simple_Numbers.spin
** Serial = FullDuplexSerialPlus.spin
Thank you for your help,
- Josh
With the code below, both numbers output to the terminal are output as the exact same axis value... But if I either "rightX :=" or "rightY :=" statement is removed, then the proper values are displayed in the terminal.
It seems as if it is writing the same thing to both variables ("rightX" and "rightY")..?
The code:
PUB Main | rightX, rightY Serial.start(31, 30, 0, 57600) 'Start the terminal waitcnt(clkfreq*3 + cnt) ' --- PS2.Start(pDAT, 5000) 'first_pin is pDAT, Poll every 5ms repeat rightX := Num.decf(PS2.get_RightX,4) rightY := Num.decf(PS2.get_RightY,4) waitcnt(clkfreq/4 + cnt) Serial.str(rightX) Serial.str(String(" - ")) Serial.str(rightY) Serial.tx(13)
** Num = Simple_Numbers.spin
** Serial = FullDuplexSerialPlus.spin
Thank you for your help,
- Josh
Comments
If you do two conversions in a row, the buffer content gets overwritten during the 2nd call. The two returned
values are the identical address (that of the buffer). The solution is to use the string or copy it somewhere else
before you call Simple_Numbers again.
In your case, do "rightX := PS2.get_RightX" and "rightY := PS2.get_RightY" to save the numeric values, then
do the call to Simple_Numbers just before outputting it like "Serial.str(Num.decf(rightX,4))".
Post Edited (Mike Green) : 7/6/2008 4:19:12 AM GMT