
Originally Posted by
duff
can you post something that compiles and does not rely on other non posted code or libraries that shows this problem?
Thanks for looking at this. Sorry about the posting. Here is some code that should compile with no other libraries:
Code:
#define SYSTEMPWR 2
#define DISPLAYPWR 12
//#include <SimpleTimer.h>
#include <Snooze.h>
uint8_t rx_byte = 0x00;
boolean badIn = false;
boolean sleeping = false;
boolean awake = false;
//SimpleTimer timer;
//int ledOnTimerID = 0;
//int ledOffTimerID = 0;
elapsedMillis ledOnTimerID = 0;
elapsedMillis ledOffTimerID = 0;
int ledOnLimit = 4000;
int ledOffLimit = 4000;
int displayOffPwrState = 0;
int displayOnPwrState = 0;
int displayPwrState = 0;
int count = 0;
SnoozeBlock config;
bool switchState; //variable that holds the system power state
void processDebug()
{
// capture any serial input to support debug printouts
if (Serial.available() > 0) // is a character available?
{
rx_byte = Serial.read(); // get a character from the Serial port
//Serial.print("Number received: ");
//Serial.println(rx_byte);
switch(rx_byte)
{
case 'z':
Serial.println(" ");
Serial.print("Display Power Off Count is: ");
Serial.println(displayOffPwrState);
Serial.print("Display Power On Count is: ");
Serial.println(displayOnPwrState);
Serial.print("Current Display Power State: ");
Serial.println(displayPwrState);
break;
default :
badIn = true;
break;
}
if (badIn)
{
Serial.println("Bad Input Try Again:");
Serial.println("z - Prints the power on power off counts");
badIn = false;
}
}
}
void wakeUp(void)
{
Serial.println("Wake Up from Sleep Called");
// when you come out of sleep power on the
// the display and reset the timers
digitalWrite(DISPLAYPWR, HIGH);
displayOnPwrState = displayOnPwrState + 1;
displayPwrState = 1;
// enable the timers that were disabled in standby
//timer.enable(ledOnTimerID);
//timer.enable(ledOffTimerID);
// reset the timers to flash the LED every 4 seconds when running
ledOffTimerID = 0;
ledOnTimerID = 300; // set led on 300 ms ahead of off so led stays on for 300 ms
awake = true;
sleeping = false;
}
void standby(void)
{
digitalWrite(DISPLAYPWR, LOW);
displayOffPwrState = displayOffPwrState + 1;
displayPwrState = 0;
//Serial.println("Sleeping ");
// disable the active timers
sleeping = true;
awake = false;
Snooze.sleep(config);
}
void functionOne()
{
count++;
}
void functionTwo()
{
count--;
}
void functionThree()
{
count++;
}
void checkTimer()
{
if(ledOnTimerID > ledOnLimit)
{
ledOn();
// reset the timer
ledOnTimerID = 0;
}
if(ledOffTimerID >= ledOffLimit)
{
ledOff();
// reset the timer
ledOffTimerID = 0;
}
}
//Teensy Light OFF (to verify Teensy is "Up")
void ledOff()
{
digitalWriteFast(LED_BUILTIN, LOW);
}
//Teensy Light ON (to verify Teensy is "Up")
void ledOn()
{
digitalWriteFast(LED_BUILTIN, HIGH);
}
void setup()
{
Serial.begin(115200);
pinMode(SYSTEMPWR, INPUT);
pinMode(DISPLAYPWR, OUTPUT);
pinMode(LED_BUILTIN, OUTPUT);
//config.pinMode(SYSTEMPWR, INPUT_PULLUP, RISING);
config.pinMode(SYSTEMPWR, INPUT, HIGH);
ledOffTimerID = 0;
ledOnTimerID = 300; // set led on 300 ms ahead of off so led stays on for 300 ms
// there is always power to the board so sleep or not based on external switch position
if(digitalRead(SYSTEMPWR))
{
displayPwrState = 1;
digitalWrite(DISPLAYPWR, HIGH);
}
else
{
standby();
}
}
void loop()
{
switchState = digitalRead(SYSTEMPWR);
if (switchState == HIGH)
{
if(sleeping)
{
wakeUp();
}
//Updates whatever timers have been defined
checkTimer();
//timer.run();
processDebug();
functionOne();
functionTwo();
functionThree();
}
else
{
standby();
}
}
I do not "wake up" using this code.
Thank you