Add some basic button logic

pull/14/head
Dennis Bücker 1 year ago
parent 2ca345af38
commit 228bddd074
  1. 22
      src/EnterColorSequence.cpp
  2. 2
      src/MCUInfo.h
  3. 3
      src/main.cpp

@ -1,4 +1,5 @@
#include "SimonSays.h"
#include "MCUInfo.h"
#include <FastLED.h> // For color management
@ -29,7 +30,28 @@ void EnterColorSequence::leave(SimonSays &simonSays)
void EnterColorSequence::update(SimonSays &simonSays)
{
if (!inputStarted) {
// Only start,
simonSays.simonDisplay.displayOneColor(CRGB::Green);
//Serial.println("Game not started condition.");
if (M5.Btn.wasPressed())
{
inputStarted = true;
}
else
{
return;
}
}
// check for short press
if (M5.Btn.wasReleased())
{
simonSays.simonDisplay.displayOneColor(CRGB::Red);
}
// check for long press
if (M5.Btn.wasReleaseFor(MCUInfo::longButtonPress))
{
simonSays.simonDisplay.displayOneColor(CRGB::Orange);
}
}

@ -5,5 +5,7 @@ struct MCUInfo
static constexpr float periodIntervalInMs = 2000.f;
static constexpr float tickIntervalInMs = periodIntervalInMs/maxTicks;
static constexpr float longButtonPress = 700; // millisecond
};

@ -56,11 +56,12 @@ void loop()
{
timeOfLastTick = time;
M5.update();
Simon.update();
SimonDisplay.update();
M5.update();
}
//delay(1000);

Loading…
Cancel
Save