ENIB 2023 : UnderPressure : Différence entre versions
(→Que fait ce projet ?) |
(→Code) |
||
| Ligne 16 : | Ligne 16 : | ||
ici je pose mon code documenté ! | ici je pose mon code documenté ! | ||
</pre> | </pre> | ||
| + | |||
| + | #include <Wire.h> | ||
| + | #include <Adafruit_Sensor.h> | ||
| + | #include <Adafruit_BME280.h> | ||
| + | |||
| + | Adafruit_BME280 bme; // I2C | ||
| + | |||
| + | const int greenLed = 12; | ||
| + | const int orangeLed = 11; | ||
| + | const int redLed = 10; | ||
| + | const float targetPressure = 1.0; | ||
| + | const int targetDuration = 5000; // 5 seconds | ||
| + | |||
| + | unsigned long startTime; | ||
| + | bool pressureReached = false; | ||
| + | |||
| + | void setup() { | ||
| + | // Start the I2C communication | ||
| + | Wire.begin(); | ||
| + | |||
| + | // Initialize the BME280 sensor | ||
| + | bme.begin(0x76); | ||
| + | |||
| + | // Set the LED pins as output | ||
| + | pinMode(greenLed, OUTPUT); | ||
| + | pinMode(orangeLed, OUTPUT); | ||
| + | pinMode(redLed, OUTPUT); | ||
| + | } | ||
| + | |||
| + | void loop() { | ||
| + | float pressure = bme.readPressure() / 100.0F; | ||
| + | |||
| + | // Check if the pressure is correct | ||
| + | if (pressure >= targetPressure) { | ||
| + | if (!pressureReached) { | ||
| + | // Start the timer | ||
| + | startTime = millis(); | ||
| + | pressureReached = true; | ||
| + | } else { | ||
| + | // Check if the duration is long enough | ||
| + | if (millis() - startTime >= targetDuration) { | ||
| + | // Turn on the green LED | ||
| + | digitalWrite(greenLed, HIGH); | ||
| + | digitalWrite(orangeLed, LOW); | ||
| + | digitalWrite(redLed, LOW); | ||
| + | } else { | ||
| + | // Turn on the orange LED | ||
| + | digitalWrite(greenLed, LOW); | ||
| + | digitalWrite(orangeLed, HIGH); | ||
| + | digitalWrite(redLed, LOW); | ||
| + | } | ||
| + | } | ||
| + | } else { | ||
| + | // Turn on the red LED | ||
| + | digitalWrite(greenLed, LOW); | ||
| + | digitalWrite(orangeLed, LOW); | ||
| + | digitalWrite(redLed, HIGH); | ||
| + | pressureReached = false; | ||
| + | } | ||
| + | } | ||
==Catégories== | ==Catégories== | ||
[[Catégorie:Enib2023]] | [[Catégorie:Enib2023]] | ||
Version du 26 janvier 2023 à 14:49
photo de l'équipe
Que fait ce projet ?
Le joueur se retrouve face à un plateau rempli de verres avec des pailles. Son but est de trouver le bon verre et de souffler dedans à 2 bars pendant 6 secondes. Plusieurs énigmes-indices l'aideront, elles seront notées sur la décoration des verres (parasols). Lorsque le jeu est gagné, des leds s'allument.
Liste des composants
- composant 1
- composant 2
- ...
Code
ici je pose mon code documenté !
- include <Wire.h>
- include <Adafruit_Sensor.h>
- include <Adafruit_BME280.h>
Adafruit_BME280 bme; // I2C
const int greenLed = 12; const int orangeLed = 11; const int redLed = 10; const float targetPressure = 1.0; const int targetDuration = 5000; // 5 seconds
unsigned long startTime; bool pressureReached = false;
void setup() {
// Start the I2C communication Wire.begin();
// Initialize the BME280 sensor bme.begin(0x76);
// Set the LED pins as output pinMode(greenLed, OUTPUT); pinMode(orangeLed, OUTPUT); pinMode(redLed, OUTPUT);
}
void loop() {
float pressure = bme.readPressure() / 100.0F;
// Check if the pressure is correct
if (pressure >= targetPressure) {
if (!pressureReached) {
// Start the timer
startTime = millis();
pressureReached = true;
} else {
// Check if the duration is long enough
if (millis() - startTime >= targetDuration) {
// Turn on the green LED
digitalWrite(greenLed, HIGH);
digitalWrite(orangeLed, LOW);
digitalWrite(redLed, LOW);
} else {
// Turn on the orange LED
digitalWrite(greenLed, LOW);
digitalWrite(orangeLed, HIGH);
digitalWrite(redLed, LOW);
}
}
} else {
// Turn on the red LED
digitalWrite(greenLed, LOW);
digitalWrite(orangeLed, LOW);
digitalWrite(redLed, HIGH);
pressureReached = false;
}
}
