-----------------------CS00: 13.75sCS01: 110s (1m, 50s)CS02: 3520s (58m, 40s)CS00 + CS02: 14080s (3.91h)

---------------------CS00: 4766 /s (during dream phase)CS01: 593.8 /sCS02: 18.6 /sCS00 + CS02: 4.6 /s (during initial waitstate)

Other than initialization, the lucid13 software runs entirely via interrupts. Timer-triggered IRQs count through the long initial wait until the subject is in a deep sleep. The timing scaler is then switched to a high rate to create the smooth PWM for the lucid dreaming LED blinking.Functioning modes:--User input/options--Wait-for-sleep mode--PWM dreaming modeDuring startup the LED lights up for approx. 2 seconds to indicate operation.The device also checks if the input button was pressed and held during power up for those initial 2 seconds. If it was, "immediate mode" is entered: the LEDs begin blinking. This is mostly so guyfrom7up could easily test the hardware without waiting for four hours ;-).It could also be used for "catnap" type sleep states.However, we could also add a bit of code to vary the pulse width...whattay think?After checking for user input, etc., and setting up the IRQ, the ATtiny13 is immediate placed in sleep mode. In this mode only the timers, clocks and IRQs are functional. Of course, this is a power-saving measure.Rollover time for a 16-bit counter, per timer scaler value (times approx)--A ~4 hour wait is possible with the CS02 and CS00 flag combination, a clock scaler of 1024. In this state, the IRQ is triggered 4.6 times per second. The WAITING state could easily be fine tuned, by using the 16-bit counter (for durations < 4 hrs) together with the waitstate counter (for longer delays.)Since four hours is as good a delay as any, a longer-duration waitstate isn't used. A longer delay would be a trivial matter to implement.NOTE: guyfrom7up has found the waitstate for his AVRs is somewhat greater than 4 hours, while mine is somewhat less. The internal oscillator of the AVR isn't highly accurate, but it's good enough for our needs....At 4.6 IRQs per second, CPU power consumption should be very low. Of course the AVR cannot be in power-down mode, as that requires an external wake up signal. Ours must be timed internally, so SLEEP_MODE_IDLE is our best choice.IRQs per second, for each scaler (approx)--The timer scaler value changes to CS00 when MODE_DREAMING begins--in order to create the gentle transitions of the software pwm. The duty cycle for the CPU (and IRQ) is much greater (about 4.7K per second.) But the LED duty cycle is much less than it would be with a simple on/off switch. A trade off between cpu and LED current draw...The overall pulse width (length) of the LED blink is controlled by the MACRO_WIDTH and MACRO_GAP constants. The PWM is handled by incrementing the pwm and transition variables by the constants PWM_VAL and TRANS_VAL. Altering those constants will change how rapidly the PWM "ramps up."Currently, the dreaming frequency LED pulse rate is approx 1.5 hz.The current version (0.2b) uses only 438 bytes of flash memory. This is well short of the 1K limit on the ATtiny13.So adding more features is certainly do-able.