Merge branch 'feature/ledBtn' into 'main'
changement de version board manager See merge request SAE_203_2025/grA_21_Morpion_lumineaux/gra_21_morpion_lumineux_code!7
This commit is contained in:
commit
fc7eec2b44
@ -14,6 +14,8 @@ Adafruit_MPR121 cap = Adafruit_MPR121();
|
|||||||
uint16_t lasttouched = 0;
|
uint16_t lasttouched = 0;
|
||||||
uint16_t currtouched = 0;
|
uint16_t currtouched = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
randomSeed(analogRead(0));
|
randomSeed(analogRead(0));
|
||||||
|
|||||||
251
localMode.cpp
251
localMode.cpp
@ -6,15 +6,15 @@
|
|||||||
extern Adafruit_SH1107 display;
|
extern Adafruit_SH1107 display;
|
||||||
|
|
||||||
MechKey keys[] = {
|
MechKey keys[] = {
|
||||||
{0, A0, false, Adafruit_NeoPixel(1, A0, NEO_GRB + NEO_KHZ800)},
|
{0, A0, false, Adafruit_NeoPixel(1, D4, NEO_GRB + NEO_KHZ800)}, //D4
|
||||||
{1, 25, false, Adafruit_NeoPixel(1, 25, NEO_GRB + NEO_KHZ800)},
|
{1, 25, false, Adafruit_NeoPixel(1, D5, NEO_GRB + NEO_KHZ800)},
|
||||||
{2, 34, false, Adafruit_NeoPixel(1, 34, NEO_GRB + NEO_KHZ800)},
|
{2, 34, false, Adafruit_NeoPixel(1, A0, NEO_GRB + NEO_KHZ800)},
|
||||||
{3, 39, false, Adafruit_NeoPixel(1, 39, NEO_GRB + NEO_KHZ800)},
|
{3, 39, false, Adafruit_NeoPixel(1, A1, NEO_GRB + NEO_KHZ800)},
|
||||||
{4, 36, false, Adafruit_NeoPixel(1, 36, NEO_GRB + NEO_KHZ800)},
|
{4, 36, false, Adafruit_NeoPixel(1, 16, NEO_GRB + NEO_KHZ800)},
|
||||||
{5, 4, false, Adafruit_NeoPixel(1, 4, NEO_GRB + NEO_KHZ800)},
|
{5, 4, false, Adafruit_NeoPixel(1, 17, NEO_GRB + NEO_KHZ800)},
|
||||||
{6, 14, false, Adafruit_NeoPixel(1, 14, NEO_GRB + NEO_KHZ800)},
|
{6, 14, false, Adafruit_NeoPixel(1, D2, NEO_GRB + NEO_KHZ800)},
|
||||||
{7, 33, false, Adafruit_NeoPixel(1, 33, NEO_GRB + NEO_KHZ800)},
|
{7, 33, false, Adafruit_NeoPixel(1, D3, NEO_GRB + NEO_KHZ800)}, //D3
|
||||||
{8, 15, false, Adafruit_NeoPixel(1, 15, NEO_GRB + NEO_KHZ800)},
|
{8, 15, false, Adafruit_NeoPixel(1, 4, NEO_GRB + NEO_KHZ800)},
|
||||||
};
|
};
|
||||||
const int numKeys = 9;
|
const int numKeys = 9;
|
||||||
|
|
||||||
@ -32,23 +32,40 @@ unsigned long lastDebounceReset = 0;
|
|||||||
const unsigned long debounceDelayReset = 200;
|
const unsigned long debounceDelayReset = 200;
|
||||||
uint8_t btnPrev = LOW;
|
uint8_t btnPrev = LOW;
|
||||||
uint8_t btn;
|
uint8_t btn;
|
||||||
|
bool isFirstInit = true;
|
||||||
|
|
||||||
|
|
||||||
|
bool isWin = false;
|
||||||
|
|
||||||
|
int c1[] = {-1,-1};
|
||||||
|
int c2[] = {-1,-1};
|
||||||
|
int c3[] = {-1,-1};
|
||||||
|
|
||||||
void setBtn(Adafruit_MPR121& cap, uint16_t& lasttouched, uint16_t& currtouched){
|
void setBtn(Adafruit_MPR121& cap, uint16_t& lasttouched, uint16_t& currtouched){
|
||||||
|
if(isFirstInit){
|
||||||
|
turnOff();
|
||||||
|
isFirstInit = false;
|
||||||
|
}
|
||||||
display.clearDisplay();
|
display.clearDisplay();
|
||||||
display.setCursor(0, 0);
|
display.setCursor(0, 0);
|
||||||
display.print("Veuillez rester\nappuye sur chaqu'un\ndes boutons pendant\n3 secondes avant de\nles relacher pour\nles initialiser");
|
display.print("Rester appuye sur\nchaqu'un des boutons\npendant 3 secondes\npour les initialiser");
|
||||||
display.display();
|
display.display();
|
||||||
|
|
||||||
if(allInit()){
|
if(allInit()){
|
||||||
isBtnSet = true;
|
isBtnSet = true;
|
||||||
|
for (int i = 0; i < numKeys; i++) {
|
||||||
|
keys[i].led.setPixelColor(0, 0,0,0);
|
||||||
|
keys[i].led.show();
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
currtouched = cap.touched();
|
currtouched = cap.touched();
|
||||||
for (int i = 0; i < numKeys; i++) {
|
for (int i = 0; i < numKeys; i++) {
|
||||||
uint8_t t = keys[i].touchID;
|
uint8_t t = keys[i].touchID;
|
||||||
keys[i].led.setPixelColor(0, 255); // Bleu
|
|
||||||
keys[i].led.show();
|
|
||||||
if ((currtouched & _BV(t)) && !(lasttouched & _BV(t))) {
|
if ((currtouched & _BV(t)) && !(lasttouched & _BV(t))) {
|
||||||
Serial.print("Touch "); Serial.print(t); Serial.println(" pressed");
|
Serial.print("Touch "); Serial.print(t); Serial.println(" pressed");
|
||||||
btns[i] = true;
|
btns[i] = true;
|
||||||
|
keys[i].led.setPixelColor(0, 255,255,255);
|
||||||
|
keys[i].led.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lasttouched = currtouched;
|
lasttouched = currtouched;
|
||||||
@ -73,16 +90,44 @@ Coord getCo(int key) {
|
|||||||
bool victoire(int grille[3][3], int joueur) {
|
bool victoire(int grille[3][3], int joueur) {
|
||||||
// Vérification des lignes et colonnes
|
// Vérification des lignes et colonnes
|
||||||
for (int i = 0; i < 3; ++i) {
|
for (int i = 0; i < 3; ++i) {
|
||||||
if (grille[i][0] == joueur && grille[i][1] == joueur && grille[i][2] == joueur)
|
if (grille[i][0] == joueur && grille[i][1] == joueur && grille[i][2] == joueur){
|
||||||
return true;
|
c1[0]=i;
|
||||||
if (grille[0][i] == joueur && grille[1][i] == joueur && grille[2][i] == joueur)
|
c1[1]=0;
|
||||||
return true;
|
c2[0]=i;
|
||||||
|
c2[1]=1;
|
||||||
|
c3[0]=i;
|
||||||
|
c3[1]=2;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (grille[0][i] == joueur && grille[1][i] == joueur && grille[2][i] == joueur){
|
||||||
|
c1[0]=0;
|
||||||
|
c1[1]=i;
|
||||||
|
c2[0]=1;
|
||||||
|
c2[1]=i;
|
||||||
|
c3[0]=2;
|
||||||
|
c3[1]=i;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Vérification des deux diagonales
|
// Vérification des deux diagonales
|
||||||
if (grille[0][0] == joueur && grille[1][1] == joueur && grille[2][2] == joueur)
|
if (grille[0][0] == joueur && grille[1][1] == joueur && grille[2][2] == joueur){
|
||||||
return true;
|
c1[0]=0;
|
||||||
if (grille[0][2] == joueur && grille[1][1] == joueur && grille[2][0] == joueur)
|
c1[1]=0;
|
||||||
return true;
|
c2[0]=1;
|
||||||
|
c2[1]=1;
|
||||||
|
c3[0]=2;
|
||||||
|
c3[1]=2;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (grille[0][2] == joueur && grille[1][1] == joueur && grille[2][0] == joueur){
|
||||||
|
c1[0]=0;
|
||||||
|
c1[1]=2;
|
||||||
|
c2[0]=1;
|
||||||
|
c2[1]=1;
|
||||||
|
c3[0]=2;
|
||||||
|
c3[1]=0;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,16 +138,6 @@ bool allInit() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void afficheGrille() {
|
|
||||||
Serial.println("==============");
|
|
||||||
for(int i = 0; i < 3; i++) {
|
|
||||||
for(int j = 0; j < 3; j++) {
|
|
||||||
Serial.print(grille[i][j]);
|
|
||||||
}
|
|
||||||
Serial.println();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void reset() {
|
void reset() {
|
||||||
Serial.println("Reset");
|
Serial.println("Reset");
|
||||||
|
|
||||||
@ -111,9 +146,12 @@ void reset() {
|
|||||||
grille[i][j] = 0;
|
grille[i][j] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
isWin = false;
|
||||||
|
for (int i = 0; i < numKeys; i++) {
|
||||||
|
keys[i].led.setPixelColor(0, 0,0,0);
|
||||||
|
keys[i].led.show();
|
||||||
|
}
|
||||||
joueur1 = true;
|
joueur1 = true;
|
||||||
afficheGrille();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void readButtonReset() {
|
void readButtonReset() {
|
||||||
@ -129,31 +167,40 @@ void readButtonReset() {
|
|||||||
void localModeDuo(Adafruit_MPR121& cap, uint16_t& lasttouched, uint16_t& currtouched) {
|
void localModeDuo(Adafruit_MPR121& cap, uint16_t& lasttouched, uint16_t& currtouched) {
|
||||||
currtouched = cap.touched();
|
currtouched = cap.touched();
|
||||||
readButtonReset();
|
readButtonReset();
|
||||||
|
|
||||||
|
if(!isWin){
|
||||||
|
menuGame();
|
||||||
|
for (int i = 0; i < numKeys; i++) {
|
||||||
|
uint8_t t = keys[i].touchID;
|
||||||
|
|
||||||
|
if ((currtouched & _BV(t)) && !(lasttouched & _BV(t))) {
|
||||||
|
Serial.print("Touch "); Serial.print(t); Serial.println(" pressed");
|
||||||
|
|
||||||
for (int i = 0; i < numKeys; i++) {
|
Coord c = getCo(i);
|
||||||
uint8_t t = keys[i].touchID;
|
if(grille[c.y][c.x] == 0) {
|
||||||
|
if(joueur1) {
|
||||||
if ((currtouched & _BV(t)) && !(lasttouched & _BV(t))) {
|
grille[c.y][c.x] = 1;
|
||||||
Serial.print("Touch "); Serial.print(t); Serial.println(" pressed");
|
keys[i].led.setPixelColor(0, 0,0,255);
|
||||||
|
keys[i].led.show();
|
||||||
Coord c = getCo(i);
|
if(victoire(grille, 1)) {
|
||||||
if(grille[c.y][c.x] == 0) {
|
Serial.println("Joueur 1 a gagne");
|
||||||
if(joueur1) {
|
affichResultat();
|
||||||
grille[c.y][c.x] = 1;
|
}
|
||||||
afficheGrille();
|
} else {
|
||||||
if(victoire(grille, 1)) {
|
grille[c.y][c.x] = 2;
|
||||||
Serial.println("Joueur 1 a gagne");
|
keys[i].led.setPixelColor(0, 255,0,0);
|
||||||
}
|
keys[i].led.show();
|
||||||
} else {
|
if(victoire(grille, 2)) {
|
||||||
grille[c.y][c.x] = 2;
|
Serial.println("Joueur 2 a gagne");
|
||||||
afficheGrille();
|
affichResultat();
|
||||||
if(victoire(grille, 2)) {
|
}
|
||||||
Serial.println("Joueur 2 a gagne");
|
|
||||||
}
|
}
|
||||||
|
joueur1 = !joueur1;
|
||||||
}
|
}
|
||||||
joueur1 = !joueur1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}else{
|
||||||
|
menuWin();
|
||||||
}
|
}
|
||||||
lasttouched = currtouched;
|
lasttouched = currtouched;
|
||||||
}
|
}
|
||||||
@ -161,34 +208,88 @@ void localModeDuo(Adafruit_MPR121& cap, uint16_t& lasttouched, uint16_t& currtou
|
|||||||
void localModeSolo(Adafruit_MPR121& cap, uint16_t& lasttouched, uint16_t& currtouched) {
|
void localModeSolo(Adafruit_MPR121& cap, uint16_t& lasttouched, uint16_t& currtouched) {
|
||||||
currtouched = cap.touched();
|
currtouched = cap.touched();
|
||||||
readButtonReset();
|
readButtonReset();
|
||||||
|
if(!isWin){
|
||||||
|
menuGame();
|
||||||
|
for (int i = 0; i < numKeys; i++) {
|
||||||
|
uint8_t t = keys[i].touchID;
|
||||||
|
|
||||||
for (int i = 0; i < numKeys; i++) {
|
if ((currtouched & _BV(t)) && !(lasttouched & _BV(t))) {
|
||||||
uint8_t t = keys[i].touchID;
|
Serial.print("Touch "); Serial.print(t); Serial.println(" pressed");
|
||||||
|
|
||||||
if ((currtouched & _BV(t)) && !(lasttouched & _BV(t))) {
|
Coord c = getCo(i);
|
||||||
Serial.print("Touch "); Serial.print(t); Serial.println(" pressed");
|
if(grille[c.y][c.x] == 0) {
|
||||||
|
grille[c.y][c.x] = 1;
|
||||||
|
keys[i].led.setPixelColor(0, 0,0,255);
|
||||||
|
keys[i].led.show();
|
||||||
|
if(victoire(grille, 1)) {
|
||||||
|
Serial.println("Joueur 1 a gagne");
|
||||||
|
affichResultat();
|
||||||
|
}
|
||||||
|
|
||||||
Coord c = getCo(i);
|
int x, y;
|
||||||
if(grille[c.y][c.x] == 0) {
|
do {
|
||||||
grille[c.y][c.x] = 1;
|
x = random(0, 3);
|
||||||
afficheGrille();
|
y = random(0, 3);
|
||||||
if(victoire(grille, 1)) {
|
} while(grille[y][x] != 0);
|
||||||
Serial.println("Joueur 1 a gagne");
|
|
||||||
}
|
|
||||||
|
|
||||||
int x, y;
|
grille[y][x] = 2;
|
||||||
do {
|
keys[i].led.setPixelColor(0, 255,0,0);
|
||||||
x = random(0, 3);
|
keys[i].led.show();
|
||||||
y = random(0, 3);
|
if(victoire(grille, 2)) {
|
||||||
} while(grille[y][x] != 0);
|
Serial.println("Joueur 2 a gagne");
|
||||||
|
affichResultat();
|
||||||
grille[y][x] = 2;
|
}
|
||||||
afficheGrille();
|
}
|
||||||
if(victoire(grille, 2)) {
|
}
|
||||||
Serial.println("Joueur 2 a gagne");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}else{
|
||||||
|
menuWin();
|
||||||
}
|
}
|
||||||
lasttouched = currtouched;
|
lasttouched = currtouched;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void affichResultat(){
|
||||||
|
for(int i = 0; i < 3; i++) {
|
||||||
|
for(int j = 0; j < 3; j++) {
|
||||||
|
if((i!=c1[0] || j!=c1[1]) && (i!=c2[0] || j!=c2[1]) && (i!=c3[0] || j!=c3[1])){
|
||||||
|
keys[(3*i)+j].led.setPixelColor(0, 0,0,0);
|
||||||
|
keys[(3*i)+j].led.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
isWin = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void turnOff(){
|
||||||
|
for (int i = 0; i < numKeys; i++) {
|
||||||
|
keys[i].led.setPixelColor(0, 0,0,0);
|
||||||
|
keys[i].led.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void menuGame(){
|
||||||
|
display.clearDisplay();
|
||||||
|
display.setCursor(0, 0);
|
||||||
|
display.println("Cliquer sur un boutonpour commencer");
|
||||||
|
display.display();
|
||||||
|
}
|
||||||
|
|
||||||
|
void menuWin(){
|
||||||
|
display.clearDisplay();
|
||||||
|
display.setCursor(0, 0);
|
||||||
|
if(victoire(grille, 1)){
|
||||||
|
display.println("Victoire du joueur 1");
|
||||||
|
display.println();
|
||||||
|
display.println("Cliquer sur le boutonreplay pour rejouer !");
|
||||||
|
display.println("Cliquer sur le boutonreset pour revenir\nau menu !");
|
||||||
|
}else{
|
||||||
|
display.println("Victoire du joueur 2");
|
||||||
|
display.println();
|
||||||
|
display.println("Cliquer sur le boutonreplay pour rejouer !");
|
||||||
|
display.println();
|
||||||
|
display.println("Cliquer sur le boutonreset pour revenir\nau menu !");
|
||||||
|
}
|
||||||
|
display.display();
|
||||||
|
}
|
||||||
|
|||||||
@ -29,6 +29,7 @@ extern bool btns[9];
|
|||||||
extern bool joueur1;
|
extern bool joueur1;
|
||||||
extern bool isBtnSet;
|
extern bool isBtnSet;
|
||||||
|
|
||||||
|
|
||||||
Coord getCo(int key);
|
Coord getCo(int key);
|
||||||
bool victoire(int grille[3][3], int joueur);
|
bool victoire(int grille[3][3], int joueur);
|
||||||
bool allInit();
|
bool allInit();
|
||||||
@ -36,6 +37,10 @@ void afficheGrille();
|
|||||||
void reset();
|
void reset();
|
||||||
void setBtn(Adafruit_MPR121& cap, uint16_t& lasttouched, uint16_t& currtouched);
|
void setBtn(Adafruit_MPR121& cap, uint16_t& lasttouched, uint16_t& currtouched);
|
||||||
void readButtonReset();
|
void readButtonReset();
|
||||||
|
void affichResultat();
|
||||||
|
void turnOff();
|
||||||
|
void menuGame();
|
||||||
|
void menuWin();
|
||||||
|
|
||||||
void localModeDuo(Adafruit_MPR121& cap, uint16_t& lasttouched, uint16_t& currtouched);
|
void localModeDuo(Adafruit_MPR121& cap, uint16_t& lasttouched, uint16_t& currtouched);
|
||||||
void localModeSolo(Adafruit_MPR121& cap, uint16_t& lasttouched, uint16_t& currtouched);
|
void localModeSolo(Adafruit_MPR121& cap, uint16_t& lasttouched, uint16_t& currtouched);
|
||||||
|
|||||||
41
menu.cpp
41
menu.cpp
@ -1,4 +1,5 @@
|
|||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
|
#include "localMode.h"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
// Variables de configuration du menu
|
// Variables de configuration du menu
|
||||||
@ -11,27 +12,28 @@ uint8_t btnPrevB;
|
|||||||
uint8_t btnA;
|
uint8_t btnA;
|
||||||
uint8_t btnB;
|
uint8_t btnB;
|
||||||
|
|
||||||
bool isMod = false;
|
uint8_t isMod = false;
|
||||||
bool isModJeu = false;
|
uint8_t isModJeu = false;
|
||||||
bool isDifficulty = false;
|
uint8_t isDifficulty = false;
|
||||||
bool isPlay = false;
|
bool isPlay = false;
|
||||||
bool isWebSet = false;
|
bool isWebSet = false;
|
||||||
|
|
||||||
|
|
||||||
Adafruit_SH1107 display = Adafruit_SH1107(64, 128, &Wire);
|
Adafruit_SH1107 display = Adafruit_SH1107(64, 128, &Wire);
|
||||||
|
|
||||||
unsigned long lastDebounceTimeA = 0;
|
unsigned long lastDebounceTimeA = 0;
|
||||||
unsigned long lastDebounceTimeB = 0;
|
unsigned long lastDebounceTimeB = 0;
|
||||||
const unsigned long debounceDelay = 200;
|
const unsigned long debounceDelay = 200;
|
||||||
|
|
||||||
// Assure-toi que epd_bitmap_logo soit déclaré ailleurs ou inclus ici
|
|
||||||
//extern const unsigned char epd_bitmap_logo[];
|
//extern const unsigned char epd_bitmap_logo[];
|
||||||
|
|
||||||
void setupMenu() {
|
void setupMenu() {
|
||||||
pinMode(BUTTON_A, INPUT_PULLUP);
|
pinMode(BUTTON_A, INPUT_PULLUP);
|
||||||
pinMode(BUTTON_B, INPUT_PULLUP);
|
pinMode(BUTTON_B, INPUT_PULLUP);
|
||||||
|
|
||||||
btnPrevA = digitalRead(BUTTON_A);
|
btnPrevA = 0x0;
|
||||||
btnPrevB = digitalRead(BUTTON_B);
|
btnPrevB = 0x0;
|
||||||
|
|
||||||
display.begin(0x3C, true);
|
display.begin(0x3C, true);
|
||||||
display.clearDisplay();
|
display.clearDisplay();
|
||||||
@ -50,7 +52,7 @@ void setupMenu() {
|
|||||||
void choixMode() {
|
void choixMode() {
|
||||||
display.clearDisplay();
|
display.clearDisplay();
|
||||||
display.setCursor(0, 0);
|
display.setCursor(0, 0);
|
||||||
display.print("Choisissez le mode :\n");
|
display.print("Choisir le mode :\n");
|
||||||
display.print("[A] Local\n");
|
display.print("[A] Local\n");
|
||||||
display.print("[B] Web\n");
|
display.print("[B] Web\n");
|
||||||
display.display();
|
display.display();
|
||||||
@ -59,7 +61,7 @@ void choixMode() {
|
|||||||
void choixModeJeu() {
|
void choixModeJeu() {
|
||||||
display.clearDisplay();
|
display.clearDisplay();
|
||||||
display.setCursor(0, 0);
|
display.setCursor(0, 0);
|
||||||
display.print("Choisissez le type :\n");
|
display.print("Choisir le type :\n");
|
||||||
display.print("[A] Solo\n");
|
display.print("[A] Solo\n");
|
||||||
display.print("[B] Duo\n");
|
display.print("[B] Duo\n");
|
||||||
display.display();
|
display.display();
|
||||||
@ -68,35 +70,36 @@ void choixModeJeu() {
|
|||||||
void choixDifficulty() {
|
void choixDifficulty() {
|
||||||
display.clearDisplay();
|
display.clearDisplay();
|
||||||
display.setCursor(0, 0);
|
display.setCursor(0, 0);
|
||||||
display.print("Choisissez la \ndifficulte :\n");
|
display.print("Choisir la \ndifficulte :\n");
|
||||||
display.print("[A] Debutant\n");
|
display.print("[A] Debutant\n");
|
||||||
display.print("[B] Expert\n");
|
display.print("[B] Expert\n");
|
||||||
display.display();
|
display.display();
|
||||||
}
|
}
|
||||||
|
|
||||||
void menu() {
|
void menu() {
|
||||||
|
|
||||||
if (!isMod) {
|
if (!isMod) {
|
||||||
choixMode();
|
choixMode();
|
||||||
} else if (local && !isModJeu) {
|
} else if (local && !isModJeu) {
|
||||||
choixModeJeu();
|
choixModeJeu();
|
||||||
} else if (local && solo && !isDifficulty) {
|
} else if (local && solo && !isDifficulty) {
|
||||||
choixDifficulty();
|
choixDifficulty();
|
||||||
} else {
|
} else{
|
||||||
isPlay = true;
|
isPlay = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleButtonA() {
|
void handleButtonA() {
|
||||||
if (!isMod) {
|
if (!isMod) {
|
||||||
local = true;
|
local = true;
|
||||||
isMod = true;
|
isMod = true;
|
||||||
} else if (!isModJeu) {
|
} else if (local && !isModJeu) {
|
||||||
solo = true;
|
solo = true;
|
||||||
isModJeu = true;
|
isModJeu = true;
|
||||||
} else if (solo && !isDifficulty) {
|
} else if (local && solo && !isDifficulty) {
|
||||||
difficulty = 1;
|
difficulty = 1;
|
||||||
isDifficulty = true;
|
isDifficulty = true;
|
||||||
isPlay = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,18 +107,24 @@ void handleButtonB() {
|
|||||||
if (!isMod) {
|
if (!isMod) {
|
||||||
local = false;
|
local = false;
|
||||||
isMod = true;
|
isMod = true;
|
||||||
} else if (!isModJeu) {
|
} else if (local && !isModJeu) {
|
||||||
solo = false;
|
solo = false;
|
||||||
isModJeu = true;
|
isModJeu = true;
|
||||||
} else if (solo && !isDifficulty) {
|
} else if (local && solo && !isDifficulty) {
|
||||||
difficulty = 2;
|
difficulty = 2;
|
||||||
isDifficulty = true;
|
isDifficulty = true;
|
||||||
isPlay = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void readButton() {
|
void readButton() {
|
||||||
btnA = digitalRead(BUTTON_A);
|
btnA = digitalRead(BUTTON_A);
|
||||||
|
/*
|
||||||
|
Serial.print(btnA);
|
||||||
|
Serial.print(" ");
|
||||||
|
Serial.println(btnPrevA);
|
||||||
|
delay(1000);
|
||||||
|
*/
|
||||||
|
|
||||||
if (btnA == LOW && btnPrevA == HIGH && (millis() - lastDebounceTimeA > debounceDelay)) {
|
if (btnA == LOW && btnPrevA == HIGH && (millis() - lastDebounceTimeA > debounceDelay)) {
|
||||||
lastDebounceTimeA = millis();
|
lastDebounceTimeA = millis();
|
||||||
handleButtonA();
|
handleButtonA();
|
||||||
|
|||||||
5
menu.h
5
menu.h
@ -4,7 +4,6 @@
|
|||||||
#include <Adafruit_GFX.h>
|
#include <Adafruit_GFX.h>
|
||||||
#include <Adafruit_SH110X.h>
|
#include <Adafruit_SH110X.h>
|
||||||
|
|
||||||
// Variables de configuration du menu
|
|
||||||
extern bool local;
|
extern bool local;
|
||||||
extern bool solo;
|
extern bool solo;
|
||||||
extern int difficulty;
|
extern int difficulty;
|
||||||
@ -14,9 +13,7 @@ extern uint8_t btnPrevB;
|
|||||||
extern uint8_t btnA;
|
extern uint8_t btnA;
|
||||||
extern uint8_t btnB;
|
extern uint8_t btnB;
|
||||||
|
|
||||||
extern bool isMod;
|
|
||||||
extern bool isModJeu;
|
|
||||||
extern bool isDifficulty;
|
|
||||||
extern bool isPlay;
|
extern bool isPlay;
|
||||||
extern bool isWebSet;
|
extern bool isWebSet;
|
||||||
|
|
||||||
|
|||||||
21
musique.cpp
Normal file
21
musique.cpp
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#include "musique.h"
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
int BassTab[]={1911,1702,1516,1431,1275,1136,1012};//bass 1~7
|
||||||
|
|
||||||
|
|
||||||
|
void pinInit()
|
||||||
|
{
|
||||||
|
pinMode(SPEAKER,OUTPUT);
|
||||||
|
digitalWrite(SPEAKER,LOW);
|
||||||
|
}
|
||||||
|
void sound(uint8_t note_index)
|
||||||
|
{
|
||||||
|
for(int i=0;i<100;i++)
|
||||||
|
{
|
||||||
|
digitalWrite(SPEAKER,HIGH);
|
||||||
|
delayMicroseconds(BassTab[note_index]);
|
||||||
|
digitalWrite(SPEAKER,LOW);
|
||||||
|
delayMicroseconds(BassTab[note_index]);
|
||||||
|
}
|
||||||
|
}
|
||||||
15
musique.h
Normal file
15
musique.h
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#ifndef MUSIQUE_H
|
||||||
|
#define MUSIQUE_H
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
#define SPEAKER 19
|
||||||
|
|
||||||
|
//#define I2C2_SDA2 19
|
||||||
|
//#define I2C2_SCL2 18
|
||||||
|
|
||||||
|
|
||||||
|
void pinInit();
|
||||||
|
void sound(uint8_t note_index);
|
||||||
|
|
||||||
|
#endif // MUSIQUE_H
|
||||||
3
pin.h
3
pin.h
@ -11,4 +11,5 @@
|
|||||||
#define RX 16
|
#define RX 16
|
||||||
#define TX 17
|
#define TX 17
|
||||||
#define SCL 22
|
#define SCL 22
|
||||||
#define SDA 23
|
#define SDA 23
|
||||||
|
#define VART 0
|
||||||
13
web.cpp
13
web.cpp
@ -5,10 +5,9 @@
|
|||||||
|
|
||||||
extern Adafruit_SH1107 display;
|
extern Adafruit_SH1107 display;
|
||||||
|
|
||||||
// Utilisateurs du réseau
|
|
||||||
const char *ssid = "morpion-SAE";
|
const char *ssid = "morpion-SAE";
|
||||||
const char *password = "12345678";
|
const char *password = "12345678";
|
||||||
NetworkServer server(80);
|
WiFiServer server(80);
|
||||||
|
|
||||||
void setupWeb() {
|
void setupWeb() {
|
||||||
Serial.println();
|
Serial.println();
|
||||||
@ -26,18 +25,18 @@ void setupWeb() {
|
|||||||
|
|
||||||
display.clearDisplay();
|
display.clearDisplay();
|
||||||
display.setCursor(0, 0);
|
display.setCursor(0, 0);
|
||||||
display.println("Connectez vous a :");
|
display.println("Connectez-vous a :");
|
||||||
display.print("Nom : ");
|
display.print("Nom : ");
|
||||||
display.println(ssid);
|
display.println(ssid);
|
||||||
display.print("Mdp : ");
|
display.print("Mdp : ");
|
||||||
display.println(password);
|
display.println(password);
|
||||||
display.println();
|
display.println();
|
||||||
display.print("Puis accedez a \nl'adresse ");
|
display.print("Puis accedez a\nl'adresse ");
|
||||||
display.print(myIP);
|
display.print(myIP);
|
||||||
display.display();
|
display.display();
|
||||||
}
|
}
|
||||||
|
|
||||||
void webGame(NetworkClient &c){
|
void webGame(WiFiClient &c) {
|
||||||
c.println(R"rawliteral(
|
c.println(R"rawliteral(
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
@ -312,7 +311,7 @@ void webGame(NetworkClient &c){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loopWeb() {
|
void loopWeb() {
|
||||||
NetworkClient client = server.accept();
|
WiFiClient client = server.available();
|
||||||
if (client) {
|
if (client) {
|
||||||
Serial.println("New Client.");
|
Serial.println("New Client.");
|
||||||
String currentLine = "";
|
String currentLine = "";
|
||||||
@ -339,4 +338,4 @@ void loopWeb() {
|
|||||||
client.stop();
|
client.stop();
|
||||||
Serial.println("Client Disconnected.");
|
Serial.println("Client Disconnected.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
10
web.h
10
web.h
@ -2,19 +2,17 @@
|
|||||||
#define WEBSERVER_H
|
#define WEBSERVER_H
|
||||||
|
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#include <NetworkClient.h>
|
#include <WiFiClient.h>
|
||||||
#include <WiFiAP.h>
|
#include <WiFiAP.h>
|
||||||
|
|
||||||
// SSID & mot de passe du réseau WiFi
|
|
||||||
extern const char *ssid;
|
extern const char *ssid;
|
||||||
extern const char *password;
|
extern const char *password;
|
||||||
|
|
||||||
// Serveur et client web
|
extern WiFiServer server;
|
||||||
extern NetworkServer server;
|
|
||||||
|
|
||||||
void setupWeb();
|
void setupWeb();
|
||||||
void loopWeb();
|
void loopWeb();
|
||||||
void webGame(NetworkClient &c);
|
void webGame(WiFiClient &c);
|
||||||
void webSolo(NetworkClient &c);
|
void webSolo(WiFiClient &c);
|
||||||
|
|
||||||
#endif // WEBSERVER_H
|
#endif // WEBSERVER_H
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user