Gaming Allowance Based on Sleep

Hi Forum,

I am a student trying to make a device that helps people improve sleep by giving computer allowance based on the amount of sleep the night before.

The code I have now (attached) is pretty much finished and works but there's something I want to improve. The device detects sleeping and waking up with a pressure sensor under the pillow (this is in mode=2), but as soon as I move my head off the pillow it thinks I've woken up. How do I make it so that it waits 5 minutes after detecting pressure to assume 'asleep' and 5 minutes after no pressure before assuming 'awake'?

Another thing, in (mode=4) I made the LEDs countdown the allowance but after it's done the last LED stays lit. I put [fill_solid(leds, 30, CRGB::Black);] but it didn't do anything.

Thanks in advance,


pressure_3.6.ino (2.43 KB)

You might be able to use millis() to do that. Something like

unsigned long lastTime = 0;

//then in the loop:
if(pressure < 900 && wasJustAsleep){
    lastTime = millis();
if (millis - lastTime > 300000){//5 minutes since lastTime was set to millis
sleeping = false; 

Of course, that will all have to be integrated with the rest of the code.