diff --git a/GPN-Lasertag.ino b/GPN-Lasertag.ino index 4c52c61bb22e053e9681370dda1b5a106c65f065..ff93789e8fb021ff50202324a1d178c12b898293 100644 --- a/GPN-Lasertag.ino +++ b/GPN-Lasertag.ino @@ -40,6 +40,9 @@ Menu *role_menu = new Menu(2); // 2 Items per page Player *player; GameServer *server; GameClient *client; +char pixIndex = 0; +bool changePixels = true; +unsigned long lastChange = 0; unsigned long lastNotificationPull = 0; void setup() { @@ -78,7 +81,7 @@ void hostGame() { #endif } -String recv_ir(){ +String recv_ir() { badge.setGPIO(IR_EN, HIGH); Serial.println("Entering receive mode"); String received = ""; @@ -91,14 +94,14 @@ String recv_ir(){ while (!dataCompleted && !done) { int on_time = 0; - decode_results results; // Somewhere to store the results + decode_results results; // Somewhere to store the results if (irrecv.decode(&results)) { if (results.overflow) { Serial.println("IR code too long. Edit IRremoteInt.h and increase RAWBUF"); return "a12\n7.0\n.0.\n1b"; } - char * buf = reinterpret_cast<char*>(&results.value); + char *buf = reinterpret_cast<char *>(&results.value); if (millis() - on_time > 500) { pixels.setPixelColor(1, pixels.Color(0, 0, 0)); @@ -109,7 +112,7 @@ String recv_ir(){ uint8_t checksum = buf[1]; dataCompleted = true; - if(checksum == checksumRec) { + if (checksum == checksumRec) { dataVerified = true; pixels.setPixelColor(1, pixels.Color(0, 100, 0)); } else { @@ -117,8 +120,7 @@ String recv_ir(){ } pixels.show(); on_time = millis(); - } - else { + } else { received += String(buf[0]) + buf[1] + buf[2] + buf[3]; checksumRec += buf[0] + buf[1] + buf[2] + buf[3]; Serial.printf("->:\n\t0: %c\n\t1: %c\n\t2: %c\n\t3: %c\n", buf[0], buf[1], buf[2], buf[3]); @@ -166,10 +168,17 @@ void loop() { if (millis() - lastNotificationPull > BADGE_PULL_INTERVAL) { if (connectBadge()) { + pixels.setPixelColor(pixIndex, pixels.Color(0, 0, 0)); pixels.setPixelColor(0, pixels.Color(0, 255, 0)); - } else { - lastNotificationPull = millis(); + changePixels = false; } + lastNotificationPull = millis(); + } + if (changePixels && millis() - lastChange > 1200) { + pixels.setPixelColor(pixIndex, pixels.Color(0, 0, 0)); + pixIndex = (pixIndex + 1) % 4; + pixels.setPixelColor(pixIndex, pixels.Color(255, 0, 0)); + lastChange = millis(); } pixels.show();