From 98eeb45fbb805b3bea54d590f5bb10af2b5e5a80 Mon Sep 17 00:00:00 2001 From: Prof Date: Fri, 4 Nov 2022 11:05:51 +0100 Subject: [PATCH] =?UTF-8?q?S=C3=A9quence=20Initialisation=20+=20Debug=20su?= =?UTF-8?q?r=20NanoRed=20Cr=C3=A9ation=20d'un=20second=20environnement=20p?= =?UTF-8?q?our=20debug=20sur=20Arduino=20Nano=20Red=20(Mega168P=2016Mhz)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformio.ini | 9 ++++++- src/main.cpp | 73 +++++++++++++++++++++----------------------------- 2 files changed, 39 insertions(+), 43 deletions(-) diff --git a/platformio.ini b/platformio.ini index dd241d4..978ad21 100644 --- a/platformio.ini +++ b/platformio.ini @@ -8,10 +8,17 @@ ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html -[env:pro8MHzatmega328] +[env:ProMini8MHz] platform = atmelavr board = pro8MHzatmega328 framework = arduino lib_deps = adafruit/Adafruit NeoPixel@^1.10.6 featherfly/SoftwareSerial@^1.0 +[env:NanoRouge] +platform = atmelavr +board = nanoatmega168 +framework = arduino +lib_deps = + adafruit/Adafruit NeoPixel@^1.10.6 + featherfly/SoftwareSerial@^1.0 \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 572dd25..2e9d985 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,14 +17,21 @@ 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; +void CUIZZ_Color_C2B(byte IDColor, byte* nRed, byte* nGreen, byte* nBlue){ + if(IDColor == 255){ + *nRed = 255; + *nGreen = 255; + *nBlue = 255; + } + else{ + *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); + return (((nRed/32) << 5) | ((nGreen/32) << 2) | nBlue/64); } //Envoi simple Message @@ -48,41 +55,19 @@ void CUIZZ_UpdateLED(unsigned long nDelay = 1){ byte CUIZZPixel_G[8]; byte CUIZZPixel_B[8]; + byte nRouge, nVert, nBleu; // 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; - } - } + for (byte i = 0; i < 8; i++) + { + CUIZZ_Color_C2B((CUIZZ_Score+i+1),&nRouge,&nVert,&nBleu); + CUIZZPixel_R[i] = nRouge; + CUIZZPixel_G[i] = nVert; + CUIZZPixel_B[i] = nBleu; } break; @@ -165,19 +150,23 @@ void setup() { // INIT Pin Buzzer pinMode(CUIZZ_PIN_Buzzer,INPUT_PULLUP); - if(CUIZZ_PIN_Buzzer == 2 || CUIZZ_PIN_Buzzer == 3) - { - attachInterrupt(digitalPinToInterrupt(CUIZZ_PIN_Buzzer),CUIZZ_Buzzer,CHANGE); - } - // Attente MASTER while(CUIZZ_GameMode == 0){ CUIZZ_GetMessage(); - if(CUIZZ_Score > 60){ + if(CUIZZ_Score > 247){ CUIZZ_Score = 0; } - CUIZZ_Score++; - CUIZZ_UpdateLED(50); + if(CUIZZ_GameState > 11){ + CUIZZ_Score++; + CUIZZ_GameState = 0; + } + else{CUIZZ_GameState++;} + CUIZZ_UpdateLED(20); + } + + if(CUIZZ_PIN_Buzzer == 2 || CUIZZ_PIN_Buzzer == 3) + { + attachInterrupt(digitalPinToInterrupt(CUIZZ_PIN_Buzzer),CUIZZ_Buzzer,CHANGE); } }