Hey everyone,
So for a new project of mine I am trying to use the new Arduino 1.0 system. But I seem to be having a bit of trouble with the new serial commands. Basically what I am trying to do is send 6 bytes to the arduino and have the arduino parse out those bytes and act accordingly. The byte is structured as such:
1) negotiator, such as '!"
2) motor/command selection '0-6'
3)motor speed, byte1
4)motor speed, byte2
5)motor speed, byte 3
6)terminator, such as '~'
The motor speed is made up of three bytes because I would like to send values '000' through '255' through the three bytes.
Does anyone have a good idea as to how i can receive the bytes, look for the negotiator, parse the next four bytes, and wrap/end everything up with the terminator??
I think I should be using the Serial.findUntil() and the Serial.parseint() commands but I can't get everything to work properly together.
I have the following code:
void useSerial()
{
//This function is for commanding the qik only through Serial
while(Serial.available() > 0)
{
Serial.println(Serial.available());
boolean ready = Serial.findUntil("!","~");
if(ready)
{
Serial.println(Serial.available());
if (Serial.available() == 4)
{
byte1 = Serial.read();
byte2 = Serial.read();
byte3 = Serial.read();
byte4 = Serial.read();
Debug();
}
}
}
}
and basically Serial.available seems to always be either 1 or 0, no matter how much info i send through.
Any help would be greatly appreciated.