Skip to content

Instantly share code, notes, and snippets.

@Phyks
Last active December 29, 2015 03:39
Show Gist options
  • Save Phyks/7609044 to your computer and use it in GitHub Desktop.
Save Phyks/7609044 to your computer and use it in GitHub Desktop.
void serialEvent() {
//serialEvent est appelée à la fin de la boucle si des données sont dispos sur le RX
while(Serial.available()) {
incoming_byte = (byte) Serial.read();
if(highByte(incoming_byte)) {
// Header
serial_i = incoming_byte & B00011111; // serial_i = compteur
// Note: serial_i = 0 => à traiter
// Note : [Unused] serial_fonction = (incoming_byte >> 5) & B011;
if(serial_i != 0) {
// Forward
Serial.print((incoming_byte & B11100000) | (serial_i - 1)); // Décrément du compteur
serial_i = -1
}
if(incoming_byte && B01100000 == 2) {
// Broadcast
Serial.print(incoming_byte & B11100000); // Forward avec compteur nul
}
}
else {
// Paquet de couleur
if(serial_i != -1) {
// Si on doit traiter le paquet, on le fait
duty[serial_i] = (incoming_byte & B01111111) << 1;
serial_i++;
}
else {
// Sinon, on forward tel quel
Serial.print(incoming_byte);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment