So, I am trying to make my Nano go to sleep if it hasn't been used for 10 seconds.
But how do I wake it up again without resetting it? I can't use an interrupt pin, or a timer. This is what I am following: https://www.gammon.com.au/power
[code]
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <avr/sleep.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
static const unsigned char PROGMEM image_data_ARDUINOarray[] = {
// ARDUINO Logo C-File Array
// This is a logo array, removed because it is irrelevant
};
unsigned long previousMillis = 0;
const long interval = 10000;
void setup() {
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
display.clearDisplay();
display.drawBitmap(0, 0, image_data_ARDUINOarray, 128, 64, 1);
display.display();
delay(2000);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(15, 5);
display.println(F("Checking Battery"));
display.setCursor(20, 25);
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.print(F("Battery"));
display.setCursor(25, 45);
display.print(F("Tester"));
display.display();
delay(2000);
display.clearDisplay();
display.fillRect(108, 3, 2, 3, SSD1306_INVERSE);
display.drawRect(110, 0, 18, 10, SSD1306_INVERSE);
display.display();
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
display.clearDisplay();
display.display();
set_sleep_mode (SLEEP_MODE_PWR_DOWN);
sleep_enable();
sleep_cpu ();
}
}
[/code]
This is a battery tester. It needs to automatically detect when a battery to be tested is attached to the circuit. The problem is that I already ordered the PCBs - before I thought of the sleep idea!