Advertisement
learnelectronics

Low Power Arduino

Mar 10th, 2020
3,259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.25 KB | None | 0 0
  1.  
  2. // https://github.com/rocketscream/Low-Power
  3.  
  4.  
  5.  
  6.  
  7.  
  8. #include <LowPower.h>                                //the library for the low power
  9. #include <Wire.h>                                    //i2c library for display
  10. #include <Adafruit_SSD1306.h>                        //adafruit display library
  11.  
  12. #define OLED_RESET 4                                  //required by the adafruit library
  13. Adafruit_SSD1306 display(OLED_RESET);                 //set up the display
  14.  
  15. void setup() {
  16.   Serial.begin(9600);                                 //serial comms for debugging
  17.   pinMode(13,OUTPUT);                                 //set built in LED for output
  18.  
  19. digitalWrite(13,LOW);                                 //turn off LED
  20.  
  21.   display.begin(SSD1306_SWITCHCAPVCC, 0x3C);          //start the display  
  22.   display.display();                                  //display the buffer data
  23.  
  24.   display.clearDisplay();                             //clear the display
  25.  
  26. }
  27.  
  28. void loop() {
  29.  
  30.   digitalWrite(13,HIGH);                              //turn on led
  31.   display.setTextSize(2);                             //setup data for display
  32.   display.setTextColor(WHITE);                        //setup data for display
  33.   display.setCursor(0,0);                             //setup data for display
  34.   display.clearDisplay();                             //setup data for display
  35.   display.println("Arduino:- I am going for a Nap");  //put nap message in buffer
  36.   display.display();                                  //display the buffer data
  37.  
  38.   delay(2000);                                        //have a quick smoke
  39.   digitalWrite(13,LOW);                               //turn LED off
  40.  
  41.  
  42.   LowPower.idle(SLEEP_8S, ADC_OFF, TIMER2_OFF, TIMER1_OFF, TIMER0_OFF,
  43.                  SPI_OFF, USART0_OFF, TWI_OFF);                               //sleepy time
  44.  
  45.   display.clearDisplay();                             //setup data for display
  46.   display.setCursor(0,0);                             //setup data for display
  47.   display.println("Arduino:- Hey I just Woke up");    //put wake up message in buffer
  48.   Serial.println("");
  49.   display.display();                                  //display buffer data
  50.   delay(2000);                                        //finish that smoke
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement