Home › Forums › EasyTransfer Library Support Forum › little problem with timing › Reply To: little problem with timing
I don’t know what could be wrong without looking at the rest of your code, but I do suggest a more efficient way to do what you are trying to do.
You are trying to send 6 boolean (yes/no) values, however the smallest unit of data in an AVR is a byte of 8 bits. So each boolean uses up a whole byte of data space. So to send 6 yes/no values you are using up 6 whole bytes or 48 bits of data. Instead, you could encode all of your boolean values into a single byte. Here’s an example:
//first create a naming to position address convention, this is just to make it easier for us
#define SCAN 0
#define FORWARD 1
#define STOP 2
#define REVERSE 3
#define LEFT 4
#define RIGHT 5
//create a variable that will hold all the values.
byte commands;
//When we want to set a value to 1 (true) we do this
bitSet(commands, FORWARD);
bitSet(commands, LEFT);
//When we want to clear a value (set to 0, false) we do this
bitClear(commands, RIGHT);
bitClear(commands, SCAN);
//When we want to act on the different values
if(bitRead(commands, FORWARD) == true)
Do Something;
if(bitRead(commands, SCAN) == false)
Stop Something;
So it looks a bit different but it is a much more efficient way to encode binary (on or off) information. Give it a try and see if it works out for you.
You could also set a value directly from a digital input pin like this:
bitWrite(commands, FORWARD, digitalRead(13));
That will set the FORWARD bit TRUE if pin 13 is HIGH or FALSE if the pin is LOW.