From fac1fbdd1e35999d0ecebf247122f172b5128d8a Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Wed, 28 Apr 2021 23:27:30 +0200 Subject: [PATCH] Add skeleton of the game --- fastest_presser/platformio.ini | 1 + fastest_presser/src/main.cpp | 49 +++++++++++++++++++++++++++++++--- fastest_presser/src/main.h | 11 ++++++++ 3 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 fastest_presser/src/main.h diff --git a/fastest_presser/platformio.ini b/fastest_presser/platformio.ini index ea23b77..baf8082 100644 --- a/fastest_presser/platformio.ini +++ b/fastest_presser/platformio.ini @@ -12,3 +12,4 @@ platform = atmelavr board = uno framework = arduino +lib_deps = arduino-libraries/LiquidCrystal@^1.0.7 diff --git a/fastest_presser/src/main.cpp b/fastest_presser/src/main.cpp index e55b7e4..8387b00 100644 --- a/fastest_presser/src/main.cpp +++ b/fastest_presser/src/main.cpp @@ -1,8 +1,51 @@ #include +#include +#include + +LiquidCrystal lcd(12, 11, 2, 3, 4, 5); + void setup() { -// write your initialization code here + pinMode(LED_BUILTIN, OUTPUT); + digitalWrite(LED_BUILTIN, LOW); + randomSeed(analogRead(0)); + lcd.begin(16, 2); } void loop() { -// write your code here -} \ No newline at end of file + displayCountdown(); + delay(1000); + byte randomWait = random(6, 32); + lcd.clear(); + for (byte i = 0; i < randomWait; i++) { + if (i == 16) { + lcd.setCursor(0, 1); + } + lcd.print("."); + delay(500); + } + lcd.clear(); + lcd.print("Maintenant !"); + // TODO add code to determine winner, maybe use interrupts? + delay(2000); + lcd.clear(); +} + +void displayCountdown() { + lcd.setCursor(0, 0); + lcd.print("Prets ?"); + lcd.setCursor(0, 1); + displayDigit("3"); + delay(600); + displayDigit("2"); + delay(600); + displayDigit("1"); +} + +void displayDigit(const char *digit) { + lcd.print(digit); + for (byte i = 0; i < 3; i++) { + delay(200); + lcd.print("."); + } + lcd.print(" "); +} diff --git a/fastest_presser/src/main.h b/fastest_presser/src/main.h new file mode 100644 index 0000000..be4186a --- /dev/null +++ b/fastest_presser/src/main.h @@ -0,0 +1,11 @@ +// +// Created by Gabriel Augendre on 28/04/2021. +// + +#ifndef FASTEST_PRESSER_MAIN_H +#define FASTEST_PRESSER_MAIN_H + +void displayCountdown(); +void displayDigit(const char *digit); + +#endif //FASTEST_PRESSER_MAIN_H