#include <Snooze.h>
// Load drivers
SnoozeDigital digital;
SnoozeTimer timer;
SnoozeUSBSerial usb;
//SnoozeBlock config_teensy(usb, timer);
SnoozeBlock config_teensy(usb, timer, digital); ///*** REB ADDED / CHANGED
const int maxHistorySize = 40; //**** REB ADDED 3333
struct hData //**** REB ADDED 3333
{ //**** REB ADDED 3333
char text[25]; //**** REB ADDED 3333
unsigned long time; //**** REB ADDED 3333
}; //**** REB ADDED 3333
hData history[maxHistorySize]; //**** REB ADDED 3333
int idx = 0; //**** REB ADDED 3333
// set pin numbers:
const int button1Pin = 0; // sw1
const int button2Pin = 9; // sw2
const int led1Pin = 21; // led1
const int led2Pin = 20; // led2
void setup() {
Serial.begin(115200);
while (!usb){};
pinMode(led1Pin, OUTPUT);
pinMode(led2Pin, OUTPUT);
digital.pinMode(button1Pin, INPUT_PULLUP, FALLING);//pin, mode, type
digital.pinMode(button2Pin, INPUT_PULLUP, FALLING);//pin, mode, type
timer.setTimer(5000);// milliseconds
// usb.println("Setup Done");
}
bool done1=false; //**** REB ADDED 2222
bool done2=false; //**** REB ADDED 2222
bool done3=false; //**** REB ADDED 2222
void loop() {
int who;
static elapsedMillis clock;
uint32_t iWokeUpAt; //**** REB ADDED ****
uint32_t usbWokeUpAt; //**** REB ADDED ****
if ((done3==false) && (clock >= 1000)) { //**** REB ALTERED 2222
done3=true;
strncpy(history[idx].text, "three", 10); //**** REB ADDED 3333
history[idx].time = millis(); //**** REB ADDED 3333
++idx; //**** REB ADDED 3333
usb.println("three");
digitalWrite(led2Pin, HIGH);
delay(200);
digitalWrite(led2Pin, LOW);
} else if ((done2==false) && (clock >= 2000)) { //**** REB ALTERED 2222
done2=true;
strncpy(history[idx].text, "two", 10); //**** REB ADDED 3333
history[idx].time = millis(); //**** REB ADDED 3333
++idx; //**** REB ADDED 3333
usb.println("two");
digitalWrite(led2Pin, HIGH);
delay(200);
digitalWrite(led2Pin, LOW);
} else if ((done1==false) && (clock >= 3000)) { //**** REB ALTERED 2222
done1=true;
strncpy(history[idx].text, "one", 10); //**** REB ADDED 3333
history[idx].time = millis(); //**** REB ADDED 3333
++idx; //**** REB ADDED 3333
usb.println("one");
digitalWrite(led2Pin, HIGH);
delay(200);
digitalWrite(led2Pin, LOW);
} else if (clock > 4000){
strncpy(history[idx].text, "zzz", 10); //**** REB ADDED 3333
history[idx].time = millis(); //**** REB ADDED 3333
++idx; //**** REB ADDED 3333
usb.println("zzz");
done1=false; //**** REB ADDED 2222
done2=false; //**** REB ADDED 2222
done3=false; //**** REB ADDED 2222
delay(10);
/********************************************************
feed the sleep function its wakeup parameters. Then go
to deepSleep.
********************************************************/
usb.flush();
delay(500);
// config_teensy += digital; //**** REB REMOVED ****
who = Snooze.deepSleep( config_teensy );// return module that woke processor
// config_teensy -= digital; //**** REB REMOVED ****
iWokeUpAt = millis(); //**** REB ADDED ****
while (!usb && (millis() < iWokeUpAt + 8000)); //**** REB ADDED ****
usbWokeUpAt = millis(); //**** REB ADDED ****
delay(500);
strncpy(history[idx].text, "Good morning", 25); //**** REB ADDED 3333
history[idx].time = millis(); //**** REB ADDED 3333
++idx; //**** REB ADDED 3333
usb.println("Good morning");
usb.print("who="); usb.println(who); //**** REB ADDED ****
usb.print("Time to wake up usb="); //**** REB ADDED ****
usb.print(usbWokeUpAt - iWokeUpAt); //**** REB ADDED ****
usb.println("ms"); //**** REB ADDED ****
if (who == button1Pin) { // pin wakeup source is its pin value
for (int i = 0; i < 1; i++) {
digitalWrite(led1Pin, HIGH);
delay(200);
digitalWrite(led1Pin, LOW);
delay(200);
}
}
if (who == button2Pin) { // pin wakeup source is its pin value
for (int i = 0; i < 2; i++) {
digitalWrite(led1Pin, HIGH);
delay(200);
digitalWrite(led1Pin, LOW);
delay(200);
}
}
if (who == 34) { // compare wakeup value
for (int i = 0; i < 3; i++) {
digitalWrite(led1Pin, HIGH);
delay(200);
digitalWrite(led1Pin, LOW);
delay(200);
}
}
if (who == 35) { // rtc wakeup value
for (int i = 0; i < 4; i++) {
digitalWrite(led1Pin, HIGH);
delay(200);
digitalWrite(led1Pin, LOW);
delay(200);
}
}
if (who == 36) { // lptmr wakeup value
for (int i = 0; i < 5; i++) {
digitalWrite(led1Pin, HIGH);
delay(200);
digitalWrite(led1Pin, LOW);
delay(200);
}
}
if (who == 37) { // tsi wakeup value
for (int i = 0; i < 6; i++) {
digitalWrite(led1Pin, HIGH);
delay(200);
digitalWrite(led1Pin, LOW);
delay(200);
}
}
clock = 0;
}
if (idx >= maxHistorySize-2) //**** REB ADDED 3333
{
usb.println("------------- HISTORY --------------------"); //**** REB ADDED 3333
for (int n = 0; n < idx; ++n) //**** REB ADDED 3333
{ //**** REB ADDED 3333
usb.print(history[n].time); //**** REB ADDED 3333
usb.print(" - "); //**** REB ADDED 3333
usb.println(history[n].text); //**** REB ADDED 3333
} //**** REB ADDED 3333
usb.println(idx); //**** REB ADDED 3333
usb.println("---------- END OF HISTORY ----------------"); //**** REB ADDED 3333
idx = 0; //**** REB ADDED 3333
while (1); //**** REB ADDED 3333
}
}