ENIB 2023 : Salade d'Enigmes : Différence entre versions
Ligne 127 : | Ligne 127 : | ||
return 0; | return 0; | ||
} | } | ||
+ | } | ||
+ | |||
+ | /////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
+ | |||
+ | Code pour sélection de la réponse (Rouge ou Vert ou Bleu) : | ||
+ | |||
+ | #define r1_pin 13 | ||
+ | #define b1_pin 12 | ||
+ | #define g1_pin 11 | ||
+ | #define bp0 4 | ||
+ | |||
+ | #define r2_pin 10 | ||
+ | #define b2_pin 9 | ||
+ | #define g2_pin 8 | ||
+ | #define bp2 3 | ||
+ | |||
+ | #define r3_pin 7 | ||
+ | #define b3_pin 6 | ||
+ | #define g3_pin 5 | ||
+ | #define bp3 2 | ||
+ | |||
+ | #define validation A0 | ||
+ | |||
+ | unsigned long previousMillis = 0; | ||
+ | unsigned long previousMillis2 = 0; | ||
+ | int i =0; | ||
+ | |||
+ | int val1 =0; | ||
+ | int val2 =0; | ||
+ | int val3 =0; | ||
+ | |||
+ | const byte COLOR_BLACK = 0b000; | ||
+ | const byte COLOR_RED = 0b100; | ||
+ | const byte COLOR_GREEN = 0b010; | ||
+ | const byte COLOR_BLUE = 0b001; | ||
+ | const byte COLOR_MAGENTA = 0b101; | ||
+ | const byte COLOR_CYAN = 0b011; | ||
+ | const byte COLOR_YELLOW = 0b110; | ||
+ | const byte COLOR_WHITE = 0b111; | ||
+ | byte table[7] = {COLOR_RED,COLOR_GREEN,COLOR_BLUE,COLOR_MAGENTA,COLOR_CYAN,COLOR_YELLOW,COLOR_WHITE}; | ||
+ | void setup() { | ||
+ | // put your setup code here, to run once: | ||
+ | Serial.begin(9600); | ||
+ | pinMode(b1_pin, OUTPUT); | ||
+ | pinMode(g1_pin, OUTPUT); | ||
+ | pinMode(r1_pin, OUTPUT); | ||
+ | pinMode(bp0, INPUT); | ||
+ | |||
+ | pinMode(b2_pin, OUTPUT); | ||
+ | pinMode(g2_pin, OUTPUT); | ||
+ | pinMode(r2_pin, OUTPUT); | ||
+ | pinMode(bp2, INPUT); | ||
+ | |||
+ | |||
+ | pinMode(b3_pin, OUTPUT); | ||
+ | pinMode(g3_pin, OUTPUT); | ||
+ | pinMode(r3_pin, OUTPUT); | ||
+ | pinMode(bp3, INPUT); | ||
+ | pinMode(validation, INPUT); | ||
+ | } | ||
+ | |||
+ | void displayColor1(byte color) { | ||
+ | |||
+ | // Version anode commune | ||
+ | digitalWrite(r1_pin, !bitRead(color, 2)); | ||
+ | digitalWrite(g1_pin, !bitRead(color, 1)); | ||
+ | digitalWrite(b1_pin, !bitRead(color, 0)); | ||
+ | |||
+ | } | ||
+ | |||
+ | void displayColor2(byte color) { | ||
+ | |||
+ | // Version anode commune | ||
+ | digitalWrite(r2_pin, !bitRead(color, 2)); | ||
+ | digitalWrite(g2_pin, !bitRead(color, 1)); | ||
+ | digitalWrite(b2_pin, !bitRead(color, 0)); | ||
+ | |||
+ | } | ||
+ | |||
+ | void displayColor3(byte color) { | ||
+ | |||
+ | // Version anode commune | ||
+ | digitalWrite(r3_pin, !bitRead(color, 2)); | ||
+ | digitalWrite(g3_pin, !bitRead(color, 1)); | ||
+ | digitalWrite(b3_pin, !bitRead(color, 0)); | ||
+ | |||
+ | } | ||
+ | void loop() { | ||
+ | // put your main code here, to run repeatedly: | ||
+ | // displayColor1(table[1]); | ||
+ | if( digitalRead(bp0) && millis() - previousMillis2 > 1000 ) | ||
+ | { | ||
+ | |||
+ | displayColor1(table[i]); | ||
+ | i=i+1; | ||
+ | previousMillis2 = millis(); | ||
+ | if (table[i] == COLOR_BLUE) | ||
+ | { | ||
+ | Serial.println("labyrinthe ok"); | ||
+ | val1 = 1; | ||
+ | } | ||
+ | |||
+ | if( i >= 7) | ||
+ | { | ||
+ | i= 0; | ||
+ | } | ||
+ | |||
+ | |||
+ | } | ||
+ | |||
+ | if( digitalRead(bp2) && millis() - previousMillis2 > 1000 ) | ||
+ | { | ||
+ | |||
+ | displayColor2(table[i]); | ||
+ | i=i+1; | ||
+ | previousMillis2 = millis(); | ||
+ | |||
+ | if (table[i]== COLOR_GREEN) | ||
+ | { | ||
+ | Serial.println("cesar ok"); | ||
+ | val2=1; | ||
+ | } | ||
+ | if( i >= 7) | ||
+ | { | ||
+ | i= 0; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | if( digitalRead(bp3) && millis() - previousMillis2 > 1000 ) | ||
+ | { | ||
+ | |||
+ | displayColor3(table[i]); | ||
+ | i=i+1; | ||
+ | previousMillis2 = millis(); | ||
+ | |||
+ | if (table[i]== COLOR_CYAN) | ||
+ | { | ||
+ | Serial.println("periodique ok"); | ||
+ | val3 = 1; | ||
+ | } | ||
+ | |||
+ | if( i >= 7) | ||
+ | { | ||
+ | i= 0; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | if( val1 && val2 && val3) | ||
+ | { | ||
+ | displayColor1(COLOR_BLUE); | ||
+ | displayColor2(COLOR_BLUE); | ||
+ | displayColor3(COLOR_BLUE); | ||
+ | } | ||
+ | |||
+ | if(val1 && val2 && val3 && (bp0 || bp2 || bp3)) | ||
+ | { | ||
+ | |||
+ | val1 = 0; | ||
+ | val2 = 0; | ||
+ | val3 = 0; | ||
+ | } | ||
+ | |||
+ | if (analogRead(validation) == 1) | ||
+ | { | ||
+ | Serial.println("morse ok"); | ||
+ | } | ||
+ | |||
} | } | ||
Version du 26 janvier 2023 à 15:48
photo de l'équipe
Que fait ce projet ?
Ce projet est une combinaison de 4 énigmes.
Liste des parties
- Partie 1 Tableau périodique :
Le but était de sélectionner 2 valeurs grâce à un potentiomètre. Ces valeurs se devinaient grâce à deux matériaux coller sur la plaque et leur nombre atomique trouvé sur le tableau périodique
- Partie 2 Corde César
- Partie 3 Code Morse
- Partie 4 labyrinthe
Code
Code pour la partie Tableau périodique (Il y a une librairie à télécharger) : #include <SPI.h> #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED display height, in pixels #define valPotReader A0 #define buttonPer D8 #define Win D7 #define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) #define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32 Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); int valPot; int pos=0; int resultPer[2]={0,0}; int solPer[2] = {29,13}; bool buttonPerState=0; bool prevButtonPerState=0; void setup() { // put your setup code here, to run once: Serial.begin(9600); pinMode(valPotReader,INPUT); pinMode(buttonPer,INPUT); pinMode(Win,OUTPUT); // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) { Serial.println(F("SSD1306 allocation failed")); for(;;); // Don't proceed, loop forever } // Show initial display buffer contents on the screen -- // the library initializes this with an Adafruit splash screen. display.display(); delay(2000); // Pause for 2 seconds // Clear the buffer display.clearDisplay(); } void loop() { // put your main code here, to run repeatedly: valPot=round((float(analogRead(valPotReader))/1024)*118); show(); if(isPressed()){ Serial.println("oui"); int i = pos%2; pos=pos+1; resultPer[i]=valPot; show(); }; Serial.println((resultPer[0]==solPer[0] && resultPer[1]==solPer[1])); if(resultPer[0]==solPer[0] && resultPer[1]==solPer[1]) { Serial.print("Win"); digitalWrite(Win,HIGH); }else{digitalWrite(Win,LOW);} } void show(){ display.clearDisplay(); display.setTextSize(4); display.setTextColor(SSD1306_WHITE); display.setCursor(16,16); display.print(valPot); display.setTextSize(1); display.setCursor(80,53); display.print(resultPer[0]); display.print('|'); display.print(resultPer[1]); display.display(); } bool isPressed(){ buttonPerState=digitalRead(buttonPer); if(prevButtonPerState==0 && buttonPerState==1){ prevButtonPerState=buttonPerState; return 1; } else{ prevButtonPerState=buttonPerState; return 0; } } /////////////////////////////////////////////////////////////////////////////////////////////////////////////// Code pour sélection de la réponse (Rouge ou Vert ou Bleu) : #define r1_pin 13 #define b1_pin 12 #define g1_pin 11 #define bp0 4 #define r2_pin 10 #define b2_pin 9 #define g2_pin 8 #define bp2 3 #define r3_pin 7 #define b3_pin 6 #define g3_pin 5 #define bp3 2 #define validation A0 unsigned long previousMillis = 0; unsigned long previousMillis2 = 0; int i =0; int val1 =0; int val2 =0; int val3 =0; const byte COLOR_BLACK = 0b000; const byte COLOR_RED = 0b100; const byte COLOR_GREEN = 0b010; const byte COLOR_BLUE = 0b001; const byte COLOR_MAGENTA = 0b101; const byte COLOR_CYAN = 0b011; const byte COLOR_YELLOW = 0b110; const byte COLOR_WHITE = 0b111; byte table[7] = {COLOR_RED,COLOR_GREEN,COLOR_BLUE,COLOR_MAGENTA,COLOR_CYAN,COLOR_YELLOW,COLOR_WHITE}; void setup() { // put your setup code here, to run once: Serial.begin(9600); pinMode(b1_pin, OUTPUT); pinMode(g1_pin, OUTPUT); pinMode(r1_pin, OUTPUT); pinMode(bp0, INPUT); pinMode(b2_pin, OUTPUT); pinMode(g2_pin, OUTPUT); pinMode(r2_pin, OUTPUT); pinMode(bp2, INPUT); pinMode(b3_pin, OUTPUT); pinMode(g3_pin, OUTPUT); pinMode(r3_pin, OUTPUT); pinMode(bp3, INPUT); pinMode(validation, INPUT); } void displayColor1(byte color) { // Version anode commune digitalWrite(r1_pin, !bitRead(color, 2)); digitalWrite(g1_pin, !bitRead(color, 1)); digitalWrite(b1_pin, !bitRead(color, 0)); } void displayColor2(byte color) { // Version anode commune digitalWrite(r2_pin, !bitRead(color, 2)); digitalWrite(g2_pin, !bitRead(color, 1)); digitalWrite(b2_pin, !bitRead(color, 0)); } void displayColor3(byte color) { // Version anode commune digitalWrite(r3_pin, !bitRead(color, 2)); digitalWrite(g3_pin, !bitRead(color, 1)); digitalWrite(b3_pin, !bitRead(color, 0)); } void loop() { // put your main code here, to run repeatedly: // displayColor1(table[1]); if( digitalRead(bp0) && millis() - previousMillis2 > 1000 ) { displayColor1(table[i]); i=i+1; previousMillis2 = millis(); if (table[i] == COLOR_BLUE) { Serial.println("labyrinthe ok"); val1 = 1; } if( i >= 7) { i= 0; } } if( digitalRead(bp2) && millis() - previousMillis2 > 1000 ) { displayColor2(table[i]); i=i+1; previousMillis2 = millis(); if (table[i]== COLOR_GREEN) { Serial.println("cesar ok"); val2=1; } if( i >= 7) { i= 0; } } if( digitalRead(bp3) && millis() - previousMillis2 > 1000 ) { displayColor3(table[i]); i=i+1; previousMillis2 = millis(); if (table[i]== COLOR_CYAN) { Serial.println("periodique ok"); val3 = 1; } if( i >= 7) { i= 0; } } if( val1 && val2 && val3) { displayColor1(COLOR_BLUE); displayColor2(COLOR_BLUE); displayColor3(COLOR_BLUE); } if(val1 && val2 && val3 && (bp0 || bp2 || bp3)) { val1 = 0; val2 = 0; val3 = 0; } if (analogRead(validation) == 1) { Serial.println("morse ok"); } }