From 79ab9547ff483da85cfa643d36ecb5294676e704 Mon Sep 17 00:00:00 2001 From: Prof Date: Fri, 4 Nov 2022 00:40:35 +0100 Subject: [PATCH] Premier Jet - Attente Fin Code --- platformio.ini | 4 +- src/main.cpp | 173 +++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 170 insertions(+), 7 deletions(-) diff --git a/platformio.ini b/platformio.ini index f8e533c..dd241d4 100644 --- a/platformio.ini +++ b/platformio.ini @@ -12,4 +12,6 @@ platform = atmelavr board = pro8MHzatmega328 framework = arduino -lib_deps = adafruit/Adafruit NeoPixel@^1.10.6 +lib_deps = + adafruit/Adafruit NeoPixel@^1.10.6 + featherfly/SoftwareSerial@^1.0 diff --git a/src/main.cpp b/src/main.cpp index dba5cd8..572dd25 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,19 +1,152 @@ #include #include +#include -#define CUIZZ_Color 1 // 0 - MASTER, 1 - Blanc, 2 - Rouge, 3 - Vert, 4 - Bleu, 5 - Jaune -#define CUIZZ_Interrupt 6 +#define CUIZZ_PIN_Buzzer 2 +#define CUIZZ_PIN_LED 4 +#define CUIZZ_NB_LED 8 +#define CUIZZ_SERIAL_TX 8 +#define CUIZZ_SERIAL_RX 9 byte CUIZZ_GameMode; // 0 - Attente Init, 1 - byte CUIZZ_GameState; -byte CUIZZ_Players[6]; byte CUIZZ_Score; +byte CUIZZ_MyID; +SoftwareSerial HC12(CUIZZ_SERIAL_TX,CUIZZ_SERIAL_RX); +Adafruit_NeoPixel CUIZZPixel(CUIZZ_NB_LED,CUIZZ_PIN_LED,NEO_GRB + NEO_KHZ800); + +// Calcul Couleur RGB sur 1 Byte +void CUIZZ_Color_C2B(byte IDColor, byte nRed, byte nGreen, byte nBlue){ + nRed = (IDColor >> 5) * 32; + nGreen = ((IDColor & 28) >> 2) * 32; + nBlue = (IDColor & 3) * 64; +} + +byte CUIZZ_Color_B2C(byte nRed, byte nGreen, byte nBlue){ + return ((nRed << 5) | (nGreen << 2) | nBlue); +} + +//Envoi simple Message void CUIZZ_SendMessage(byte TypeMessage, byte Destinataire){ + char TheMessage[15] = ""; // Définition des Types de Messages /* 1 - Send Lock Box */ + + // Send message + HC12.write(TheMessage,15); + Serial.write(TheMessage,15); + Serial.flush(); + HC12.flush(); + +} + +void CUIZZ_UpdateLED(unsigned long nDelay = 1){ + byte CUIZZPixel_R[8]; + byte CUIZZPixel_G[8]; + byte CUIZZPixel_B[8]; + + // OFF + CUIZZPixel.clear(); + + switch (CUIZZ_GameMode) + { + case 0: // Game Mode - Attente Initialisation + if(CUIZZ_Score < 20 ){ + // LED en ROUGE + for (byte i = 0; i < 8; i++) + { + CUIZZPixel_R[i] = 255; + CUIZZPixel_G[i] = 0; + CUIZZPixel_B[i] = 0; + } + + } + else{ + if(CUIZZ_Score < 40 ){ + // LED en VERT + for (byte i = 0; i < 8; i++) + { + CUIZZPixel_R[i] = 0; + CUIZZPixel_G[i] = 255; + CUIZZPixel_B[i] = 0; + } + } + else{ + // LED en Bleu + for (byte i = 0; i < 8; i++) + { + CUIZZPixel_R[i] = 0; + CUIZZPixel_G[i] = 0; + CUIZZPixel_B[i] = 255; + } + } + } + break; + + default: + break; + } + + // ON + for(byte i=0; i 0){ + if(nNB_Bytes == 15){ + for(int i=0;i 0){ + if(nNB_Bytes == 15){ + for(int i=0;i 60){ + CUIZZ_Score = 0; + } + CUIZZ_Score++; + CUIZZ_UpdateLED(50); + } + } void loop() { - // put your main code here, to run repeatedly: + // Lecture Message + CUIZZ_GetMessage(); + if (digitalRead(CUIZZ_PIN_Buzzer) == LOW) { + CUIZZ_Buzzer(); + } } \ No newline at end of file