Hello everyone , I am a beginner knowing good solid base that I judge.
I just wonder how can we send a byte by choosing the bits Into this byte. I simply ask you to guide me and I wish all to even try to build every single program that suits me. My program aims to send 2 byte to another Arduino receiver , a byte that includes a 3-bit addressing and 3 bits commands. The other byte will be the value of a potentiometer . Thank you and wish you happy holiday season.
Here's one way, manipulating each bit individually
byte byteToSend;
void setup(){
Serial.begin(9600);
}
void loop(){
if (set_bit0 == true){
byteToSend = byteToSend | 0b00000001; // set bit 0, leave rest alone
}
if (clear_bit0 == true){
byteToSend = byteToSend & 0b11111110; // set bit 0, leave rest alone
}
// etc. for other bits based on whatever criteria you are using
Serial.write (byteToSend); // send it out
// and then start again
} //end loop
Hello and thank you for your help.
I think it would be really hard for me to take it that way because I need to send a first byte consists of 3 address bits (I think you have understood ) and 3 bits of commands that will be used LEDs to light or change the direction of rotation of a motor by the button ( the 3-bit binary good about who will say that for 0 eg LEDs are off and one will be on) , the MSB will be 1 differentiate the second which will have its MSB to 0. The second byte understand the value of a potentiometer . The byte address must be sent before the one with the potentiometer for the Arduino receiver recognizes that it is good for him and not for Arduino that will have a different address ( this will be through the transmission XBee already configured and c ' that this is my college charge of the reception of my data).
I also wondered if it was possible to use the string function for this manipulation.
I thank you once again for your quick response and help. Have a nice day .
LucasNR:
I think it would be really hard for me to take it that way because I need to send a first byte consists of 3 address bits (I think you have understood ) and 3 bits of commands
Just use the technique suggested by @CrossRoads to change whatever bits you need.
It would help if you give us some examples of the sort of byte data you want to send.
...R
Post a bit function list as follows:
Byte_1
bit0: [function]
bit1: [function]
etc.
Byte_2
bit0: [function
bit1: [function]
etc.
Byte_3
bit0: [function]
bit1: [function]
etc.
simply ask you to guide me and I wish all to even try to build every single program that suits me.
This is a help forum, not a program writing service. We'll guide you , but you have to write the code.
Hello everyone , first of all I apologize for my absence these days I was caught in my work. I try to make a program on how to CrossRoads but unfortunately it does not suit me because that way we send one byte for each order or my request is to send one byte comprising bits commands. I'll try your raschemmel way, I thank you all for your help.
Read up on bitwise operators, for example Bitwise Operators in C and C++ - Cprogramming.com
They are the key to what you want to do. Understand what they do, and you should be able to figure out how to do what you want.