Pages: 1 [2]   Go Down
Author Topic: Help with improving code  (Read 624 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The code that you posted, is that still functional without the UL-part, Paul talked about?

Two hours after you go to sleep, you first start going into REM-sleep. We don't want to interfere before going to sleep. Hence the 2 hour waiting period.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset



GOD BLESS ARDUINO AND THIS GUY WHO I CANT BOTHER TO CHECK HIS NAME. IT WORKS. OIL!
Logged

Des Moines, WA - USA
Offline Offline
God Member
*****
Karma: 25
Posts: 779
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The code that you posted, is that still functional without the UL-part, Paul talked about?

Two hours after you go to sleep, you first start going into REM-sleep. We don't want to interfere before going to sleep. Hence the 2 hour waiting period.

Yes, thanks for asking!

Now a simplified and smaller version.

Code:
/*
   Inception Sleep Goggles

   LEDs in the goggles blink an a timed pattern to alert you when you are
   dreaming. The program waits 2 hours for you to fall asleep before starting
   the blink sequence every 10 minutes.
   
   This example code is in the public domain.
*/

#define ENTRIES(ARRAY)  (sizeof(ARRAY) / sizeof(ARRAY[0])

const unsigned long     TENTH_SECOND    =  100UL;
const unsigned long     QUARTER_SECOND  =  250UL;
const unsigned long     HALF_SECOND     =  500UL;
const unsigned long     SECOND          = 1000UL;
const unsigned long     TWO_SECONDS     =  2 * SECOND;
const unsigned long     MINUTE          = 60 * SECOND;
const unsigned long     TEN_MINUTES     = 10 * MINUTE;
const unsigned long     HOUR            = 60 * MINUTE;
const unsigned long     TWO_HOURS       =  2 * HOUR;

const uint8_t           LED_OFF         = LOW;
const uint8_t           LED_ON          = HIGH;

const uint8_t           pinLED          = 2;    // Attiny85

struct timing_pair_t
{
    const unsigned long _msON;
    const unsigned long _msOFF;
};

timing_pair_t           sequence[] =
{
    // SEQUENCE TABLE IS REVERSED

      {   TENTH_SECOND,    TEN_MINUTES }        // Sequence End
    , {   TENTH_SECOND,   TENTH_SECOND }
    , {   TENTH_SECOND,   TENTH_SECOND }
    , {   TENTH_SECOND,   TENTH_SECOND }
    , {   TENTH_SECOND,   TENTH_SECOND }
    , { QUARTER_SECOND, QUARTER_SECOND }
    , {    HALF_SECOND,    HALF_SECOND }           
    , {         SECOND,    HALF_SECOND }
    , {    TWO_SECONDS,      TWO_HOURS }        // Sequence Begin
};

void blink(unsigned long msOn, unsigned long msOff)
{
    digitalWrite(pinLED, LED_ON);   delay(msOn);
    digitalWrite(pinLED, LED_OFF);  delay(msOff);
}

void setup()
{
    pinMode(pinLED, OUTPUT);
}

void loop()
{
    // start at the end of 'sequence[]'

    for ( int i = ENTRIES(sequence); i--; )
    {
        blink(sequence[i]._msON, sequence[i]._msOFF);
    }
}
« Last Edit: January 13, 2013, 09:47:24 pm by lloyddean » Logged

Pages: 1 [2]   Go Up
Jump to: