ENIB 2023 : Salade d'Enigmes : Différence entre versions
| Ligne 6 : | Ligne 6 : | ||
==Que fait ce projet ? == | ==Que fait ce projet ? == | ||
Ce projet est une combinaison de 4 énigmes. | Ce projet est une combinaison de 4 énigmes. | ||
| − | ==Liste des | + | ==Liste des parties== |
| + | |||
| + | * Partie 1 | ||
| + | |||
| + | [[ | ||
| + | [[Fichier:EnigmeTableauPeriodiqueV2.jpg|vignette]] | ||
| + | ]] | ||
| − | |||
* composant 2 | * composant 2 | ||
* ... | * ... | ||
Version du 26 janvier 2023 à 16:21
photo de l'équipe
Que fait ce projet ?
Ce projet est une combinaison de 4 énigmes.
Liste des parties
- Partie 1
[[
]]
- composant 2
- ...
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;
}
}
