ENIB 2022 - groupe A : Shooter Xtrem : Différence entre versions
(→photo de l'équipe) |
(→Code) |
||
Ligne 23 : | Ligne 23 : | ||
<pre> | <pre> | ||
ici je pose mon code documenté ! | ici je pose mon code documenté ! | ||
− | + | ||
+ | #include <Wire.h> | ||
+ | #include "rgb_lcd.h" | ||
+ | |||
+ | #define MINUTES 60 | ||
+ | #define SECONDES 1 | ||
+ | |||
+ | rgb_lcd lcd; | ||
+ | const int colorR = 0; | ||
+ | const int colorG = 255; | ||
+ | const int colorB = 0; | ||
+ | int photocellPin = 0; // the cell and 10K pulldown are connected to a0 | ||
+ | int photocellReading; // the analog reading from the analog resistor divider | ||
+ | int tps = 0; | ||
+ | int tps_restant = 0; | ||
+ | int val = 0; | ||
+ | int i =0; | ||
+ | unsigned long chrono; | ||
+ | unsigned long temps = 1000; | ||
+ | unsigned long tempsled = 500; // Durée d'allumage des leds des joueurs | ||
+ | int tempsmax; // Temps max par manche | ||
+ | |||
+ | |||
+ | void setup(void) | ||
+ | { | ||
+ | // We'll send debugging information via the Serial monitor | ||
+ | // set up the LCD's number of columns and rows: | ||
+ | lcd.begin(16, 2); | ||
+ | lcd.setRGB(colorR, colorG, colorB); | ||
+ | delay(1000); | ||
+ | } | ||
+ | |||
+ | int loop_lumiere() | ||
+ | { | ||
+ | // Mesure la tension sur la broche A0 | ||
+ | int lumiere = analogRead(A0); | ||
+ | // Envoi la mesure au PC pour affichage et attends 250ms | ||
+ | lcd.setCursor(13,1); | ||
+ | //Serial.println(lumiere); | ||
+ | lcd.print(lumiere); | ||
+ | if (lumiere < 965) | ||
+ | { | ||
+ | val += 1; | ||
+ | } | ||
+ | delay(50); | ||
+ | return lumiere; | ||
+ | } | ||
+ | |||
+ | void affichetemps(int temps) { | ||
+ | byte minutes = temps / 60; | ||
+ | byte secondes = temps % 60; | ||
+ | int tempsaff = minutes * 100 + secondes; | ||
+ | timer.showNumberDecEx(tempsaff, 0b01000000, true, 4); | ||
+ | } | ||
+ | |||
+ | void loop() | ||
+ | { | ||
+ | |||
+ | if (millis() - chrono >= temps) { // une seconde est passée | ||
+ | tempsmax --; | ||
+ | affichetemps(tempsmax); | ||
+ | if (tempsmax <= 0) { | ||
+ | lcd.print ("Score final : "); | ||
+ | lcd.print(val); | ||
+ | } | ||
+ | chrono = millis(); | ||
+ | |||
+ | for (tps==0; tps<=30; tps+=1){ | ||
+ | tps_restant = 30-tps; | ||
+ | lcd.print("Tps restant : "); | ||
+ | lcd.print(tps_restant); | ||
+ | lcd.setCursor(0,1); | ||
+ | lcd.print("Score : "); | ||
+ | lcd.print(val); | ||
+ | loop_lumiere(); | ||
+ | delay(1000); | ||
+ | lcd.clear(); | ||
+ | } | ||
+ | lcd.print ("Score final : "); | ||
+ | lcd.print(val); | ||
+ | delay (10000); | ||
+ | } | ||
+ | |||
</pre> | </pre> | ||
Version du 13 janvier 2022 à 16:32
photo de l'équipe
Que fait ce projet ?
Shooter Xtrem : C'est une borne de basket tel que l'on peut voir dans les fêtes foraine ou bowling, Qui fonctionne à l'aide d'une photo résistance et d'un afficheur.
Le premier but notre jeu est de marquer un maximum de panier en un temps donné, Ensuite si deux machines similaires sont côte à côte il sera possible de s'affronter pour faire le meilleur score.
Liste des composants
- Carte Arduino Nano
- Résistance 220ohm
- Capteur sharp infrarouge
- Afficheur LCD
Code
ici je pose mon code documenté ! #include <Wire.h> #include "rgb_lcd.h" #define MINUTES 60 #define SECONDES 1 rgb_lcd lcd; const int colorR = 0; const int colorG = 255; const int colorB = 0; int photocellPin = 0; // the cell and 10K pulldown are connected to a0 int photocellReading; // the analog reading from the analog resistor divider int tps = 0; int tps_restant = 0; int val = 0; int i =0; unsigned long chrono; unsigned long temps = 1000; unsigned long tempsled = 500; // Durée d'allumage des leds des joueurs int tempsmax; // Temps max par manche void setup(void) { // We'll send debugging information via the Serial monitor // set up the LCD's number of columns and rows: lcd.begin(16, 2); lcd.setRGB(colorR, colorG, colorB); delay(1000); } int loop_lumiere() { // Mesure la tension sur la broche A0 int lumiere = analogRead(A0); // Envoi la mesure au PC pour affichage et attends 250ms lcd.setCursor(13,1); //Serial.println(lumiere); lcd.print(lumiere); if (lumiere < 965) { val += 1; } delay(50); return lumiere; } void affichetemps(int temps) { byte minutes = temps / 60; byte secondes = temps % 60; int tempsaff = minutes * 100 + secondes; timer.showNumberDecEx(tempsaff, 0b01000000, true, 4); } void loop() { if (millis() - chrono >= temps) { // une seconde est passée tempsmax --; affichetemps(tempsmax); if (tempsmax <= 0) { lcd.print ("Score final : "); lcd.print(val); } chrono = millis(); for (tps==0; tps<=30; tps+=1){ tps_restant = 30-tps; lcd.print("Tps restant : "); lcd.print(tps_restant); lcd.setCursor(0,1); lcd.print("Score : "); lcd.print(val); loop_lumiere(); delay(1000); lcd.clear(); } lcd.print ("Score final : "); lcd.print(val); delay (10000); }