Tuto
Description
tuto
#include "Screen.h" #include "Bouton.h" #include "Led.h" #include "Son.h" #define DELAY_INSTRUCTIONS 5000 #define DO 261 #define RE 277 #define MI 293 Screen monEcran1; Bouton b; Led l; Son s; bool needClick; enum States { WELCOME, MENU, WAIT_BUTTON, USE_BUTTON, BUTTON_PUSH, LED, PLUG_LED, SWITCH_LED, BLINK_LED, BUZZER, WAIT_BUZZER, BUZZER_PLAY, OTHERS_BRICKS, END, SITE }; States state; void welcome() { attendre(200); monEcran1.printMsg(" T ", 2); attendre(700); monEcran1.printMsg(" TH ", 2); attendre(700); monEcran1.printMsg(" THI ", 2); attendre(700); monEcran1.printMsg(" THIN ", 2); attendre(700); monEcran1.printMsg(" THING ", 2); attendre(700); monEcran1.printMsg(" THINGZ ", 2); attendre(700); monEcran1.clear(); state = MENU; } void menu() { monEcran1.printMsg(" Bienvenue !", 0); monEcran1.printMsg("Decouvrons", 2); monEcran1.printMsg("ensemble ta", 3); monEcran1.printMsg("carte Thingz", 4); monEcran1.printMsg(" :)", 5); attendre(DELAY_INSTRUCTIONS); monEcran1.clear(); monEcran1.printMsg("Si tu veux", 0); monEcran1.printMsg("recommencer", 1); monEcran1.printMsg("ces instru-", 2); monEcran1.printMsg("ctions tu peux", 3); monEcran1.printMsg("a tout moment", 4); monEcran1.printMsg("debrancher et", 5); attendre(DELAY_INSTRUCTIONS); monEcran1.clear(); monEcran1.printMsg("rebrancher ", 0); monEcran1.printMsg("l'ecran", 1); attendre(DELAY_INSTRUCTIONS); monEcran1.clear(); monEcran1.printMsg("Pour commencer", 0); monEcran1.printMsg("Tu vas avoir", 1); monEcran1.printMsg("besoin d'un", 2); monEcran1.printMsg("bouton", 3); attendre(DELAY_INSTRUCTIONS); monEcran1.clear(); monEcran1.printMsg("Branche un", 0); monEcran1.printMsg("bouton n'im-", 1); monEcran1.printMsg("porte ou sur", 2); monEcran1.printMsg("la carte", 3); attendre(DELAY_INSTRUCTIONS); state = WAIT_BUTTON; } void waitButton() { if (b.isReady()) { state = USE_BUTTON; monEcran1.clear(); } } void useButton() { monEcran1.printMsg("Tres bien !", 0); monEcran1.printMsg("Clique pour", 1); monEcran1.printMsg("decouvrir la", 2); monEcran1.printMsg("suite", 3); needClick = true; } void buttonPush() { monEcran1.clear(); monEcran1.printMsg("Genial ! ;)", 0); attendre(2000); monEcran1.clear(); monEcran1.printMsg("Poursuivons", 0); monEcran1.printMsg("notre decou-", 1); monEcran1.printMsg("verte. Clique", 2); monEcran1.printMsg("pour continuer", 3); needClick = true; } void led() { monEcran1.clear(); monEcran1.printMsg("Avec Thingz tu", 0); monEcran1.printMsg("peux faire de", 1); monEcran1.printMsg("la lumiere.", 2); monEcran1.printMsg("Branche une", 3); monEcran1.printMsg("Led", 4); attendre(DELAY_INSTRUCTIONS); state = PLUG_LED; } void waitLed() { if (l.isReady()) { state = SWITCH_LED; monEcran1.clear(); } } void switchLed() { monEcran1.printMsg("Regarde la led.", 0); monEcran1.printMsg("Je peux", 1); monEcran1.printMsg("l'allumer", 2); attendre(2000); l.allume(); attendre(3000); monEcran1.clear(); monEcran1.printMsg("ou l'eteindre", 0); attendre(2000); l.eteind(); attendre(3000); state = BLINK_LED; } void blinkLed() { monEcran1.clear(); monEcran1.printMsg("Mais je peux", 0); monEcran1.printMsg("aussi la faire", 1); monEcran1.printMsg("clignoter", 2); for (int i = 0; i < 3; i++) { attendre(1000); l.allume(); attendre(1000); l.eteind(); } monEcran1.clear(); monEcran1.printMsg("Je peux le", 0); monEcran1.printMsg("faire plus", 1); monEcran1.printMsg("lentement", 2); for (int i = 0; i < 3; i++) { attendre(2000); l.allume(); attendre(2000); l.eteind(); } monEcran1.clear(); monEcran1.printMsg("Ou plus ", 0); monEcran1.printMsg("rapidement", 1); for (int i = 0; i < 10; i++) { attendre(400); l.allume(); attendre(400); l.eteind(); } attendre(1000); monEcran1.clear(); monEcran1.printMsg("C'est moi qui", 0); monEcran1.printMsg("qui decide.", 1); monEcran1.printMsg("C'est moi qui", 2); monEcran1.printMsg("programme !", 3); monEcran1.printMsg("Et bientot", 4); monEcran1.printMsg("ce sera TOI !", 5); attendre(DELAY_INSTRUCTIONS); state = BUZZER; } void buzzer() { monEcran1.clear(); monEcran1.printMsg("Thingz c'est", 0); monEcran1.printMsg("aussi du son", 1); monEcran1.printMsg("Branche le", 2); monEcran1.printMsg("buzzer", 3); state = WAIT_BUZZER; } void waitBuzzer() { if (s.isReady()) { state = BUZZER_PLAY; monEcran1.clear(); } } void buzzerPlay() { monEcran1.printMsg("Deviens un", 0); monEcran1.printMsg("vrai musicien", 1); attendre(2000); monEcran1.clear(); monEcran1.printMsg("DO", 0); s.sonne(DO); attendre(600); s.arreteDeSonner(); attendre(100); monEcran1.clear(); monEcran1.printMsg("RE", 0); s.sonne(RE); attendre(600); s.arreteDeSonner(); attendre(100); monEcran1.clear(); monEcran1.printMsg("MI", 0); s.sonne(MI); attendre(600); s.arreteDeSonner(); attendre(100); monEcran1.clear(); monEcran1.printMsg("Et pourquoi", 0); monEcran1.printMsg("pas au clair ", 1); monEcran1.printMsg("de la lune", 2); attendre(2000); monEcran1.clear(); s.sonne(DO); monEcran1.printMsg("DO", 0); attendre(400); s.arreteDeSonner(); monEcran1.clearLine(0); attendre(200); s.sonne(DO); monEcran1.printMsg("DO", 0); attendre(400); s.arreteDeSonner(); monEcran1.clearLine(0); attendre(200); s.sonne(DO); monEcran1.printMsg("DO", 0); attendre(400); s.arreteDeSonner(); monEcran1.clearLine(0); attendre(200); s.sonne(RE); monEcran1.printMsg("RE", 0); attendre(400); s.arreteDeSonner(); monEcran1.clearLine(0); attendre(200); s.sonne(MI); monEcran1.printMsg("MI", 0); attendre(800); s.arreteDeSonner(); monEcran1.clearLine(0); attendre(400); s.sonne(RE); monEcran1.printMsg("RE", 0); attendre(800); s.arreteDeSonner(); monEcran1.clearLine(0); attendre(400); s.sonne(DO); monEcran1.printMsg("DO", 0); attendre(400); s.arreteDeSonner(); monEcran1.clearLine(0); attendre(200); s.sonne(MI); monEcran1.printMsg("MI", 0); attendre(400); s.arreteDeSonner(); monEcran1.clearLine(0); attendre(200); s.sonne(RE); monEcran1.printMsg("RE", 0); attendre(400); s.arreteDeSonner(); monEcran1.clearLine(0); attendre(200); s.sonne(RE); monEcran1.printMsg("RE", 0); attendre(400); s.arreteDeSonner(); monEcran1.clearLine(0); attendre(200); s.sonne(DO); monEcran1.printMsg("DO", 0); attendre(2400); s.arreteDeSonner(); monEcran1.clearLine(0); attendre(1000); state = OTHERS_BRICKS; } void othersBricks() { monEcran1.printMsg("Tu viens de", 0); monEcran1.printMsg("de voir une", 1); monEcran1.printMsg("introduction", 2); monEcran1.printMsg("de ce qu'est", 3); monEcran1.printMsg("Thingz. Mais", 4); monEcran1.printMsg("il te reste", 5); attendre(DELAY_INSTRUCTIONS); monEcran1.clear(); monEcran1.printMsg("encore beau-", 0); monEcran1.printMsg("coup de choses", 1); monEcran1.printMsg("a decouvrir !", 2); attendre(DELAY_INSTRUCTIONS); monEcran1.clear(); monEcran1.printMsg("Pour ca,", 0); monEcran1.printMsg("rendez-vous", 1); monEcran1.printMsg("sur ", 2); monEcran1.printMsg("https://thingz", 3); monEcran1.printMsg(".co/blog", 4); attendre(DELAY_INSTRUCTIONS); monEcran1.clear(); state = END; } void end() { monEcran1.printMsg("D'ici la", 0); monEcran1.printMsg("Soit inventif", 1); monEcran1.printMsg(".Laisse", 2); monEcran1.printMsg("parler ton", 3); monEcran1.printMsg("imagination", 4); monEcran1.printMsg("Et surtout", 5); attendre(DELAY_INSTRUCTIONS); monEcran1.clear(); monEcran1.printMsg(" Amuse toi !", 0); monEcran1.printMsg(" 0 0", 2); monEcran1.printMsg(" ____", 3); monEcran1.printMsg(" \\__/", 4); attendre(DELAY_INSTRUCTIONS); monEcran1.clear(); state = SITE; } void site() { monEcran1.printMsg("A tres vite", 0); monEcran1.printMsg("sur", 1); monEcran1.printMsg("https://thingz", 2); monEcran1.printMsg(".co/blog", 3); } void doState() { switch (state) { case WELCOME: welcome(); break; case MENU: menu(); break; case WAIT_BUTTON: waitButton(); break; case USE_BUTTON: useButton(); break; case BUTTON_PUSH: buttonPush(); break; case LED: led(); break; case PLUG_LED: waitLed(); break; case SWITCH_LED: switchLed(); break; case BLINK_LED: blinkLed(); break; case BUZZER: buzzer(); break; case WAIT_BUZZER: waitBuzzer(); break; case BUZZER_PLAY: buzzerPlay(); break; case OTHERS_BRICKS: othersBricks(); break; case END: end(); break; case SITE: site(); break; } } void setup() { Serial.begin(9600); needClick = false; } void loop() { if (!monEcran1.isReady()) { state = WELCOME; } else if (!needClick) doState(); else { if (b.aEteAppuye()) { state = States(int(state) + 1); needClick = false; } } }