Decoding Lines of code from buttons
RMCanaway
Posts: 16
in Propeller 1
So I have been designing a robotics controller for my school over the past year. as of right now I'm testing the button data being sent to the xbee on the receiver from the transmitting controller. The Button data (pins 0-7) are being sent in a 8-bit packet. The issue I'm having right now is to know which button is being pressed from those bits on the receiver (ex. 10000000 (This would be the 1st button on pin 0 being pressed on the transmitter)). I will upload my code. I've been searching everywhere for awhile, Xbee manuals, Spin references. Please let me know any ideas that would help me complete this project sooner
the temporary code 10.12.19 is for the transmitter
Thanks,
Ryan Canaway
the temporary code 10.12.19 is for the transmitter
Thanks,
Ryan Canaway
Comments
If you want to check for bit7 of the buttons value sent accross XBee you could do this:
Since you don't have many buttons you could create mask constants and do something like this:
...which would be a little faster as it doesn't have to call the bit_state() method. I think it would make the code more readable as well.
I'm thinking of doing the second option. however whenever i put it in my code and try to upload it. I get a "Expected end of line" message on the left parenthesis in bit_state(buttons, 7)
On the transmit side, you are sending all 4 bytes of the buttons variable. Why? There are only 8 bits for the buttons and they are all in the first one sent.
On the receive side, you have it waiting for 1 byte after the ! but the other three bytes that were sent have to be cleared out. Right after that, you have That will receive the second byte of the transmission, which by my view will always be a zero. The last two bytes of the trasmission will be cleared out when waiting for the next key "!". It could be simplified to the one byte you need to transmit. Just send the one relevant bytes, buttons (no "!" necessary) and have one instruction to read the byte to buttons on the receive side.
The syntax of that statement, (xbee.rx & |< 1) is weird. For decoding buttons try one of the methods that Jon suggested. You have to define the method
PUB bit_state(value, bitpos)
Unless you define it, it will throw the error you saw.
In your receiver code the variable temp is defined as local in the PUB call, but then you have, temp is a single long, but the longfill will also zero out index and six additional longs in memory. Can have unintended bad consequences. :-O
I have taken out the repeat on the transmit side so It just sends one bit of data at a time. I'm still having issues reading individual bytes. if you could help me out, that would be spectacular .