<commit_before>Interrupt Driven
================

* A new approach to building low-power apps on Arduino.
* The main state of the processor is a low-power mode.
* Devices wake the processor using interrupts, it services them and
  returns to sleep.

Example
-------

    #include "device.h"
    #include "external.h"
    #include "timer.h"
    
    Watchdog timer(5, 1);
    External ext0(2), ext1(3);
    Devices devices;
    
    void setup(void)
    {
    	Serial.begin(115200);
    
    	devices.add(timer);
    	devices.add(ext0);
    	devices.add(ext1);
    	devices.begin();
    
    	pinMode(13, OUTPUT);
    }
    
    void loop(void)
    {
    	switch (devices.select()) {
    	case 1:
    		Serial.println("tick");
    		break;
    	case 2:
    		digitalWrite(13, HIGH);
    		break;
    	case 3:
    		digitalWrite(13, LOW);
    		break;
    	default:
    		Serial.println("???");
    		break;
    	}
    
    	Serial.println("awake");
    	delay(100);
    }

Comments on this code:
* Three devices: a 
[watchdog timer](http://evothings.com/watchdog-timers-how-to-reduce-power-usage-in-your-arduino-projects/) 
  with id 1, interrupting every 5s and two
  [external interrupts](http://gonium.net/md/2006/12/20/handling-external-interrupts-with-arduino/) 
  on ports 2 and 3 (and ids 2 and 3).
* A device group ("devices") which manages them.
* Selecting on the device group sends the CPU to sleep if no device is ready.
* When a device is ready, it returns its id.
* Each external interrupt line is connected to ground by a push-buttons; when
  the one attached to pin #2 is pressed, the LED on pin #13 is lit, when the
  one on pin #3 is pressed, the LED is switched off again.

Credits
-------
* <NAME>'s excellent [interrupt page](http://gammon.com.au/interrupts)
<commit_msg>code example<commit_after>Interrupt Driven
================

* A new approach to building low-power apps on Arduino.
* The main state of the processor is a low-power mode.
* Devices wake the processor using interrupts, it services them and
  returns to sleep.

Example
-------

    #include "device.h"
    #include "external.h"
    #include "timer.h"
    
    Watchdog timer(5, 1);
    External ext0(2), ext1(3);
    Devices devices;
    
    void setup(void)
    {
    	Serial.begin(115200);
    
    	devices.add(timer);
    	devices.add(ext0);
    	devices.add(ext1);
    	devices.begin();
    
    	pinMode(13, OUTPUT);
    }
    
    void loop(void)
    {
    	switch (devices.select()) {
    	case 1:
    		Serial.println("tick");
    		break;
    	case 2:
    		digitalWrite(13, HIGH);
    		break;
    	case 3:
    		digitalWrite(13, LOW);
    		break;
    	default:
    		Serial.println("???");
    		break;
    	}
    
    	Serial.println("awake");
    	delay(100);
    }

Comments on this code:
* Three devices: a 
[watchdog timer](http://evothings.com/watchdog-timers-how-to-reduce-power-usage-in-your-arduino-projects/) 
  with id 1, interrupting every 5s and two
  [external interrupts](http://gonium.net/md/2006/12/20/handling-external-interrupts-with-arduino/) 
  on ports 2 and 3 (and ids 2 and 3).
* A device group ("devices") which manages them.
* Selecting on the device group sends the CPU to sleep if no device is ready.
* When a device is ready, it returns its id.
* Each external interrupt line is connected to ground by a push-button; when
  the one attached to pin #2 is pressed, the LED on pin #13 is lit, when
  that on pin #3 is pressed, the LED is switched off.

Credits
-------
* <NAME>'s excellent [interrupt page](http://gammon.com.au/interrupts)

{'fraction_non_alphanumeric': 0.1254550546065528, 'fraction_numerical': 0.024642957154858584, 'mean_word_length': 2.6374745417515273, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5022384', 'n_tokens_mistral': 1256, 'n_tokens_neox': 1185, 'n_words': 373}