mirror of
https://github.com/taigrr/arduinolibs
synced 2025-01-18 04:33:12 -08:00
Turn off more unused CPU features
This commit is contained in:
parent
20c266f853
commit
f90571c4d7
@ -29,8 +29,10 @@
|
|||||||
#include <DS1307RTC.h>
|
#include <DS1307RTC.h>
|
||||||
#include <Melody.h>
|
#include <Melody.h>
|
||||||
#include <PowerSave.h>
|
#include <PowerSave.h>
|
||||||
|
#include <avr/power.h>
|
||||||
#include "FrontScreen.h"
|
#include "FrontScreen.h"
|
||||||
#include "EditTime.h"
|
#include "EditTime.h"
|
||||||
|
#include "LowPowerMelody.h"
|
||||||
|
|
||||||
// I/O pins that are used by this sketch.
|
// I/O pins that are used by this sketch.
|
||||||
#define BUZZER 12
|
#define BUZZER 12
|
||||||
@ -55,7 +57,7 @@ DS1307RTC rtc(bus, RTC_ONE_HZ);
|
|||||||
// Melody to play when the alarm sounds.
|
// Melody to play when the alarm sounds.
|
||||||
int alarmNotes[] = {NOTE_C6, NOTE_C6, NOTE_C6, NOTE_C6, NOTE_REST};
|
int alarmNotes[] = {NOTE_C6, NOTE_C6, NOTE_C6, NOTE_C6, NOTE_REST};
|
||||||
byte alarmLengths[] = {8, 8, 8, 8, 2};
|
byte alarmLengths[] = {8, 8, 8, 8, 2};
|
||||||
Melody alarmMelody(BUZZER);
|
LowPowerMelody alarmMelody(BUZZER);
|
||||||
|
|
||||||
uint8_t prevHour = 24;
|
uint8_t prevHour = 24;
|
||||||
|
|
||||||
@ -78,6 +80,12 @@ void setup() {
|
|||||||
unusedPin(11);
|
unusedPin(11);
|
||||||
unusedPin(13);
|
unusedPin(13);
|
||||||
|
|
||||||
|
// Turn off peripherals we don't need.
|
||||||
|
power_spi_disable();
|
||||||
|
power_usart0_disable();
|
||||||
|
power_twi_disable();
|
||||||
|
power_timer1_disable();
|
||||||
|
|
||||||
// Enable the screen saver.
|
// Enable the screen saver.
|
||||||
lcd.setScreenSaverMode(FreetronicsLCD::BacklightOnSelect);
|
lcd.setScreenSaverMode(FreetronicsLCD::BacklightOnSelect);
|
||||||
lcd.enableScreenSaver(3);
|
lcd.enableScreenSaver(3);
|
||||||
@ -86,6 +94,7 @@ void setup() {
|
|||||||
alarmMelody.setMelody(alarmNotes, alarmLengths, sizeof(alarmLengths));
|
alarmMelody.setMelody(alarmNotes, alarmLengths, sizeof(alarmLengths));
|
||||||
alarmMelody.setLoopDuration(120000UL);
|
alarmMelody.setLoopDuration(120000UL);
|
||||||
//alarmMelody.play();
|
//alarmMelody.play();
|
||||||
|
alarmMelody.stop(); // Force Timer2 to be disabled.
|
||||||
|
|
||||||
// Read the clock settings from the realtime clock's NVRAM.
|
// Read the clock settings from the realtime clock's NVRAM.
|
||||||
hourMode.setValue(rtc.readByte(SETTING_24HOUR) != 0);
|
hourMode.setValue(rtc.readByte(SETTING_24HOUR) != 0);
|
||||||
@ -139,7 +148,7 @@ void loop() {
|
|||||||
|
|
||||||
// If the alarm is playing and a button was pressed, then turn it off.
|
// If the alarm is playing and a button was pressed, then turn it off.
|
||||||
if (alarmMelody.isPlaying()) {
|
if (alarmMelody.isPlaying()) {
|
||||||
if (event != LCD_BUTTON_NONE)
|
if (event > 0)
|
||||||
alarmMelody.stop();
|
alarmMelody.stop();
|
||||||
alarmMelody.run();
|
alarmMelody.run();
|
||||||
} else {
|
} else {
|
||||||
|
42
libraries/RTC/examples/AlarmClock/LowPowerMelody.cpp
Normal file
42
libraries/RTC/examples/AlarmClock/LowPowerMelody.cpp
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012 Southern Storm Software, Pty Ltd.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
|
* to deal in the Software without restriction, including without limitation
|
||||||
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
* and/or sell copies of the Software, and to permit persons to whom the
|
||||||
|
* Software is furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included
|
||||||
|
* in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
* DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "LowPowerMelody.h"
|
||||||
|
#include <avr/power.h>
|
||||||
|
|
||||||
|
void LowPowerMelody::play()
|
||||||
|
{
|
||||||
|
// Turn on Timer2.
|
||||||
|
power_timer2_enable();
|
||||||
|
|
||||||
|
// Start the melody playing.
|
||||||
|
Melody::play();
|
||||||
|
}
|
||||||
|
|
||||||
|
void LowPowerMelody::stop()
|
||||||
|
{
|
||||||
|
// Stop the melody playing.
|
||||||
|
Melody::stop();
|
||||||
|
|
||||||
|
// Turn off Timer2.
|
||||||
|
power_timer2_disable();
|
||||||
|
}
|
36
libraries/RTC/examples/AlarmClock/LowPowerMelody.h
Normal file
36
libraries/RTC/examples/AlarmClock/LowPowerMelody.h
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012 Southern Storm Software, Pty Ltd.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
|
* to deal in the Software without restriction, including without limitation
|
||||||
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
* and/or sell copies of the Software, and to permit persons to whom the
|
||||||
|
* Software is furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included
|
||||||
|
* in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
* DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef LowPowerMelody_h
|
||||||
|
#define LowPowerMelody_h
|
||||||
|
|
||||||
|
#include <Melody.h>
|
||||||
|
|
||||||
|
class LowPowerMelody : public Melody {
|
||||||
|
public:
|
||||||
|
LowPowerMelody(uint8_t pin) : Melody(pin) {}
|
||||||
|
|
||||||
|
void play();
|
||||||
|
void stop();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
x
Reference in New Issue
Block a user