/*
SleepWakeToggle
SUMMARY
Toggles an atmega*8 state from running to lowest power sleep
mode using a hardware interrupt, e.g. a switch. Suitable for
Arduino, JeeNode, etc.
WHY
Battery powered devices last double-plus-much-longer if you power
the chip down when not in use.
HOW IT WORKS
Interrupts are a way of having your program flow altered by simple
real world events (e.g. passage of time or activation of switches).
This program demonstrates using a single switch to accomplish two
things: putting the chip in sleep mode and then waking it up. When
a switch is activated, an interrupt is triggered and program
control is shifted to a function you specify (a callback). Two
hardware interrupts are available INT0 and INT1.
Boldly rebinding INT0/INT1 callbacks to the wake and sleep functions
in the callbacks themselves is bad magic, and doesn't seem to work
:-). So the sleep function is called from loop() after a callback
sets a flag. This way the callback which triggers sleep (here:
'toggle') is done before 'void sleep()' actually runs. This is good
because, the interrupt has to be rebound to 'wake' just before going
in to sleep_mode.
HARDWARE SETUP
Lowest power sleep mode, SLEEP_MODE_PWR_DOWN, can only respond to a
pin going from high to low. Hence, tie desired pin (2 or 3) to +
with a resistor (i.e. a "pull-up" resistor), and connect a momentary
switch to ground and the pin.
SOFTWARE SETUP
You will want to provide functions that do something interesting and
that cause the system to be in your desired state before actually
powering down. These are: "void importantThing()" and "void
prepareToSleep()" below. The state that is achieved after power up
or reset is selected by setting the global flag buttonPushed in the
setup function.
Hereby placed in the public domain, December 2010
by Kael Fischer <kael.fischer@gmail.com>
*/
// hardware interrupt stuff
#include <avr/sleep.h>
#define INT0 0
#define INT0_PIN 2
#define INT1 1
#define INT1_PIN 3
// application specific stuff
#define BLINK_PIN 13
// global flags
int buttonPushed;
void importantThing(){
// the 'work' the program does
digitalWrite(BLINK_PIN, HIGH);
delay(1000);
digitalWrite(BLINK_PIN, LOW);
delay(1000);
}
void prepareToSleep(){
// When a button is pushed
// do some prep before sleeping
// to get in the desired state
digitalWrite(BLINK_PIN, LOW);
}
void wake(){
// This is the callback that runs when the
// chip is waking up.
buttonPushed=0;
// Can set variables and check stuff. Cannot do fancy stuff.
// Program flow returns to line after 'sleep_mode()' in sleep.
// No code is required here.
}
void toggle(){
// set a flag telling system to sleep on next loop iteration.
// this is the normal running state callback triggered by the
// switch.
detachInterrupt(1); // this seems to be allowed in callback
if (buttonPushed ==0){ // just in case, ignore switch if already
buttonPushed=1; // doing it
}
}
void sleep(){
prepareToSleep(); //application specific
// YOU ARE GETTING SLEEPY.....
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
attachInterrupt(INT1,wake,LOW); // rebind interrupt
sleep_mode(); // sleeping
// program returns here, after 'wake' callback
// now back to loop
}
void setup() {
// On Off Toggle setup
pinMode(INT1_PIN, INPUT); // set switch pin to input
// to limit current
attachInterrupt(INT1,toggle,LOW);
buttonPushed=1; // set to 1 = sleep after reset
// 0 = run loop after reset
// app specific setup here
pinMode(BLINK_PIN, OUTPUT);
}
void loop() {
if (buttonPushed == 1) {
sleep();
} else {
// reset button events to sleep
attachInterrupt(INT1,toggle,LOW);
}
// do important things
importantThing();
}
Saturday, December 11, 2010
atmega*8 Hardware Sleep-Wake Toggle
Sunday, December 5, 2010
Recent Icicles
The Dork Haus had some great icicles over Thanksgiving and a few days after. It was cold. Click through and check it out at higher resolution: Gallery link.
Saturday, November 20, 2010
Thursday, September 30, 2010
Monday, September 20, 2010
The Meat Eaters - NYTimes.com
Jeff McMahan says: : it would be instrumentally good if predatory animal species were to become extinct and be replaced by new herbivorous species. A very modest proposal, of course.
Thursday, July 22, 2010
Tuesday, July 20, 2010
Sunday, July 11, 2010
black raspberry bounty
Friday, April 30, 2010
Thursday, April 29, 2010
Government requests directed to Google and YouTube
Government requests directed to Google and YouTube
Wednesday, April 21, 2010
Friday, April 9, 2010
BONUS Document Friday: Alexander Haig and the Wiretapping of American Citizens « UNREDACTED
Former Secretary of State Alexander M. Haig,who died last week at the age of 85, played a variety of roles in the military and the government, including combat duty in Korea and Vietnam, Army Chief of Staff, White House Chief of Staff, and Supreme Allied Commander Europe. It is worth remembering, however, that when he was military assistant to national security adviser Henry Kissinger and later his deputy, Haig played a central role in a wiretap scandal which was one of the abuses of power that brought down the presidency of Richard M. Nixon. Indeed, the wiretaps were an element of Article 2 of the articles of impeachmentadopted by the House Judiciary Committee on July 27, 1974.
...
When Haig made the formal request for the wiretaps, he told FBI assistant director William Sullivan that the request was “made on the highest authority” and that the matter was “so sensitive it demands handling on a need-to-know basis, with no record maintained.” That was not the way the FBI did business, especially when White House officials were issuing unprecedented requests to wiretap White House aides...
Sunday, April 4, 2010
How-To: Make Peeps sushi?
Some Peeps, some Rice Krispies treats, and some fruit roll-ups, and you've got delicious 'Peepshi.' (Okay, I think I'll be sick now...)
How to Make Peepshi = Peeps Sushi
Read more | Permalink | Comments |
Read more articles in Holiday projects |
Digg this!"
Wednesday, March 31, 2010
Thursday, March 11, 2010
Tuesday, March 9, 2010
loua1873-scalogram.jpg (2422×1932)
Friday, March 5, 2010
Petabytes on a budget: How to build cheap cloud storage | Backblaze Blog
Saturday, February 27, 2010
Hawaii News Now - LIVE - Hawaii News Now - KGMB and KHNL Home
Friday, February 26, 2010
PEP 278 -- Universal Newline Support
Wednesday, February 24, 2010
Stryde Hax: The Spy at Harriton High
Wednesday, February 17, 2010
taliban OR al-Qaeda "second in command" - Google Search
Tuesday, February 16, 2010
Women's 10k pursiut
Saturday, February 13, 2010
Clean Install Windows 7 With Upgrade Media
My XP installation got hosed at home. It would not boot and it was neither the MBR nor the partition's boot loader, so I was going to have to repair all the drivers. I took the opportunity to install Windows7 on a new RAID1 volume on 2 new 1TB Barracudas. I got the upgrade retail box which says "All editions of Windows XP and Vista qualify you to upgrade." It seemed safest to unplug the old drive during the install. But this let me unable to activate Windows7 even after I plugged in the old drive (to copy over the old files). It seems that Windows7 wants to see the old installation (not just the old install media, as in the past) while it is installing if you want to use an upgrade product key.
Here is the solution I used; very easy:
Workaround 3: Clean Install and Activate Windows 7 with MediaBootInstall Registry Hack
- After booting up, ensure that no Windows Updates pending task which requires a system reboot to finish installing.
Tip: Normally, an orange-colored shield icon will be displayed next to Shutdown button in the Start Menu Power Button or at notification tray area if a restart is required.
If reboot is required, restart the computer to allow any pending updates is installed.
- Run Registry Editor (RegEdit).
- Navigate to the following registry key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup\OOBE
- In the right pane, change the value data for MediaBootInstall from 1 to0.
Alternatively, just download and execute MediaBootInstall.reg to merge the value into registry.
- Open an elevated command prompt as administrator.
- Run the command below to reset Windows 7 activation status:
slmgr -rearm
- Reboot the computer.
- Run the Activate Windows utility (accessible from bottom section ofControl Panel -> System and Security -> System, or type Activate Windows into Start Search), type in the upgrade product key and activate Windows.