Petite news, hier soir j'ai vite fait continué à coder.
Du coup j'ai intégré le mouvement du moteur dans ma boucle.
Le code un peu brut, la mise en mouvement du moteur se situe au début de la boucle
loop et la détection des bouton au repère "
//----- Barre: detection deplacement":
//-------------- LIBRAIRIES ----------------------//****************************************************************
#include <SevenSegmentAsciiMap.h> //
#include <SevenSegmentExtended.h> // Librairies pour les afficheurs 4 digits 7 segments
#include <SevenSegmentTM1637.h> //
#include "Arduino.h" //
#include "SoftwareSerial.h" // Librairies Dfmini
#include "DFRobotDFPlayerMini.h" //
#include <Adafruit_NeoPixel.h> // Librairie pour les leds
//-------------- DECLARATION MATOS ---------------//****************************************************************
SevenSegmentTM1637 TM1(24, 22); //afficheur du BAS déclaration -- CLK 24 -- DIO 22 --
SevenSegmentTM1637 TM2(28, 26); //afficheur du CENTRE déclaration -- CLK 28 -- DIO 26 --
SevenSegmentTM1637 TM3(32, 30); //afficheur du HAUT déclaration -- CLK 32 -- DIO 30 --
Adafruit_NeoPixel STRIP(8, 34, NEO_GRBW + NEO_KHZ800); // Bande led déclaration -- NBR LED 8 -- DIO 34 --
SoftwareSerial mySoftwareSerial(13, 12); // Dfmini déclaration -- RX 12 -- TX 13 -- DOIVENT ETRES PWR
DFRobotDFPlayerMini myDFPlayer; //
void printDetail(uint8_t type, int value); //
//------------- DECLARATION VARIAVLES -------------//***************************************************************
int Latence = 50; // Pour gérer le delay de l'arduino (multiple de 50 sinon ce sera la merde !!!!!)
int TempAFF = 0; // Temporaire pour les Afficheurs
int TempLED = 0; // Temporaire pour les Leds
int TempLEDBRILL = 0; int TempLEDBRILLAD = 0; // Tempoiraire scintillement Leds
int TempBONUS = 0; // Tempoiraire décompte bonus
int Highscore = 0; // Highscore
int Bille = 0; // Bille on bar
int Etape = 0; // Trou demandé
int Bonus = 0; // Variable bonus
int Score = 0; // variable Score
int BTNcredit = 0; // Bouton Credit
const int stepPinMotor1 = 5; // Step Moteur 1 -- PIN 5 --
const int dirPinMotor1 = 4; // Direction Moteur 1 -- PIN 4 --
int Motor1Bouge = 0;
int BttnMontMotor1 = 0; // Bouton Up Motor 1
int BttnDscdMotor1 = 0; // Bouton Down Motor 1
int Motor1 = 0; // Bougeage de Motor 1
int Amode = 1; // Boucle ATTRACK MODE
int Debutpartie = 0; // Initialisation de la partie après le crédit
int Initbarre = 0; // Initialisation Bonus et partie
int DescenteBarre = 0;// Pour que les barres aillent chercher une nouvelle bille
int MonteBarre = 0; // Pour que les barres remonteent
int Principale = 0; // Boucle principale avec bougeage des barres, bonus qui descent, billes qui passent dans un trou etc...
int Trou = 0; // Trou dans laquelle est tombé la Bille
int BonTrou = 0; // Boucle Bille dans le bon trou
int BadTrou = 0; // Boucle Bille dans le mauvais trou
int Gameover = 0; // Boucle Gamover
void setup() {
TM1.begin(); TM1.setPrintDelay(500); TM1.clear(); // Afficheur du BAS initialisation (début / brightness / RAZ)
TM2.begin(); TM2.setPrintDelay(500); TM2.clear(); // Afficheur du CENTRE initialisation
TM3.begin(); TM3.setPrintDelay(500); TM3.clear(); // Afficheur du HAUT initialisation
STRIP.begin(); STRIP.clear(); STRIP.show(); STRIP.setBrightness(30); // Bande led initialisation (début, clear + affichage, brightness)
mySoftwareSerial.begin(9600); Serial.begin(115200); // Dfmini comm serie
!myDFPlayer.begin(mySoftwareSerial); // Dfmini initialisation
myDFPlayer.volume(15); // Dfmini volume (0~30)
pinMode (36, INPUT_PULLUP); // Bouton Crédit en PULLUP -- PIN 36 --
pinMode(stepPinMotor1,OUTPUT); // Step Moteur 1
pinMode(dirPinMotor1,OUTPUT); // Direction Moteur 1
pinMode (38, INPUT_PULLUP); // Fin de course bas Moteur 1 -- PIN 38 --
pinMode (52, INPUT_PULLUP); // Bouton Moteur 1 Monte -- PIN 52 --
pinMode (50, INPUT_PULLUP); // Bonton Moteur 1 Descend -- PIN 38 --
pinMode(23, INPUT); // Mauvais Trou
pinMode(43, INPUT); // Trou 1
pinMode(41, INPUT); // Trou 2
pinMode(39, INPUT); // Trou 3
pinMode(37, INPUT); // Trou 4
pinMode(35, INPUT); // Trou 5
pinMode(33, INPUT); // Trou 6
pinMode(31, INPUT); // Trou 7
pinMode(29, INPUT); // Trou 8
pinMode(27, INPUT); // Trou 9
pinMode(25, INPUT); // Trou 10
Serial.begin(9600); //Pour la console
}
void loop() {
if (Motor1 == 0) {delay(Latence);} // millisecondes de mise a jour de la boucle si moteurs immobiles
if (Motor1 == 1) {
digitalWrite(dirPinMotor1,LOW); // direction Motor1 vers le Haut
for (int i = 0 ; i < 100; i++) {
digitalWrite(stepPinMotor1,HIGH); delayMicroseconds(500);
digitalWrite(stepPinMotor1,LOW); delayMicroseconds(500);}
Motor1 = 0;}
if (Motor1 == 2) {
digitalWrite(dirPinMotor1,HIGH); // direction Motor1 vers le Haut
for (int i = 0 ; i < 100; i++) {
digitalWrite(stepPinMotor1,HIGH); delayMicroseconds(500);
digitalWrite(stepPinMotor1,LOW); delayMicroseconds(500);}
Motor1 = 0;}
//--------------------------------------------------- ATTRACK MODE -------------------------------------------------
if (Amode == 1){
BTNcredit = digitalRead(36); // Verif si boutton coin est appuyé
if (BTNcredit == LOW) { Amode = 0; Debutpartie = 1; Etape = 1; // Sortie d'Attrack mode et Debut de Partie
myDFPlayer.playMp3Folder(6); // Dfmini SON pièce qui tombe
delay(1000); //
TM1.clear(); TM2.clear();TM3.clear(); // On efface les Afficheurs
STRIP.clear(); STRIP.show(); STRIP.setBrightness(30); // RAZ valeurs Bandes LEDs
TempLEDBRILL = 0; TempLEDBRILLAD = 5; TempAFF = 0; TempLED = 0;} // RAZ Valeurs Tempo
TempAFF++; int TempAFF2 = TempAFF * Latence;
switch (TempAFF2) { // Faire defiler text ecran du bas
case (1000): TM1.clear(); TM1.print("PLAY"); break;
case (2000): TM1.clear(); TM1.print("ICE"); break;
case (3000): TM1.clear(); TM1.print("COLD"); break;
case (4000): TM1.clear(); TM1.print("BEER"); break;
case (5000): TM1.clear(); break;
case (6000): TM1.clear(); TM1.setCursor(1, DECALAGE (Highscore)); TM1.print(Highscore); TempAFF = 0; break;}
TempLED++;
if ( TempLED <= 10 ) { STRIP.setBrightness(60);STRIP.setPixelColor(TempLED, 240, 240, 20); STRIP.setPixelColor(TempLED-1, 130, 130, 50); STRIP.show();}
if ( TempLED > 10 && TempLED <= 20 ){ STRIP.setPixelColor(TempLED-12, 0, 0, 0); STRIP.show(); }
if ( TempLED > 20 && TempLED <= 30 ){ STRIP.setPixelColor(TempLED-20, 240, 240, 20); STRIP.setPixelColor(TempLED-21, 130, 130, 50); STRIP.setPixelColor(TempLED-22, 0, 0, 0); STRIP.show(); }
if ( TempLED >= 30 && TempLED <= 40 ){ STRIP.setPixelColor(TempLED-32, 130, 130, 50); STRIP.show();}
if ( TempLED >= 50 && TempLED <= 60 ){ STRIP.setPixelColor(TempLED-52, 0, 0, 0); STRIP.show(); }
if ( TempLED == 60 ){ for (int i= 0; i<8; i++ ) {TempLEDBRILL = 20; STRIP.setBrightness(TempLEDBRILL); STRIP.setPixelColor(i, 230, 230 ,230); STRIP.show(); TempLEDBRILLAD=10;}}
if ( TempLED > 60 && TempLED <=180) {TempLEDBRILL = TempLEDBRILL + TempLEDBRILLAD ; STRIP.setBrightness(TempLEDBRILL); STRIP.show(); if (TempLEDBRILL >70 || TempLEDBRILL < 20){TempLEDBRILLAD=-TempLEDBRILLAD;} }
if ( TempLED == 180 ){ for (int i= 0; i<8; i++ ) {TempLEDBRILL = 20; STRIP.setBrightness(TempLEDBRILL); STRIP.setPixelColor(i, 0, 0 ,0); STRIP.show();}}
if (TempLED >= 200) { TempLED=0;}
} //----- FIN DE ATTRACK MODE
//--------------------------------------------------- DEBUT DE PARTIE ---------------------------------
if (Debutpartie == 1){ Bille++; Debutpartie =0; Initbarre = 1; // Sortie Debut de Partie vers Initialisation des barres
TM3.clear(); TM3.print(Bille); // Affichage Bille on barre
STRIP.clear();STRIP.setPixelColor(Etape-1, 240, 240, 20);STRIP.show();} // Allumage LED trou demandé
//----------------------------------------- INITIALISATION DES BARRES ET BONUS ------------------------
if (Initbarre ==1){ Bonus = Etape *100; TM2.clear(); TM2.setCursor(1, DECALAGE (Bonus)); TM2.print(Bonus); // Affichage Bonus
TM1.clear(); TM1.setCursor(1, DECALAGE (Score)); TM1.print(Score); // Affichage Score
Initbarre = 0; DescenteBarre = 1; TempBONUS = -10;} // Sortie Initialisation barres vers DescenteBarre
//-------------------------------------------------- DESCENTE DES BARRES ------------------------------
if (DescenteBarre ==1){
digitalWrite(dirPinMotor1,HIGH); // Direction Moteur 1 vers le bas
int ConFinDeCourse1 = digitalRead(38); // Lecteur Contacteur Fin de course Moteur 1
if (ConFinDeCourse1 == HIGH) {
Motor1 = 2; } // Pour faire sauter le delais de la boucle principale
if (ConFinDeCourse1 == LOW) {
Motor1 = 0;
myDFPlayer.playMp3Folder(1); // Dfmini SON Debut de partie
DescenteBarre = 0; MonteBarre = 1;}} // Sortie DescenteBarre barres vers MonteBarre
//-------------------------------------------------- MONTE DES BARRES ------------------------------
if (MonteBarre ==1){
digitalWrite(dirPinMotor1,LOW); // Direction Moteur 1 vers le bas
for (int i = 0 ; i < 3000; i++) {
digitalWrite(stepPinMotor1,HIGH);
delayMicroseconds(500);
digitalWrite(stepPinMotor1,LOW);
delayMicroseconds(500); }
MonteBarre = 0; Principale = 1;} // Sortie MonteBarre barres vers Principale
//----------------------------------------------------BOUCLE PRINCIPALE--------------------------------
if (Principale == 1) {
TempBONUS++; if (TempBONUS > (3000/Latence) && Bonus > 0) {Bonus = Bonus - 10; // Décompte Bonus
myDFPlayer.playMp3Folder(5); // Dfmini Bonus -10
TM2.clear(); TM2.setCursor(1, DECALAGE (Bonus)); TM2.print(Bonus); //
TempBONUS = 0;}
//
TempLEDBRILL = TempLEDBRILL + TempLEDBRILLAD;
STRIP.setBrightness(TempLEDBRILL); STRIP.setPixelColor(Etape-1, 240, 240, 20);
STRIP.show();
if (TempLEDBRILL >70 ){TempLEDBRILLAD=-10;};
if (TempLEDBRILL <10 ){TempLEDBRILLAD= 10;}
//----- Barre: detection deplacement
BttnMontMotor1 = digitalRead(52); // Moteur 1
BttnDscdMotor1 = digitalRead(50); //
if (BttnMontMotor1 == LOW){ Motor1 = 1;} // Montera
if (BttnDscdMotor1 == LOW){ Motor1 = 2;} // Descendra
//----- Detection du Trou
int Troudetect = 0; Trou=0;
Troudetect = digitalRead(23); if (Troudetect == LOW){ Trou=20;} // Mauvais Trou
Troudetect = digitalRead(43); if (Troudetect == LOW){ Trou=1;} // Trou 1
Troudetect = digitalRead(41); if (Troudetect == LOW){ Trou=2;} // Trou 2
Troudetect = digitalRead(39); if (Troudetect == LOW){ Trou=3;} // Trou 3
Troudetect = digitalRead(37); if (Troudetect == LOW){ Trou=4;} // Trou 4
Troudetect = digitalRead(35); if (Troudetect == LOW){ Trou=5;} // Trou 5
Troudetect = digitalRead(33); if (Troudetect == LOW){ Trou=6;} // Trou 6
Troudetect = digitalRead(31); if (Troudetect == LOW){ Trou=7;} // Trou 7
Troudetect = digitalRead(29); if (Troudetect == LOW){ Trou=8;} // Trou 8
Troudetect = digitalRead(27); if (Troudetect == LOW){ Trou=9;} // Trou 9
Troudetect = digitalRead(25); if (Troudetect == LOW){ Trou=10;} // Trou 10
if (Trou != 0 && Trou == Etape) { BonTrou =1 ; Principale = 0 ;} // Bille tombé dans le Bon Trou :D
if (Trou != 0 && Trou != Etape) { BadTrou =1 ; Principale = 0 ;} // Bille tombé dans le Mauvais Trou :(
} //----- FIN DE BOUCLE PRINCIPALE
//----------------------------------------------------------BON Trou-----------------------------------
if (BonTrou == 1) {
myDFPlayer.playMp3Folder(3); // Dfmini SON Bon trou
TM2.blink(); TempBONUS = Bonus/10;
for ( int i=0; i < TempBONUS; i++){ // Décompte du bonus
Bonus= Bonus -10; Score = Score +10;
myDFPlayer.playMp3Folder(4); delay (150- (i)); // Dfmini SON Bonus decompte
TM2.clear(); TM2.setCursor(1, DECALAGE (Bonus)); TM2.print(Bonus); // Affichage Bonus
TM1.clear(); TM1.setCursor(1, DECALAGE (Score)); TM1.print(Score);} // Affichage Score
Etape++; if (Etape > 10) {Etape=1;} BonTrou =0; Initbarre =1;TM1.blink();STRIP.clear();STRIP.show();} // Retour Initialisation barre
//--------------------------------------------------------MAUVAIS Trou----------------------------------
if (BadTrou == 1){
for (int i= 0; i<10; i++ ) {STRIP.setPixelColor(i, 230, 0 ,0); STRIP.show();} // LEDS en Rouge
TM3.clear(); TM3.print("-"); TM2.clear(); TM2.print("----"); TM1.clear(); TM1.print("OUPS"); // OUPS Message
myDFPlayer.playMp3Folder(9); // Dfmini SON Mauvais trou
delay (3000);
if (Bille == 3) { Gameover = 1;} // Verif si GAME OVER
Debutpartie = 1; BadTrou = 0;} // Retour debut de partie
//----------------------------------------------------------GAME OVER------------------------------------
if (Gameover == 1) { myDFPlayer.playMp3Folder(8); // Dfmini SON GAME OVER
TM1.clear(); TM2.clear(); TM3.clear();
TM1.print(" GAME OVER YOUR Score ");
TM1.clear(); TM1.setCursor(1, DECALAGE (Score)); TM1.print(Score); delay (500);
TM2.blink(); delay (1000); TM1.clear();
if ( Score > Highscore) { Highscore = Score;
TM1.clear(); TM1.print(" NEW"); TM1.blink(); TM1.print("HIGH"); TM1.blink(); TM1.print("SCOR"); TM1.blink(); TM1.clear();}
Amode = 1; Gameover = 0; Debutpartie = 0; Bille = 0; Etape = 0; Score = 0;}
//Serial.print (BttnMontMotor1);
Serial.println (Motor1);
//printDetail(myDFPlayer.readType(), myDFPlayer.read());
}//----- FIN LOOP
// Fonction pour trouver decalage des afficheurs *******************
int DECALAGE (int Adecaler) {
int Decal = 0;
if ( Adecaler <1000){Decal = 1;}
if ( Adecaler <100){Decal = 2;}
if ( Adecaler <10){Decal = 3;}
return Decal;
}
// Fonction Comm Dfmini ************************ *******************
void printDetail(uint8_t type, int value){
switch (type) {
case TimeOut: Serial.println(F("Time Out!")); break;
case WrongStack: Serial.println(F("Stack Wrong!")); break;
case DFPlayerCardInserted: Serial.println(F("Card Inserted!")); break;
case DFPlayerCardRemoved: Serial.println(F("Card Removed!")); break;
case DFPlayerCardOnline: Serial.println(F("Card Online!")); break;
case DFPlayerUSBInserted: Serial.println("USB Inserted!"); break;
case DFPlayerUSBRemoved: Serial.println("USB Removed!"); break;
case DFPlayerPlayFinished: Serial.print(F("Number:")); Serial.print(value); Serial.println(F(" Play Finished!")); break;
case DFPlayerError: Serial.print(F("DFPlayerError:"));
switch (value) {
case Busy: Serial.println(F("Card not found")); break;
case Sleeping: Serial.println(F("Sleeping")); break;
case SerialWrongStack: Serial.println(F("Get Wrong Stack")); break;
case CheckSumNotMatch: Serial.println(F("Check Sum Not Match")); break;
case FileIndexOut: Serial.println(F("File Index Out of Bound")); break;
case FileMismatch: Serial.println(F("Cannot Find File")); break;
case Advertise: Serial.println(F("In Advertise")); break;
default: break;
}
break; default: break;
}
}
Par contre, je commence à ne plus trop avoir de place sur ma breadboard.
Sans compter qu'a chaque fois que je la range, j'ai toujours un câble qui se barre et je cherche des plombes le coupable.
Il est temps de passer à une version plus durable, voir la version finale (de l'électronique).
Du coup, je vais commander le nécessaire très vite, je vais juste checker ce qu'il me faut pour les lightguns de la future VirtuaCop histoire d'essayer de grouper au max ma commande.
J'en profiterai pour commander les poulies GT2 ainsi que tout le reste nécessaire à la "mécanique".
Du coup, pour la prochaine étape, je vais surement fabriquer le plateau.
Faudrait que je fasse un schéma de câblage aussi... Là si je fais tomber le bousin de câble, je ne m'y retrouverai pas.
Par contre je suis toujours dans l'attente de mes billes, elles sont apparemment bloquées à Paris depuis un mois

Enfin bref, ça risque d'avancer un peu moins les 2-3 prochaines semaines, faudra pas vous inquiétez.
Bsx