Added arduino libs
هذا الالتزام موجود في:
@@ -0,0 +1,48 @@
|
||||
#include <EnableInterrupt.h>
|
||||
|
||||
#ifdef EI_ATTINY24
|
||||
#define OUTPUTPIN 10 // == B0
|
||||
#define INTERRUPTEDPIN 9 // == B1
|
||||
// Modify this at your leisure. But you must be aware of which port it's on (see below).
|
||||
#elif defined EI_ATTINY25
|
||||
#define OUTPUTPIN 0 // == B0
|
||||
#define INTERRUPTEDPIN 1 // == B1
|
||||
#else
|
||||
#error Dang, only ATtiny chips supported by this sketch.
|
||||
#endif
|
||||
|
||||
// Connect a LED to Pin 3. It might be different in different ATtiny micro controllers
|
||||
//const uint8_t outputBitMask = 0x01;
|
||||
const uint8_t outputBitMask = digital_pin_to_bit_mask_PGM[OUTPUTPIN];
|
||||
const uint8_t inputBitMask = digital_pin_to_bit_mask_PGM[INTERRUPTEDPIN];
|
||||
|
||||
volatile uint16_t endlessCounter=0; // The count will go back to 0 after hitting 65535.
|
||||
volatile uint8_t interruptState=0;
|
||||
|
||||
void interruptFunction() {
|
||||
if (interruptState) {
|
||||
interruptState=0;
|
||||
PORTB &= ~_BV(outputBitMask);
|
||||
} else {
|
||||
interruptState=1;
|
||||
PORTB |= 1 << outputBitMask;
|
||||
}
|
||||
}
|
||||
|
||||
// the setup routine runs once when you press reset:
|
||||
void setup() {
|
||||
DDRB |= outputBitMask; // OUTPUTPIN is set to output
|
||||
DDRB &= ~inputBitMask; // INPUTPIN is set to input
|
||||
PORTB |= inputBitMask; // Pull up the resistor
|
||||
MCUCR &= ~PUD; // ensure Pull Up Disable is off
|
||||
enableInterrupt(INTERRUPTEDPIN, interruptFunction, CHANGE);
|
||||
}
|
||||
|
||||
// the loop routine runs over and over again forever:
|
||||
void loop() {
|
||||
//digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
|
||||
//delay(1000); // wait for a second
|
||||
//digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
|
||||
//delay(1000); // wait for a second
|
||||
endlessCounter++; // give it something to do
|
||||
}
|
19
libraries/EnableInterrupt/examples/ATtinyBlink/Makefile
Normal file
19
libraries/EnableInterrupt/examples/ATtinyBlink/Makefile
Normal file
@@ -0,0 +1,19 @@
|
||||
## Arduino Makefile, see https://github.com/sudar/Arduino-Makefile (it's awesome!)
|
||||
ARDUINO_DIR = /home/schwager/bin/arduino-1.8.5
|
||||
|
||||
# ISP_PORT = /dev/ttyACM0
|
||||
#BOARD_TAG = attiny85at8
|
||||
BOARD_TAG = attiny44at8
|
||||
ALTERNATE_CORE = tiny
|
||||
BOARDS_TXT = ~/sketchbook/hardware/arduino-tiny/boards.txt
|
||||
ARDUINO_CORE_PATH = /home/schwager/sketchbook/hardware/arduino-tiny/cores/tiny
|
||||
# ARDUINO_VAR_PATH = ~/sketchbook/hardware/arduino-tiny/cores/tiny
|
||||
#AVR_TOOLS_DIR = /home/schwager/bin/arduino-1.8.4/hardware/tools/avr
|
||||
|
||||
CFLAGS_STD = -g
|
||||
CXXFLAGS_STD = -g
|
||||
|
||||
ISP_PROG = usbtiny
|
||||
F_CPU = 1000000L
|
||||
|
||||
include /usr/share/arduino/Arduino.mk
|
228
libraries/EnableInterrupt/examples/AllPins2560/AllPins2560.ino
Normal file
228
libraries/EnableInterrupt/examples/AllPins2560/AllPins2560.ino
Normal file
@@ -0,0 +1,228 @@
|
||||
// EnableInterrupt Simple example sketch
|
||||
// See the Wiki at http://code.google.com/p/arduino-pinchangeint/wiki for more information.
|
||||
|
||||
#include <EnableInterrupt.h>
|
||||
|
||||
volatile uint8_t externalInterruptCounter=0;
|
||||
volatile uint8_t anyInterruptCounter=0;
|
||||
|
||||
#ifdef ARDUINO_MEGA
|
||||
#define PINCOUNT(x) pin ##x ##Count
|
||||
|
||||
// Do not use any Serial.print() in interrupt subroutines. Serial.print() uses interrupts,
|
||||
// and by default interrupts are off in interrupt subroutines. Interrupt routines should also
|
||||
// be as fast as possible. Here we just increment counters.
|
||||
#define interruptFunction(x) \
|
||||
volatile uint8_t PINCOUNT(x); \
|
||||
void interruptFunction ##x () { \
|
||||
anyInterruptCounter++; \
|
||||
PINCOUNT(x)++; \
|
||||
}
|
||||
|
||||
#define interruptExFunction(x) \
|
||||
volatile uint8_t PINCOUNT(x); \
|
||||
void interruptExFunction ##x () { \
|
||||
externalInterruptCounter++; \
|
||||
anyInterruptCounter++; \
|
||||
PINCOUNT(x)++; \
|
||||
}
|
||||
|
||||
#define updateOn(x) \
|
||||
if (PINCOUNT(x) != 0) { \
|
||||
printIt((char *) #x, PINCOUNT(x)); \
|
||||
PINCOUNT(x)=0; \
|
||||
}
|
||||
|
||||
#define disablePCInterrupt(x) \
|
||||
disableInterrupt( x | PINCHANGEINTERRUPT)
|
||||
|
||||
#define setupInterrupt(x) \
|
||||
EI_printPSTR("Add pin: "); \
|
||||
EI_printPSTR(#x); \
|
||||
EI_printPSTR("\r\n"); \
|
||||
pinMode( x, INPUT_PULLUP); \
|
||||
enableInterrupt( x, interruptFunction##x, CHANGE)
|
||||
|
||||
#define setupExInterrupt(x) \
|
||||
EI_printPSTR("Add External pin: "); \
|
||||
EI_printPSTR(#x); \
|
||||
EI_printPSTR("\r\n"); \
|
||||
pinMode( x, INPUT_PULLUP); \
|
||||
enableInterrupt( x, interruptExFunction##x, CHANGE)
|
||||
|
||||
interruptFunction(SS);
|
||||
interruptFunction(SCK);
|
||||
interruptFunction(MOSI);
|
||||
interruptFunction(MISO);
|
||||
interruptFunction(10);
|
||||
interruptFunction(11);
|
||||
interruptFunction(12);
|
||||
interruptFunction(13);
|
||||
interruptFunction(14);
|
||||
interruptFunction(15);
|
||||
interruptFunction(A8);
|
||||
interruptFunction(A9);
|
||||
interruptFunction(A10);
|
||||
interruptFunction(A11);
|
||||
interruptFunction(A12);
|
||||
interruptFunction(A13);
|
||||
interruptFunction(A14);
|
||||
interruptFunction(A15);
|
||||
interruptFunction(70); // fake 70, trick to allow software interrupts on Port J. PJ2
|
||||
interruptFunction(71); // fake 71. PJ3
|
||||
interruptFunction(72); // fake 72. PJ4
|
||||
interruptFunction(73); // fake 73. PJ5
|
||||
interruptFunction(74); // fake 74. PJ6
|
||||
// External Interrupts
|
||||
interruptExFunction(21);
|
||||
interruptExFunction(20);
|
||||
interruptExFunction(19);
|
||||
interruptExFunction(18);
|
||||
interruptExFunction(2);
|
||||
interruptExFunction(3);
|
||||
interruptExFunction(75); // fake 75. PE6
|
||||
interruptExFunction(76); // fake 76. PE7
|
||||
#else
|
||||
#error This sketch supports 2560-based Arduinos only.
|
||||
#endif
|
||||
|
||||
void printIt(char *pinNumber, uint8_t count) {
|
||||
EI_printPSTR("Pin ");
|
||||
Serial.print(pinNumber);
|
||||
EI_printPSTR(" was interrupted: ");
|
||||
Serial.println(count, DEC);
|
||||
}
|
||||
|
||||
// Attach the interrupt in setup()
|
||||
// NOTE: PORTJ2-6 (aka, "Pin '70', '71', '72', '73', '74'" are turned on as OUTPUT.
|
||||
// These are not true pins on the Arduino Mega series!
|
||||
void setup() {
|
||||
//uint8_t pind, pink;
|
||||
Serial.begin(115200);
|
||||
EI_printPSTR("---------------------------------------");
|
||||
// PINS 0 and 1 NOT USED BECAUSE OF Serial.print()
|
||||
setupInterrupt(SS);
|
||||
setupInterrupt(SCK);
|
||||
setupInterrupt(MOSI);
|
||||
setupInterrupt(MISO);
|
||||
setupInterrupt(10);
|
||||
setupInterrupt(11);
|
||||
setupInterrupt(12);
|
||||
setupInterrupt(13);
|
||||
setupInterrupt(14);
|
||||
setupInterrupt(15);
|
||||
setupInterrupt(A8);
|
||||
setupInterrupt(A9);
|
||||
setupInterrupt(A10);
|
||||
setupInterrupt(A11);
|
||||
setupInterrupt(A12);
|
||||
setupInterrupt(A13);
|
||||
setupInterrupt(A14);
|
||||
setupInterrupt(A15);
|
||||
////
|
||||
DDRJ |=0b01111100; // Non-Arduino Port J pins all become output.
|
||||
PORTJ|=0b01111100; // Turn them all high.
|
||||
enableInterrupt(70, interruptFunction70, CHANGE);
|
||||
enableInterrupt(71, interruptFunction71, CHANGE);
|
||||
enableInterrupt(72, interruptFunction72, CHANGE);
|
||||
enableInterrupt(73, interruptFunction73, CHANGE);
|
||||
enableInterrupt(74, interruptFunction74, CHANGE);
|
||||
// External Interrupts
|
||||
setupExInterrupt(21);
|
||||
setupExInterrupt(20);
|
||||
setupExInterrupt(19);
|
||||
setupExInterrupt(18);
|
||||
setupExInterrupt(2);
|
||||
setupExInterrupt(3);
|
||||
////
|
||||
DDRE |=0b11000000; // Non-Arduino Port E pins all become output.
|
||||
PORTE|=0b11000000; // Turn them all high.
|
||||
enableInterrupt(75, interruptExFunction75, CHANGE);
|
||||
enableInterrupt(76, interruptExFunction76, CHANGE);
|
||||
}
|
||||
|
||||
uint8_t otherToggle=1;
|
||||
uint8_t enabledToggle=1;
|
||||
uint8_t disableCounter=0;
|
||||
// In the loop, we just check to see where the interrupt count is at. The value gets updated by the
|
||||
// interrupt routine.
|
||||
void loop() {
|
||||
uint8_t jbits =0b01111110; // PJ2
|
||||
uint8_t njbits=0b00000001; // PJ2
|
||||
uint8_t ebits =0b11000000; // PE6/7
|
||||
uint8_t nebits=0b00111111; // PE6/7
|
||||
|
||||
EI_printPSTR("------\r\n");
|
||||
delay(1000); // Every second,
|
||||
if (disableCounter & 0x08) {
|
||||
EI_printPSTR("Toggle 20, 71, 75, A8, 15, MISO...");
|
||||
delay(1000);
|
||||
if (enabledToggle==1) {
|
||||
EI_printPSTR("---OFF---");
|
||||
disableInterrupt(20);
|
||||
disableInterrupt(71);
|
||||
disableInterrupt(75);
|
||||
disableInterrupt(15);
|
||||
disableInterrupt(A8);
|
||||
disableInterrupt(MISO);
|
||||
enabledToggle=0;
|
||||
}
|
||||
else {
|
||||
EI_printPSTR("***ON***");
|
||||
setupExInterrupt(20);
|
||||
setupInterrupt(71);
|
||||
setupExInterrupt(75);
|
||||
setupInterrupt(15);
|
||||
setupInterrupt(A8);
|
||||
setupInterrupt(MISO);
|
||||
enabledToggle=1;
|
||||
}
|
||||
disableCounter=0;
|
||||
}
|
||||
PORTE &= nebits;
|
||||
PORTJ &= njbits;
|
||||
// *out &= njbits;
|
||||
delay(1);
|
||||
PORTE |= ebits;
|
||||
PORTJ |= jbits;
|
||||
// *out |= jbits;
|
||||
delay(1);
|
||||
updateOn(SS);
|
||||
updateOn(SCK);
|
||||
updateOn(MOSI)
|
||||
updateOn(MISO);
|
||||
updateOn(10);
|
||||
updateOn(11);
|
||||
updateOn(12);
|
||||
updateOn(13);
|
||||
updateOn(14);
|
||||
updateOn(15);
|
||||
updateOn(A8);
|
||||
updateOn(A9);
|
||||
updateOn(A10);
|
||||
updateOn(A11);
|
||||
updateOn(A12);
|
||||
updateOn(A13);
|
||||
updateOn(A14);
|
||||
updateOn(A15);
|
||||
// External Interrupts
|
||||
updateOn(2);
|
||||
updateOn(3);
|
||||
updateOn(18);
|
||||
updateOn(19);
|
||||
updateOn(20);
|
||||
updateOn(21);
|
||||
// Fake Arduino Pins
|
||||
updateOn(70);
|
||||
updateOn(71);
|
||||
updateOn(72);
|
||||
updateOn(73);
|
||||
updateOn(74);
|
||||
// External Interrupts
|
||||
updateOn(75);
|
||||
updateOn(76);
|
||||
if (externalInterruptCounter > 0) { EI_printPSTR(" ext: "); Serial.println(externalInterruptCounter); }; \
|
||||
externalInterruptCounter=0;
|
||||
disableCounter++;
|
||||
}
|
||||
|
12
libraries/EnableInterrupt/examples/AllPins2560/Makefile
Normal file
12
libraries/EnableInterrupt/examples/AllPins2560/Makefile
Normal file
@@ -0,0 +1,12 @@
|
||||
# Arduino Makefile, see https://github.com/sudar/Arduino-Makefile (it's awesome!)
|
||||
BOARD_TAG = mega
|
||||
BOARD_SUB = atmega2560
|
||||
ARDUINO_PORT = /dev/ttyACM0
|
||||
ARDUINO_LIBS =
|
||||
AVR_TOOLS_DIR = /usr
|
||||
|
||||
CFLAGS_STD = -g
|
||||
CXXFLAGS_STD = -g
|
||||
|
||||
include /usr/share/arduino/Arduino.mk
|
||||
|
200
libraries/EnableInterrupt/examples/AllPins328/AllPins328.ino
Normal file
200
libraries/EnableInterrupt/examples/AllPins328/AllPins328.ino
Normal file
@@ -0,0 +1,200 @@
|
||||
// EnableInterrupt Simple example sketch
|
||||
// See the Wiki at http://code.google.com/p/arduino-pinchangeint/wiki for more information.
|
||||
|
||||
// This example demonstrates the use of the EnableInterrupt library on all pins.
|
||||
// The library has only been tested on an Arduino Duemilanove and Mega ADK.
|
||||
|
||||
#include <EnableInterrupt.h>
|
||||
|
||||
volatile uint8_t externalInterruptCounter=0;
|
||||
volatile uint8_t anyInterruptCounter=0;
|
||||
|
||||
#ifdef ARDUINO_328
|
||||
#define PINCOUNT(x) pin ##x ##Count
|
||||
|
||||
// Do not use any Serial.print() in interrupt subroutines. Serial.print() uses interrupts,
|
||||
// and by default interrupts are off in interrupt subroutines. Interrupt routines should also
|
||||
// be as fast as possible. Here we just increment counters.
|
||||
#define interruptFunction(x) \
|
||||
volatile uint8_t PINCOUNT(x); \
|
||||
void interruptFunction ##x () { \
|
||||
anyInterruptCounter++; \
|
||||
PINCOUNT(x)++; \
|
||||
}
|
||||
|
||||
#define interruptExFunction(x) \
|
||||
volatile uint8_t PINCOUNT(x); \
|
||||
void interruptExFunction ##x () { \
|
||||
externalInterruptCounter++; \
|
||||
anyInterruptCounter++; \
|
||||
PINCOUNT(x)++; \
|
||||
}
|
||||
|
||||
#define updateOn(x) \
|
||||
if (PINCOUNT(x) != 0) { \
|
||||
printIt((char *) #x, PINCOUNT(x)); \
|
||||
if (externalInterruptCounter > 0) { \
|
||||
EI_printPSTR(" ext: "); Serial.println(externalInterruptCounter); \
|
||||
externalInterruptCounter=0; \
|
||||
}; \
|
||||
PINCOUNT(x)=0; \
|
||||
}
|
||||
|
||||
#define disablePCInterrupt(x) \
|
||||
disableInterrupt( x | PINCHANGEINTERRUPT)
|
||||
|
||||
#define setupPCInterrupt(x) \
|
||||
EI_printPSTR("Add PinChange pin: "); \
|
||||
EI_printPSTR(#x); \
|
||||
EI_printPSTR("\r\n"); \
|
||||
pinMode( x, INPUT_PULLUP); \
|
||||
enableInterrupt( x | PINCHANGEINTERRUPT, interruptFunction##x, CHANGE)
|
||||
|
||||
#define setupInterrupt(x) \
|
||||
EI_printPSTR("Add pin: "); \
|
||||
EI_printPSTR(#x); \
|
||||
EI_printPSTR("\r\n"); \
|
||||
pinMode( x, INPUT_PULLUP); \
|
||||
enableInterrupt( x, interruptFunction##x, CHANGE)
|
||||
|
||||
#define setupExInterrupt(x) \
|
||||
EI_printPSTR("Add External pin: "); \
|
||||
EI_printPSTR(#x); \
|
||||
EI_printPSTR("\r\n"); \
|
||||
pinMode( x, INPUT_PULLUP); \
|
||||
enableInterrupt( x , interruptExFunction##x, CHANGE)
|
||||
|
||||
interruptFunction(2);
|
||||
interruptExFunction(3);
|
||||
interruptFunction(4);
|
||||
interruptFunction(5);
|
||||
interruptFunction(6);
|
||||
interruptFunction(7);
|
||||
interruptFunction(8);
|
||||
interruptFunction(9);
|
||||
interruptFunction(10);
|
||||
interruptFunction(11);
|
||||
interruptFunction(12);
|
||||
interruptFunction(13);
|
||||
interruptFunction(A0);
|
||||
interruptFunction(A1);
|
||||
interruptFunction(A2);
|
||||
interruptFunction(A3);
|
||||
interruptFunction(A4);
|
||||
interruptFunction(A5);
|
||||
|
||||
volatile uint8_t otherCounter=0;
|
||||
void otherInterrupt3Function(void) { // Must appear after interruptFunction(3)
|
||||
pin3Count++;
|
||||
otherCounter++;
|
||||
}
|
||||
#else
|
||||
#error This sketch supports 328-based Arduinos only.
|
||||
#endif
|
||||
|
||||
void printIt(char *pinNumber, uint8_t count) {
|
||||
EI_printPSTR(" Pin ");
|
||||
Serial.print(pinNumber);
|
||||
EI_printPSTR(" was interrupted: ");
|
||||
Serial.println(count, DEC);
|
||||
}
|
||||
|
||||
// Attach the interrupt in setup()
|
||||
// NOTE: PORTJ2-6 (aka, "Pin '70', '71', '72', '73', '74'" are turned on as OUTPUT.
|
||||
// These are not true pins on the Arduino Mega series!
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
EI_printPSTR("--- START ------------------------------------\r\n");
|
||||
#ifdef DEBUG
|
||||
pinMode(PINSIGNAL, OUTPUT);
|
||||
#endif
|
||||
// PINS 0 and 1 NOT USED BECAUSE OF Serial.print()
|
||||
setupPCInterrupt(2); // by default, will be External Interrupt
|
||||
setupExInterrupt(3);
|
||||
setupInterrupt(4);
|
||||
setupInterrupt(5);
|
||||
setupInterrupt(6);
|
||||
setupInterrupt(7);
|
||||
setupInterrupt(8);
|
||||
setupInterrupt(9);
|
||||
setupInterrupt(10);
|
||||
setupInterrupt(11);
|
||||
setupInterrupt(12);
|
||||
#ifndef DEBUG
|
||||
// NOTE: Because the Arduino Duemilanove has an LED to ground and a 1k resistor in series with
|
||||
// it to the pin, Voltage at the pin should be hovering between 1-3 volts. 'nearly' ground. So
|
||||
// a wire to ground will not trip an interrupt, even though we have INPUT_PULLUP. A wire to PWR
|
||||
// will trigger an interrupt. The Uno has a op-amp buffer/driver to the LED, so will not have
|
||||
// this problem; it will behave like the other pins.
|
||||
setupInterrupt(13);
|
||||
#endif
|
||||
setupInterrupt(A0);
|
||||
setupInterrupt(A1);
|
||||
setupInterrupt(A2);
|
||||
setupInterrupt(A3);
|
||||
setupInterrupt(A4);
|
||||
setupInterrupt(A5);
|
||||
}
|
||||
|
||||
uint8_t otherToggle=1;
|
||||
uint8_t enabledToggle=1;
|
||||
uint8_t disableCounter=0;
|
||||
// In the loop, we just check to see where the interrupt count is at. The value gets updated by
|
||||
// the interrupt routine.
|
||||
void loop() {
|
||||
EI_printPSTR("------\r\n");
|
||||
delay(1000); // Perform the loop every second.
|
||||
if (disableCounter & 0x08) {
|
||||
EI_printPSTR("Toggle 2, 3, 8, A0...");
|
||||
delay(1000);
|
||||
if (enabledToggle==1) {
|
||||
disablePCInterrupt(2);
|
||||
disableInterrupt(3);
|
||||
disableInterrupt(8);
|
||||
disableInterrupt(A0);
|
||||
enabledToggle=0;
|
||||
}
|
||||
else {
|
||||
if (otherToggle == 1) {
|
||||
EI_printPSTR("3 is now a Pin Change Interrupt.\r\n");
|
||||
enableInterrupt(3, otherInterrupt3Function, CHANGE); // make sure we can switch functions.
|
||||
otherToggle=0;
|
||||
} else {
|
||||
EI_printPSTR("3 is now an External Interrupt.\r\n");
|
||||
otherToggle=1;
|
||||
setupExInterrupt(3);
|
||||
}
|
||||
setupPCInterrupt(2);
|
||||
setupInterrupt(8);
|
||||
setupInterrupt(A0);
|
||||
enabledToggle=1;
|
||||
}
|
||||
disableCounter=0;
|
||||
}
|
||||
updateOn(2);
|
||||
updateOn(3);
|
||||
updateOn(4);
|
||||
updateOn(5);
|
||||
updateOn(6);
|
||||
updateOn(7);
|
||||
updateOn(8);
|
||||
updateOn(9);
|
||||
updateOn(10);
|
||||
updateOn(11);
|
||||
updateOn(12);
|
||||
updateOn(13);
|
||||
updateOn(A0);
|
||||
updateOn(A1);
|
||||
updateOn(A2);
|
||||
updateOn(A3);
|
||||
updateOn(A4);
|
||||
updateOn(A5);
|
||||
EI_printPSTR("Consolidated interrupt count: "); Serial.println(anyInterruptCounter);
|
||||
if (otherCounter) {
|
||||
printIt((char *) "OTHER3", otherCounter);
|
||||
otherCounter=0;
|
||||
}
|
||||
externalInterruptCounter=0;
|
||||
disableCounter++;
|
||||
}
|
||||
|
12
libraries/EnableInterrupt/examples/AllPins328/Makefile
Normal file
12
libraries/EnableInterrupt/examples/AllPins328/Makefile
Normal file
@@ -0,0 +1,12 @@
|
||||
# Arduino Makefile, see https://github.com/sudar/Arduino-Makefile (it's awesome!)
|
||||
BOARD_TAG = pro
|
||||
BOARD_SUB = 16MHzatmega328
|
||||
ARDUINO_PORT = /dev/ttyUSB0
|
||||
ARDUINO_LIBS =
|
||||
AVR_TOOLS_DIR = /usr
|
||||
|
||||
CFLAGS_STD = -g
|
||||
CXXFLAGS_STD = -g
|
||||
|
||||
include /usr/share/arduino/Arduino.mk
|
||||
|
42
libraries/EnableInterrupt/examples/Debounce/Debounce.ino
Normal file
42
libraries/EnableInterrupt/examples/Debounce/Debounce.ino
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* This example shows how to combine the EnableInterrupt
|
||||
* library with some simple debouncing code for reading
|
||||
* button presses consistently.
|
||||
*
|
||||
* The interrupt is attached to digital input 5 and the
|
||||
* service routine just toggles the onboard LED status.
|
||||
*
|
||||
* Tested on: ATmega328P
|
||||
*
|
||||
* Example by Lorenzo Cafaro <lorenzo@ibisco.net>
|
||||
*
|
||||
*/
|
||||
|
||||
#include <EnableInterrupt.h>
|
||||
|
||||
#define BUTTON_PIN 5
|
||||
#define DEBOUNCE_DELAY 100 // in ms
|
||||
|
||||
uint32_t last_interrupt_time = 0;
|
||||
uint8_t led_status = 0;
|
||||
|
||||
void setup() {
|
||||
pinMode(BUTTON_PIN, INPUT);
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
enableInterrupt(BUTTON_PIN, isr_handler, RISING);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// zZz
|
||||
}
|
||||
|
||||
void isr_handler() {
|
||||
uint32_t interrupt_time = millis();
|
||||
|
||||
if (interrupt_time - last_interrupt_time > DEBOUNCE_DELAY) {
|
||||
led_status = !led_status;
|
||||
digitalWrite(LED_BUILTIN, led_status);
|
||||
}
|
||||
|
||||
last_interrupt_time = interrupt_time;
|
||||
}
|
64
libraries/EnableInterrupt/examples/HiSpeed/HiSpeed.ino
Normal file
64
libraries/EnableInterrupt/examples/HiSpeed/HiSpeed.ino
Normal file
@@ -0,0 +1,64 @@
|
||||
// EnableInterrupt HiSpeed example sketch
|
||||
// See https://github.com/GreyGnome/EnableInterrupt and the README.md for more information.
|
||||
|
||||
// This example demonstrates the use of the EnableInterrupt library on a single pin of your choice.
|
||||
// It uses the "HiSpeed" mode of the library.
|
||||
// This has only been tested on an Arduino Duemilanove and Mega ADK.
|
||||
// It is designed to work with the Arduino Duemilanove/Uno, Arduino Mega2560/ADK, the Arduino
|
||||
// Leonardo, and the Arduino Due. Please let me know how you fare on the Leonardo or Due.
|
||||
|
||||
// To use:
|
||||
|
||||
// 1. You must be using a fairly recent version of the Arduino IDE software on your PC/Mac,
|
||||
// that is, version 1.0.1 or later. Check Help->About Arduino in the IDE.
|
||||
|
||||
// 2. Wire a simple switch to an Analog or Digital pin (pin 8 in the example below)
|
||||
// that supports interrupts. See https://github.com/GreyGnome/EnableInterrupt/wiki/Usage#Summary
|
||||
// Attach the other end to a GND pin. A "single pole single throw momentary contact normally
|
||||
// open" // pushbutton switch is best for the most interrupting fun.
|
||||
// See https://www.sparkfun.com/products/97 and https://octopart.com/b3f-1000-omron-3117
|
||||
|
||||
// 3. When pressed, the switch will connect the pin to ground ("low", or "0") voltage, and interrupt the
|
||||
// processor. See http://arduino.cc/en/Tutorial/DigitalPins
|
||||
|
||||
// 4. The interrupt is serviced immediately, and the ISR (Interrupt SubRoutine) sets the value of a global
|
||||
// variable. Open Tools->Serial Monitor in the IDE to see the results of your interrupts.
|
||||
|
||||
// 5. Peruse the Examples directory for more elaborate examples.
|
||||
|
||||
// 6. Create your own sketch using the EnableInterrupt library!
|
||||
|
||||
// Refer to
|
||||
// https://github.com/GreyGnome/EnableInterrupt/wiki/Usage#Summary
|
||||
|
||||
#define NEEDFORSPEED
|
||||
|
||||
#define INTERRUPT_FLAG_PIN8 myvariable_pin8 // NOTICE: NO semicolon!!!
|
||||
|
||||
#include <EnableInterrupt.h>
|
||||
|
||||
// Attach the interrupt in setup()
|
||||
void setup() {
|
||||
//uint8_t pind, pink;
|
||||
Serial.begin(115200);
|
||||
EI_printPSTR("---------------------------------------\r\n");
|
||||
pinMode(8, INPUT_PULLUP); // Configure the pin as an input, and turn on the pullup resistor.
|
||||
// See http://arduino.cc/en/Tutorial/DigitalPins
|
||||
enableInterruptFast(8, CHANGE);
|
||||
}
|
||||
|
||||
// In the loop, we just check to see where the interrupt count is at. The value gets updated by the
|
||||
// interrupt routine.
|
||||
void loop() {
|
||||
EI_printPSTR("---------------------------------------\r\n");
|
||||
delay(1000); // Every second,
|
||||
if (myvariable_pin8) {
|
||||
EI_printPSTR("Pin 8 was interrupted: ");
|
||||
Serial.print(myvariable_pin8, DEC); // print the interrupt count.
|
||||
EI_printPSTR(" times so far.\r\n");
|
||||
myvariable_pin8=0;
|
||||
}
|
||||
else {
|
||||
EI_printPSTR("No interrupts.\r\n");
|
||||
}
|
||||
}
|
14
libraries/EnableInterrupt/examples/HiSpeed/Makefile
Normal file
14
libraries/EnableInterrupt/examples/HiSpeed/Makefile
Normal file
@@ -0,0 +1,14 @@
|
||||
# Arduino Makefile, see https://github.com/sudar/Arduino-Makefile (it's awesome!)
|
||||
BOARD_TAG = pro
|
||||
BOARD_SUB = 16MHzatmega328
|
||||
ARDUINO_PORT = /dev/ttyUSB0
|
||||
#BOARD_TAG = 2560
|
||||
#ARDUINO_PORT = /dev/ttyACM0
|
||||
ARDUINO_LIBS =
|
||||
AVR_TOOLS_DIR = /usr
|
||||
|
||||
CFLAGS_STD = -g
|
||||
CXXFLAGS_STD = -g
|
||||
|
||||
include /usr/share/arduino/Arduino.mk
|
||||
|
4
libraries/EnableInterrupt/examples/HiSpeed/README
Normal file
4
libraries/EnableInterrupt/examples/HiSpeed/README
Normal file
@@ -0,0 +1,4 @@
|
||||
Note: This code has not been tested! Caveat Programmer. I will do it asap.
|
||||
(I have tested the HiSpeed code using the HiSpeedTest sketch, so I'm confident
|
||||
the library is working properly. Also this sketch compiles.).
|
||||
-GreyGnome
|
@@ -0,0 +1,205 @@
|
||||
// EnableInterrupt example sketch: Hi Speed Interrupts, ATmega2560/compatible, all pins
|
||||
// See the Wiki at https://github.com/GreyGnome/EnableInterrupt/wiki
|
||||
|
||||
#define NEEDFORSPEED
|
||||
|
||||
#define INTERRUPT_FLAG_PINSS iflag_pinSS
|
||||
#define INTERRUPT_FLAG_PINSCK iflag_pinSCK
|
||||
#define INTERRUPT_FLAG_PINMOSI iflag_pinMOSI
|
||||
#define INTERRUPT_FLAG_PINMISO iflag_pinMISO
|
||||
#define INTERRUPT_FLAG_PIN10 iflag_pin10
|
||||
#define INTERRUPT_FLAG_PIN11 iflag_pin11
|
||||
#define INTERRUPT_FLAG_PIN12 iflag_pin12
|
||||
#define INTERRUPT_FLAG_PIN13 iflag_pin13
|
||||
#define INTERRUPT_FLAG_PIN14 iflag_pin14
|
||||
#define INTERRUPT_FLAG_PIN15 iflag_pin15
|
||||
#define INTERRUPT_FLAG_PINA8 iflag_pinA8
|
||||
#define INTERRUPT_FLAG_PINA9 iflag_pinA9
|
||||
#define INTERRUPT_FLAG_PINA10 iflag_pinA10
|
||||
#define INTERRUPT_FLAG_PINA11 iflag_pinA11
|
||||
#define INTERRUPT_FLAG_PINA12 iflag_pinA12
|
||||
#define INTERRUPT_FLAG_PINA13 iflag_pinA13
|
||||
#define INTERRUPT_FLAG_PINA14 iflag_pinA14
|
||||
#define INTERRUPT_FLAG_PINA15 iflag_pinA15
|
||||
#define INTERRUPT_FLAG_PIN70 iflag_pin70
|
||||
#define INTERRUPT_FLAG_PIN71 iflag_pin71
|
||||
#define INTERRUPT_FLAG_PIN72 iflag_pin72
|
||||
#define INTERRUPT_FLAG_PIN73 iflag_pin73
|
||||
#define INTERRUPT_FLAG_PIN74 iflag_pin74
|
||||
#define INTERRUPT_FLAG_PIN21 iflag_pin21
|
||||
#define INTERRUPT_FLAG_PIN20 iflag_pin20
|
||||
#define INTERRUPT_FLAG_PIN19 iflag_pin19
|
||||
#define INTERRUPT_FLAG_PIN18 iflag_pin18
|
||||
#define INTERRUPT_FLAG_PIN2 iflag_pin2
|
||||
#define INTERRUPT_FLAG_PIN3 iflag_pin3
|
||||
#define INTERRUPT_FLAG_PIN75 iflag_pin75
|
||||
#define INTERRUPT_FLAG_PIN76 iflag_pin76
|
||||
|
||||
#define INTERRUPT_FLAG_PIN18 iflag_pin18
|
||||
#define INTERRUPT_FLAG_PIN19 iflag_pin19
|
||||
#define INTERRUPT_FLAG_PIN20 iflag_pin20
|
||||
#define INTERRUPT_FLAG_PIN21 iflag_pin21
|
||||
|
||||
#include <EnableInterrupt.h>
|
||||
|
||||
volatile uint8_t externalInterruptCounter=0;
|
||||
volatile uint8_t anyInterruptCounter=0;
|
||||
|
||||
#ifdef ARDUINO_MEGA
|
||||
#define PINCOUNT(x) iflag_pin ##x
|
||||
|
||||
#define setupInterrupt(x) \
|
||||
EI_printPSTR("Add pin: "); \
|
||||
EI_printPSTR(#x); \
|
||||
EI_printPSTR("\r\n"); \
|
||||
pinMode( x, INPUT_PULLUP); \
|
||||
enableInterruptFast(x, CHANGE)
|
||||
|
||||
#define updateOn(x) \
|
||||
if (PINCOUNT(x) != 0) { \
|
||||
printIt((char *) #x, PINCOUNT(x)); \
|
||||
PINCOUNT(x)=0; \
|
||||
}
|
||||
|
||||
#else
|
||||
#error This sketch supports 2560-based Arduinos only.
|
||||
#endif
|
||||
|
||||
void printIt(char *pinNumber, uint8_t count) {
|
||||
EI_printPSTR("Pin ");
|
||||
Serial.print(pinNumber);
|
||||
EI_printPSTR(" was interrupted: ");
|
||||
Serial.println(count, DEC);
|
||||
}
|
||||
|
||||
// Attach the interrupt in setup()
|
||||
// NOTE: PORTJ2-6 (aka, "Pin '70', '71', '72', '73', '74'" are turned on as OUTPUT.
|
||||
// These are not true pins on the Arduino Mega series!
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
EI_printPSTR("---------------------------------------");
|
||||
// PINS 0 and 1 NOT USED BECAUSE OF Serial.print()
|
||||
setupInterrupt(SS);
|
||||
setupInterrupt(SCK);
|
||||
setupInterrupt(MOSI);
|
||||
setupInterrupt(MISO);
|
||||
setupInterrupt(10);
|
||||
setupInterrupt(11);
|
||||
setupInterrupt(12);
|
||||
setupInterrupt(13);
|
||||
setupInterrupt(14);
|
||||
setupInterrupt(15);
|
||||
setupInterrupt(A8);
|
||||
setupInterrupt(A9);
|
||||
setupInterrupt(A10);
|
||||
setupInterrupt(A11);
|
||||
setupInterrupt(A12);
|
||||
setupInterrupt(A13);
|
||||
setupInterrupt(A14);
|
||||
setupInterrupt(A15);
|
||||
////
|
||||
DDRJ |=0b01111100; // Non-Arduino Port J pins all become output.
|
||||
PORTJ|=0b01111100; // Turn them all high.
|
||||
enableInterruptFast(70, CHANGE);
|
||||
enableInterruptFast(71, CHANGE);
|
||||
enableInterruptFast(72, CHANGE);
|
||||
enableInterruptFast(73, CHANGE);
|
||||
enableInterruptFast(74, CHANGE);
|
||||
// External Interrupts
|
||||
setupInterrupt(21);
|
||||
setupInterrupt(20);
|
||||
setupInterrupt(19);
|
||||
setupInterrupt(18);
|
||||
setupInterrupt(2);
|
||||
setupInterrupt(3);
|
||||
////
|
||||
DDRE |=0b11000000; // Non-Arduino Port E pins all become output.
|
||||
PORTE|=0b11000000; // Turn them all high.
|
||||
enableInterruptFast(75, CHANGE);
|
||||
enableInterruptFast(76, CHANGE);
|
||||
}
|
||||
|
||||
uint8_t otherToggle=1;
|
||||
uint8_t enabledToggle=1;
|
||||
uint8_t disableCounter=0;
|
||||
// In the loop, we just check to see where the interrupt count is at. The value gets updated by the
|
||||
// interrupt routine.
|
||||
void loop() {
|
||||
uint8_t jbits =0b01111110; // PJ2
|
||||
uint8_t njbits=0b00000001; // PJ2
|
||||
uint8_t ebits =0b11000000; // PE6/7
|
||||
uint8_t nebits=0b00111111; // PE6/7
|
||||
|
||||
EI_printPSTR("------\r\n");
|
||||
delay(1000); // Every second,
|
||||
if (disableCounter & 0x08) {
|
||||
EI_printPSTR("Toggle 20, 71, 75, A8, 15, MISO...");
|
||||
delay(1000);
|
||||
if (enabledToggle==1) {
|
||||
EI_printPSTR("---OFF---");
|
||||
disableInterrupt(20);
|
||||
disableInterrupt(71);
|
||||
disableInterrupt(75);
|
||||
disableInterrupt(15);
|
||||
disableInterrupt(A8);
|
||||
disableInterrupt(MISO);
|
||||
enabledToggle=0;
|
||||
}
|
||||
else {
|
||||
EI_printPSTR("***ON***");
|
||||
setupInterrupt(20);
|
||||
enableInterruptFast(71, CHANGE);
|
||||
enableInterruptFast(75, CHANGE);
|
||||
setupInterrupt(15);
|
||||
setupInterrupt(A8);
|
||||
setupInterrupt(MISO);
|
||||
enabledToggle=1;
|
||||
}
|
||||
disableCounter=0;
|
||||
}
|
||||
PORTE &= nebits;
|
||||
PORTJ &= njbits;
|
||||
// *out &= njbits;
|
||||
delay(1);
|
||||
PORTE |= ebits;
|
||||
PORTJ |= jbits;
|
||||
// *out |= jbits;
|
||||
delay(1);
|
||||
updateOn(SS);
|
||||
updateOn(SCK);
|
||||
updateOn(MOSI)
|
||||
updateOn(MISO);
|
||||
updateOn(10);
|
||||
updateOn(11);
|
||||
updateOn(12);
|
||||
updateOn(13);
|
||||
updateOn(14);
|
||||
updateOn(15);
|
||||
updateOn(A8);
|
||||
updateOn(A9);
|
||||
updateOn(A10);
|
||||
updateOn(A11);
|
||||
updateOn(A12);
|
||||
updateOn(A13);
|
||||
updateOn(A14);
|
||||
updateOn(A15);
|
||||
// External Interrupts
|
||||
updateOn(2);
|
||||
updateOn(3);
|
||||
updateOn(18);
|
||||
updateOn(19);
|
||||
updateOn(20);
|
||||
updateOn(21);
|
||||
// Fake Arduino Pins
|
||||
updateOn(70);
|
||||
updateOn(71);
|
||||
updateOn(72);
|
||||
updateOn(73);
|
||||
updateOn(74);
|
||||
// External Interrupts
|
||||
updateOn(75);
|
||||
updateOn(76);
|
||||
if (externalInterruptCounter > 0) { EI_printPSTR(" ext: "); Serial.println(externalInterruptCounter); }; \
|
||||
externalInterruptCounter=0;
|
||||
disableCounter++;
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
# Arduino Makefile, see https://github.com/sudar/Arduino-Makefile (it's awesome!)
|
||||
BOARD_TAG = mega
|
||||
BOARD_SUB = atmega2560
|
||||
|
||||
ARDUINO_PORT = /dev/ttyACM0
|
||||
ARDUINO_LIBS =
|
||||
AVR_TOOLS_DIR = /usr
|
||||
|
||||
CFLAGS_STD = -g
|
||||
CXXFLAGS_STD = -g
|
||||
|
||||
include /usr/share/arduino/Arduino.mk
|
||||
|
@@ -0,0 +1,177 @@
|
||||
// EnableInterrupt Simple example sketch
|
||||
// See the Wiki at http://code.google.com/p/arduino-pinchangeint/wiki for more information.
|
||||
|
||||
// This example demonstrates the use of the EnableInterrupt library on all pins.
|
||||
// The library has only been tested on an Arduino Duemilanove and Mega ADK.
|
||||
|
||||
#define NEEDFORSPEED
|
||||
#define INTERRUPT_FLAG_PIN2 iflag_pin2
|
||||
#define INTERRUPT_FLAG_PIN3 iflag_pin3
|
||||
#define INTERRUPT_FLAG_PIN4 iflag_pin4
|
||||
#define INTERRUPT_FLAG_PIN5 iflag_pin5
|
||||
#define INTERRUPT_FLAG_PIN6 iflag_pin6
|
||||
#define INTERRUPT_FLAG_PIN7 iflag_pin7
|
||||
#define INTERRUPT_FLAG_PIN8 iflag_pin8
|
||||
#define INTERRUPT_FLAG_PIN9 iflag_pin9
|
||||
#define INTERRUPT_FLAG_PIN10 iflag_pin10
|
||||
#define INTERRUPT_FLAG_PIN11 iflag_pin11
|
||||
#define INTERRUPT_FLAG_PIN12 iflag_pin12
|
||||
#define INTERRUPT_FLAG_PIN13 iflag_pin13
|
||||
#define INTERRUPT_FLAG_PINA0 iflag_pinA0
|
||||
#define INTERRUPT_FLAG_PINA1 iflag_pinA1
|
||||
#define INTERRUPT_FLAG_PINA2 iflag_pinA2
|
||||
#define INTERRUPT_FLAG_PINA3 iflag_pinA3
|
||||
#define INTERRUPT_FLAG_PINA4 iflag_pinA4
|
||||
#define INTERRUPT_FLAG_PINA5 iflag_pinA5
|
||||
|
||||
#include <EnableInterrupt.h>
|
||||
|
||||
volatile uint8_t anyInterruptCounter=0;
|
||||
|
||||
#ifdef ARDUINO_328
|
||||
#define PINCOUNT(x) iflag_pin ##x
|
||||
|
||||
#define updateOn(x) \
|
||||
if (PINCOUNT(x) != 0) { \
|
||||
printIt((char *) #x, PINCOUNT(x)); \
|
||||
PINCOUNT(x)=0; \
|
||||
}
|
||||
|
||||
#define disablePCInterrupt(x) \
|
||||
disableInterrupt( x | PINCHANGEINTERRUPT)
|
||||
|
||||
#define setupPCInterrupt(x) \
|
||||
EI_printPSTR("Add PinChange pin: "); \
|
||||
EI_printPSTR(#x); \
|
||||
EI_printPSTR("\r\n"); \
|
||||
pinMode( x, INPUT_PULLUP); \
|
||||
enableInterruptFast( x | PINCHANGEINTERRUPT, CHANGE)
|
||||
|
||||
#define setupInterrupt(x) \
|
||||
EI_printPSTR("Add pin: "); \
|
||||
EI_printPSTR(#x); \
|
||||
EI_printPSTR("\r\n"); \
|
||||
pinMode( x, INPUT_PULLUP); \
|
||||
enableInterruptFast( x, CHANGE)
|
||||
|
||||
#define setupExInterrupt(x) \
|
||||
EI_printPSTR("Add External pin: "); \
|
||||
EI_printPSTR(#x); \
|
||||
EI_printPSTR("\r\n"); \
|
||||
pinMode( x, INPUT_PULLUP); \
|
||||
enableInterruptFast( x , CHANGE)
|
||||
|
||||
#else
|
||||
#error This sketch supports 328-based Arduinos only.
|
||||
#endif
|
||||
|
||||
void printIt(char *pinNumber, uint8_t count) {
|
||||
EI_printPSTR(" Pin ");
|
||||
Serial.print(pinNumber);
|
||||
EI_printPSTR(" was interrupted: ");
|
||||
Serial.println(count, DEC);
|
||||
}
|
||||
|
||||
// Attach the interrupt in setup()
|
||||
// NOTE: PORTJ2-6 (aka, "Pin '70', '71', '72', '73', '74'" are turned on as OUTPUT.
|
||||
// These are not true pins on the Arduino Mega series!
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
EI_printPSTR("--- START ------------------------------------\r\n");
|
||||
#ifdef DEBUG
|
||||
pinMode(PINSIGNAL, OUTPUT);
|
||||
#endif
|
||||
// PINS 0 and 1 NOT USED BECAUSE OF Serial.print()
|
||||
setupPCInterrupt(2); // by default, would be External Interrupt
|
||||
setupExInterrupt(3);
|
||||
setupInterrupt(4);
|
||||
setupInterrupt(5);
|
||||
setupInterrupt(6);
|
||||
setupInterrupt(7);
|
||||
setupInterrupt(8);
|
||||
setupInterrupt(9);
|
||||
setupInterrupt(10);
|
||||
setupInterrupt(11);
|
||||
setupInterrupt(12);
|
||||
#ifndef DEBUG
|
||||
// NOTE: Because the Arduino Duemilanove has an LED to ground and a 1k resistor in series with
|
||||
// it to the pin, Voltage at the pin should be hovering between 1-3 volts. 'nearly' ground. So
|
||||
// a wire to ground will not trip an interrupt, even though we have INPUT_PULLUP. A wire to PWR
|
||||
// will trigger an interrupt. The Uno has a op-amp buffer/driver to the LED, so will not have
|
||||
// this problem; it will behave like the other pins.
|
||||
setupInterrupt(13);
|
||||
#endif
|
||||
setupInterrupt(A0);
|
||||
setupInterrupt(A1);
|
||||
setupInterrupt(A2);
|
||||
setupInterrupt(A3);
|
||||
setupInterrupt(A4);
|
||||
setupInterrupt(A5);
|
||||
}
|
||||
|
||||
uint8_t externalFlag=1;
|
||||
uint8_t enabledToggle=1;
|
||||
uint8_t disableCounter=0;
|
||||
// In the loop, we just check to see where the interrupt count is at. The value gets updated by
|
||||
// the interrupt routine.
|
||||
void loop() {
|
||||
EI_printPSTR("------\r\n");
|
||||
delay(1000); // Perform the loop every second.
|
||||
if (disableCounter & 0x08) {
|
||||
EI_printPSTR("Toggle 2, 3, 4, 8, A0...");
|
||||
delay(1000);
|
||||
if (enabledToggle==1) {
|
||||
EI_printPSTR(" off\r\n");
|
||||
disablePCInterrupt(2);
|
||||
if (externalFlag == 1) {
|
||||
EI_printPSTR("Disable pin 3 external interrupt\r\n");
|
||||
disableInterrupt(3);
|
||||
}
|
||||
else {
|
||||
EI_printPSTR("Disable pin 3 pin change interrupt\r\n");
|
||||
disablePCInterrupt(3);
|
||||
}
|
||||
disableInterrupt(4);
|
||||
disableInterrupt(8);
|
||||
disableInterrupt(A0);
|
||||
enabledToggle=0;
|
||||
}
|
||||
else {
|
||||
if (externalFlag == 1) {
|
||||
EI_printPSTR("3 is now a Pin Change Interrupt.\r\n");
|
||||
setupPCInterrupt(3); // make sure we can switch functions.
|
||||
externalFlag=0;
|
||||
} else {
|
||||
EI_printPSTR("3 is now an External Interrupt.\r\n");
|
||||
setupExInterrupt(3);
|
||||
externalFlag=1;
|
||||
}
|
||||
setupPCInterrupt(2);
|
||||
setupInterrupt(4);
|
||||
setupInterrupt(8);
|
||||
setupInterrupt(A0);
|
||||
enabledToggle=1;
|
||||
}
|
||||
disableCounter=0;
|
||||
}
|
||||
updateOn(2);
|
||||
updateOn(3);
|
||||
updateOn(4);
|
||||
updateOn(5);
|
||||
updateOn(6);
|
||||
updateOn(7);
|
||||
updateOn(8);
|
||||
updateOn(9);
|
||||
updateOn(10);
|
||||
updateOn(11);
|
||||
updateOn(12);
|
||||
updateOn(13);
|
||||
updateOn(A0);
|
||||
updateOn(A1);
|
||||
updateOn(A2);
|
||||
updateOn(A3);
|
||||
updateOn(A4);
|
||||
updateOn(A5);
|
||||
disableCounter++;
|
||||
}
|
||||
|
@@ -0,0 +1,14 @@
|
||||
# Arduino Makefile, see https://github.com/sudar/Arduino-Makefile (it's awesome!)
|
||||
BOARD_TAG = pro
|
||||
BOARD_SUB = 16MHzatmega328
|
||||
ARDUINO_PORT = /dev/ttyUSB0
|
||||
#BOARD_TAG = 2560
|
||||
#ARDUINO_PORT = /dev/ttyACM0
|
||||
ARDUINO_LIBS =
|
||||
AVR_TOOLS_DIR = /usr
|
||||
|
||||
CFLAGS_STD = -g
|
||||
CXXFLAGS_STD = -g
|
||||
|
||||
include /usr/share/arduino/Arduino.mk
|
||||
|
103
libraries/EnableInterrupt/examples/HiSpeedTest/HiSpeedTest.ino
Normal file
103
libraries/EnableInterrupt/examples/HiSpeedTest/HiSpeedTest.ino
Normal file
@@ -0,0 +1,103 @@
|
||||
// EnableInterrupt Simple example sketch
|
||||
// See https://github.com/GreyGnome/EnableInterrupt and the README.md for more information.
|
||||
//
|
||||
// https://github.com/GreyGnome/EnableInterrupt/wiki/Usage#Summary
|
||||
|
||||
//#define OLDLIBRARY
|
||||
|
||||
#define NEEDFORSPEED
|
||||
|
||||
#define USEINTERRUPTPIN8 // PORTB
|
||||
// Define the above, and undefine this for External Interrupt measurements.
|
||||
//#define USEINTERRUPTPIN2
|
||||
|
||||
#if defined USEINTERRUPTPIN8
|
||||
#define PININTERRUPT 8
|
||||
#define PININTERRUPT_ON PORTB |= (1 << PB0)
|
||||
#define PININTERRUPT_OFF PORTB &= ~(1 << PB0)
|
||||
#define THEINTERRUPTVARIABLE myvariable_pin8
|
||||
//#define EI_NOTPORTD // will not produce __vector_5 code
|
||||
#ifdef NEEDFORSPEED
|
||||
#define INTERRUPT_FLAG_PIN8 myvariable_pin8 // NOTICE: NO semicolon!!! This needs to track the PININTERRUPT pin
|
||||
#else
|
||||
#define EI_NOTPORTB
|
||||
volatile uint8_t myvariable_pin8=0;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined USEINTERRUPTPIN2 // PORTD
|
||||
#define PININTERRUPT 2
|
||||
#define PININTERRUPT_ON PORTD |= (1 << PD2)
|
||||
#define PININTERRUPT_OFF PORTD &= ~(1 << PD2)
|
||||
#define THEINTERRUPTVARIABLE myvariable_pin2
|
||||
#ifdef NEEDFORSPEED
|
||||
#define INTERRUPT_FLAG_PIN2 myvariable_pin2 // NOTICE: NO semicolon!!! This needs to track the PININTERRUPT pin
|
||||
#else
|
||||
volatile uint8_t myvariable_pin2=0;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef OLDLIBRARY
|
||||
#include <PinChangeInt.h>
|
||||
#define EI_printPSTR(x) SerialPrint_P(PSTR(x))
|
||||
void SerialPrint_P(const char *str) {
|
||||
for (uint8_t c; (c = pgm_read_byte(str)); str++) Serial.write(c);
|
||||
}
|
||||
#else
|
||||
#include <EnableInterrupt.h>
|
||||
#endif
|
||||
#include <avr/cpufunc.h>
|
||||
|
||||
void incrementMyVariable() { // This isn't used or compiled if NEEDFORSPEED is defined.
|
||||
THEINTERRUPTVARIABLE++;
|
||||
}
|
||||
|
||||
// Attach the interrupt in setup()
|
||||
void setup() {
|
||||
//uint8_t pind, pink;
|
||||
Serial.begin(115200);
|
||||
EI_printPSTR("---------------------------------------\r\n");
|
||||
pinMode(PININTERRUPT, OUTPUT); // Configure the pin as an output
|
||||
PININTERRUPT_OFF;
|
||||
#ifdef OLDLIBRARY
|
||||
attachPinChangeInterrupt(PININTERRUPT, incrementMyVariable, CHANGE);
|
||||
#else
|
||||
#ifdef NEEDFORSPEED
|
||||
enableInterruptFast(PININTERRUPT, CHANGE);
|
||||
#else
|
||||
enableInterrupt(PININTERRUPT, incrementMyVariable, CHANGE);
|
||||
#endif
|
||||
#endif
|
||||
EI_printPSTR("Interrupt enabled, let's go!\r\n");
|
||||
EI_printPSTR("Make sure nothing is connected to pin ");
|
||||
Serial.println(PININTERRUPT, DEC);
|
||||
EI_printPSTR("This sketch sends a software interrupt to that pin.\r\n");
|
||||
}
|
||||
|
||||
// In the loop, we just check to see where the interrupt count is at. The value gets updated by the
|
||||
// interrupt routine.
|
||||
void loop() {
|
||||
|
||||
EI_printPSTR("---------------------------------------\r\n");
|
||||
delay(1000); // Every second,
|
||||
PININTERRUPT_ON; // software interrupt
|
||||
_NOP(); // See "8-bit AVR Microcontroller with 4/8/16/32K Bytes In-System Programmable
|
||||
_NOP(); // Flash" document, Rev. 8271C-AVR-08/10, p. 71.
|
||||
_NOP(); // The interrupt signal must be held until PCIFR is changed, in order for the
|
||||
#if defined USEINTERRUPTPIN8
|
||||
_NOP(); // CPU to execute the ISR. This requires 4 nop assembler instructions.
|
||||
#else
|
||||
// (three nop's for an External Interrupt)
|
||||
#endif
|
||||
PININTERRUPT_OFF; // ...This is after the interrupt.
|
||||
if (THEINTERRUPTVARIABLE > 0) {
|
||||
EI_printPSTR("Pin was interrupted: ");
|
||||
Serial.print(THEINTERRUPTVARIABLE, DEC); // print the interrupt count.
|
||||
EI_printPSTR(" times this iteration.\r\n");
|
||||
THEINTERRUPTVARIABLE=0;
|
||||
}
|
||||
else {
|
||||
EI_printPSTR("No interrupts.\r\n");
|
||||
}
|
||||
}
|
13
libraries/EnableInterrupt/examples/HiSpeedTest/Makefile
Normal file
13
libraries/EnableInterrupt/examples/HiSpeedTest/Makefile
Normal file
@@ -0,0 +1,13 @@
|
||||
# Arduino Makefile, see https://github.com/sudar/Arduino-Makefile (it's awesome!)
|
||||
BOARD_TAG = atmega328
|
||||
ARDUINO_PORT = /dev/ttyUSB0
|
||||
#BOARD_TAG = 2560
|
||||
#ARDUINO_PORT = /dev/ttyACM0
|
||||
ARDUINO_LIBS =
|
||||
AVR_TOOLS_DIR = /usr
|
||||
|
||||
CFLAGS_STD = -g
|
||||
CXXFLAGS_STD = -g
|
||||
|
||||
include /usr/share/arduino/Arduino.mk
|
||||
|
@@ -0,0 +1,214 @@
|
||||
// EnableInterrupt example sketch
|
||||
// See the Wiki at http://code.google.com/p/arduino-pinchangeint/wiki for more information.
|
||||
|
||||
// This example demonstrates the use of the EnableInterrupt library on all pins.
|
||||
// It tests the EI_ARDUINO_INTERRUPTED_PIN facility.
|
||||
// The library has only been tested on an Arduino Duemilanove and Mega ADK.
|
||||
|
||||
#define EI_ARDUINO_INTERRUPTED_PIN
|
||||
#include <EnableInterrupt.h>
|
||||
|
||||
volatile uint8_t externalInterruptFlag=0;
|
||||
volatile uint8_t pinChangeInterruptFlag=0;
|
||||
volatile uint8_t pin70Flag=0;
|
||||
|
||||
#ifdef ARDUINO_MEGA
|
||||
|
||||
void interruptFunctionPin70 () {
|
||||
pinChangeInterruptFlag=arduinoInterruptedPin;
|
||||
pin70Flag++;
|
||||
}
|
||||
|
||||
void interruptFunction () {
|
||||
pinChangeInterruptFlag=arduinoInterruptedPin;
|
||||
}
|
||||
|
||||
void interruptExFunction () {
|
||||
externalInterruptFlag=arduinoInterruptedPin;
|
||||
}
|
||||
|
||||
#define disablePCInterrupt(x) \
|
||||
disableInterrupt( x | PINCHANGEINTERRUPT)
|
||||
|
||||
#define setupPCInterrupt(x) \
|
||||
EI_printPSTR("Add PinChange pin: "); \
|
||||
EI_printPSTR(#x); \
|
||||
EI_printPSTR("\r\n"); \
|
||||
pinMode( x, INPUT_PULLUP); \
|
||||
enableInterrupt( x | PINCHANGEINTERRUPT, interruptFunction, CHANGE)
|
||||
|
||||
#define setupInterrupt(x) \
|
||||
EI_printPSTR("Add pin: "); \
|
||||
EI_printPSTR(#x); \
|
||||
EI_printPSTR("\r\n"); \
|
||||
pinMode( x, INPUT_PULLUP); \
|
||||
enableInterrupt( x, interruptFunction, CHANGE)
|
||||
|
||||
#define setupExInterrupt(x) \
|
||||
EI_printPSTR("Add External pin: "); \
|
||||
EI_printPSTR(#x); \
|
||||
EI_printPSTR("\r\n"); \
|
||||
pinMode( x, INPUT_PULLUP); \
|
||||
enableInterrupt( x , interruptExFunction, CHANGE)
|
||||
#else
|
||||
#error This sketch supports 328-based Arduinos only.
|
||||
#endif
|
||||
|
||||
void printIt(char *pinNumber, uint8_t count) {
|
||||
EI_printPSTR(" Pin ");
|
||||
Serial.print(pinNumber);
|
||||
EI_printPSTR(" was interrupted: ");
|
||||
Serial.println(count, DEC);
|
||||
}
|
||||
|
||||
#define PIN70_PORTBITMAP 0b00000100
|
||||
#define PIN71_PORTBITMAP 0b00001000
|
||||
#define PIN72_PORTBITMAP 0b00010000
|
||||
#define PIN73_PORTBITMAP 0b00100000
|
||||
#define PIN74_PORTBITMAP 0b01000000
|
||||
|
||||
#define PIN75_PORTBITMAP 0b01000000
|
||||
#define PIN76_PORTBITMAP 0b10000000
|
||||
// Attach the interrupt in setup()
|
||||
// NOTE: PORTJ2-6 (aka, "Pin '70', '71', '72', '73', '74'" are turned on as OUTPUT.
|
||||
// These are not true pins on the Arduino Mega series!
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
EI_printPSTR("--- START ------------------------------------\r\n");
|
||||
setupInterrupt(SS);
|
||||
setupInterrupt(SCK);
|
||||
setupInterrupt(MOSI);
|
||||
setupInterrupt(MISO);
|
||||
setupInterrupt(10);
|
||||
setupInterrupt(11);
|
||||
setupInterrupt(12);
|
||||
setupInterrupt(13);
|
||||
setupInterrupt(14);
|
||||
setupInterrupt(15);
|
||||
setupInterrupt(A8);
|
||||
setupInterrupt(A9);
|
||||
setupInterrupt(A10);
|
||||
setupInterrupt(A11);
|
||||
setupInterrupt(A12);
|
||||
setupInterrupt(A13);
|
||||
setupInterrupt(A14);
|
||||
setupInterrupt(A15);
|
||||
//// 0b01111100
|
||||
// MIKE- Why turn them all high? I think they should be 0!
|
||||
DDRJ |= PIN70_PORTBITMAP | PIN71_PORTBITMAP | PIN72_PORTBITMAP
|
||||
| PIN73_PORTBITMAP | PIN74_PORTBITMAP ; // Non-Arduino Port J pins all become output.
|
||||
PORTJ &= ~(PIN70_PORTBITMAP | PIN71_PORTBITMAP | PIN72_PORTBITMAP
|
||||
| PIN73_PORTBITMAP | PIN74_PORTBITMAP) ; // Turn them all low.
|
||||
//// 0b11000000
|
||||
DDRE |= PIN75_PORTBITMAP | PIN76_PORTBITMAP; // Non-Arduino Port E pins all become output.
|
||||
PORTE &= ~(PIN75_PORTBITMAP | PIN76_PORTBITMAP); // Turn them all low.
|
||||
// MIKE- replace this if necessary: enableInterrupt(70, interruptFunctionPin70, CHANGE);
|
||||
enableInterrupt(70, interruptFunction, CHANGE);
|
||||
enableInterrupt(71, interruptFunction, CHANGE);
|
||||
enableInterrupt(72, interruptFunction, CHANGE);
|
||||
enableInterrupt(73, interruptFunction, CHANGE);
|
||||
enableInterrupt(74, interruptFunction, CHANGE);
|
||||
// External Interrupts
|
||||
setupExInterrupt(21);
|
||||
setupExInterrupt(20);
|
||||
setupExInterrupt(19);
|
||||
setupExInterrupt(18);
|
||||
setupExInterrupt(2);
|
||||
setupExInterrupt(3);
|
||||
enableInterrupt(75, interruptExFunction, CHANGE);
|
||||
enableInterrupt(76, interruptExFunction, CHANGE);
|
||||
}
|
||||
|
||||
#define IS_PINCHANGE 0
|
||||
#define IS_EXTERNAL 1
|
||||
#define FLIP 0
|
||||
#define FLOP 1
|
||||
uint8_t pin3state=IS_PINCHANGE;
|
||||
uint8_t enabledToggle=FLOP;
|
||||
uint8_t toggleCounter=0;
|
||||
uint16_t loopCounter=0;
|
||||
uint8_t portj_follower = PIN70_PORTBITMAP;
|
||||
uint8_t porte_follower = PIN75_PORTBITMAP;
|
||||
uint8_t current_pin_state = 0;
|
||||
// In the loop, we just check to see where the interrupt count is at. The value gets updated by
|
||||
// the interrupt routine.
|
||||
void loop() {
|
||||
|
||||
/*
|
||||
if (toggleCounter & 0x80) {
|
||||
EI_printPSTR("Toggle 20, 71, 75, A8, 15, MISO...");
|
||||
delay(200);
|
||||
if (enabledToggle==FLOP) {
|
||||
disableInterrupt(20);
|
||||
disableInterrupt(71);
|
||||
disableInterrupt(75);
|
||||
disableInterrupt(15);
|
||||
disableInterrupt(A8);
|
||||
disableInterrupt(MISO);
|
||||
enabledToggle=FLIP;
|
||||
}
|
||||
else {
|
||||
EI_printPSTR("***ON***");
|
||||
setupExInterrupt(20);
|
||||
setupInterrupt(71);
|
||||
setupExInterrupt(75);
|
||||
setupInterrupt(15);
|
||||
setupInterrupt(A8);
|
||||
setupInterrupt(MISO);
|
||||
enabledToggle=FLOP;
|
||||
}
|
||||
toggleCounter=0;
|
||||
}*/
|
||||
loopCounter++;
|
||||
// Starting positions:
|
||||
// portjfollower 00000100 PORTJ 00000000 // Keep track of port j
|
||||
// portefollower 00000000 PORTE 00000000 // Keep track of port e
|
||||
// current_pin_state 0 // track the state of the current pin
|
||||
if (loopCounter == 0x3FFF) {
|
||||
if (portj_follower <= PIN74_PORTBITMAP) {
|
||||
EI_printPSTR("Interrupt fake pins...");
|
||||
// If the pin is on, turn it off, and go to the next pin
|
||||
if (current_pin_state) {
|
||||
PORTJ ^= portj_follower; // turn it off
|
||||
portj_follower <<= 1;
|
||||
current_pin_state=0;
|
||||
} else {
|
||||
// if the pin is off, turn it on
|
||||
PORTJ ^= portj_follower; // turn it on
|
||||
current_pin_state=1;
|
||||
}
|
||||
delay(1); // run a few instructions after triggering the interrupt.
|
||||
} else if (porte_follower >= PIN75_PORTBITMAP) {
|
||||
EI_printPSTR("Interrupt fake pins...");
|
||||
if (current_pin_state) {
|
||||
PORTE ^= porte_follower; // turn it off
|
||||
porte_follower <<= 1;
|
||||
current_pin_state=0;
|
||||
} else {
|
||||
PORTE ^= porte_follower; // turn it on
|
||||
current_pin_state=1;
|
||||
}
|
||||
delay(1); // run a few instructions after triggering the interrupt.
|
||||
} else {
|
||||
portj_follower=PIN70_PORTBITMAP;
|
||||
porte_follower=PIN75_PORTBITMAP;
|
||||
}
|
||||
loopCounter=0;
|
||||
}
|
||||
if (pinChangeInterruptFlag) {
|
||||
//EI_printPSTR("Pin Change interrupt, pin "); Serial.println(arduinoInterruptedPin);
|
||||
EI_printPSTR("pci: "); Serial.println(pinChangeInterruptFlag);
|
||||
EI_printPSTR(", state: "); Serial.println(arduinoPinState);
|
||||
arduinoInterruptedPin=0;
|
||||
pinChangeInterruptFlag=0;
|
||||
toggleCounter++;
|
||||
}
|
||||
if (externalInterruptFlag) {
|
||||
//EI_printPSTR("External interrupt, pin "); Serial.println(arduinoInterruptedPin);
|
||||
EI_printPSTR("ext: "); Serial.println(externalInterruptFlag);
|
||||
EI_printPSTR(", state: "); Serial.println(arduinoPinState);
|
||||
arduinoInterruptedPin=0;
|
||||
externalInterruptFlag=0;
|
||||
toggleCounter++;
|
||||
}
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
# Arduino Makefile, see https://github.com/sudar/Arduino-Makefile (it's awesome!)
|
||||
#BOARD_TAG = atmega328
|
||||
#ARDUINO_PORT = /dev/ttyUSB0
|
||||
BOARD_TAG = mega
|
||||
BOARD_SUB = atmega2560
|
||||
ARDUINO_PORT = /dev/ttyACM0
|
||||
ARDUINO_LIBS =
|
||||
AVR_TOOLS_DIR = /usr
|
||||
|
||||
CFLAGS_STD = -g
|
||||
CXXFLAGS_STD = -g
|
||||
|
||||
include /usr/share/arduino/Arduino.mk
|
||||
|
@@ -0,0 +1,154 @@
|
||||
// EnableInterrupt example sketch
|
||||
// See the Wiki at http://code.google.com/p/arduino-pinchangeint/wiki for more information.
|
||||
|
||||
// This example demonstrates the use of the EnableInterrupt library on all pins.
|
||||
// It tests the EI_ARDUINO_INTERRUPTED_PIN facility.
|
||||
// The library has only been tested on an Arduino Duemilanove and Mega ADK.
|
||||
|
||||
#define EI_ARDUINO_INTERRUPTED_PIN
|
||||
#include <EnableInterrupt.h>
|
||||
|
||||
volatile uint8_t externalInterruptFlag=0;
|
||||
volatile uint8_t pinChangeInterruptFlag=0;
|
||||
volatile uint8_t pinState=0;
|
||||
|
||||
#ifdef ARDUINO_328
|
||||
#define PINCOUNT(x) pin ##x ##Count
|
||||
|
||||
void interruptFunction () {
|
||||
pinChangeInterruptFlag=arduinoInterruptedPin;
|
||||
pinState=arduinoPinState;
|
||||
}
|
||||
|
||||
void interruptExFunction () {
|
||||
externalInterruptFlag=arduinoInterruptedPin;
|
||||
pinState=arduinoPinState;
|
||||
}
|
||||
|
||||
#define disablePCInterrupt(x) \
|
||||
disableInterrupt( x | PINCHANGEINTERRUPT)
|
||||
|
||||
#define setupPCInterrupt(x) \
|
||||
EI_printPSTR("Add PinChange pin: "); \
|
||||
EI_printPSTR(#x); \
|
||||
EI_printPSTR("\r\n"); \
|
||||
pinMode( x, INPUT_PULLUP); \
|
||||
enableInterrupt( x | PINCHANGEINTERRUPT, interruptFunction, CHANGE)
|
||||
|
||||
#define setupInterrupt(x) \
|
||||
EI_printPSTR("Add pin: "); \
|
||||
EI_printPSTR(#x); \
|
||||
EI_printPSTR("\r\n"); \
|
||||
pinMode( x, INPUT_PULLUP); \
|
||||
enableInterrupt( x, interruptFunction, CHANGE)
|
||||
|
||||
#define setupExInterrupt(x) \
|
||||
EI_printPSTR("Add External pin: "); \
|
||||
EI_printPSTR(#x); \
|
||||
EI_printPSTR("\r\n"); \
|
||||
pinMode( x, INPUT_PULLUP); \
|
||||
enableInterrupt( x , interruptExFunction, CHANGE)
|
||||
#else
|
||||
#error This sketch supports 328-based Arduinos only.
|
||||
#endif
|
||||
|
||||
void printIt(char *pinNumber, uint8_t count) {
|
||||
EI_printPSTR(" Pin ");
|
||||
Serial.print(pinNumber);
|
||||
EI_printPSTR(" was interrupted: ");
|
||||
Serial.println(count, DEC);
|
||||
}
|
||||
|
||||
// Attach the interrupt in setup()
|
||||
// NOTE: PORTJ2-6 (aka, "Pin '70', '71', '72', '73', '74'" are turned on as OUTPUT.
|
||||
// These are not true pins on the Arduino Mega series!
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
EI_printPSTR("--- START ------------------------------------\r\n");
|
||||
#ifdef DEBUG
|
||||
pinMode(PINSIGNAL, OUTPUT);
|
||||
#endif
|
||||
// PINS 0 and 1 NOT USED BECAUSE OF Serial.print()
|
||||
setupPCInterrupt(2); // by default, would be External Interrupt
|
||||
setupExInterrupt(3);
|
||||
setupInterrupt(4);
|
||||
setupInterrupt(5);
|
||||
setupInterrupt(6);
|
||||
setupInterrupt(7);
|
||||
setupInterrupt(8);
|
||||
setupInterrupt(9);
|
||||
setupInterrupt(10);
|
||||
setupInterrupt(11);
|
||||
setupInterrupt(12);
|
||||
#ifndef DEBUG
|
||||
// NOTE: Because the Arduino Duemilanove has an LED to ground and a 1k resistor in series with
|
||||
// it to the pin, Voltage at the pin should be hovering between 1-3 volts. 'nearly' ground. So
|
||||
// a wire to ground will not trip an interrupt, even though we have INPUT_PULLUP. A wire to PWR
|
||||
// will trigger an interrupt. The Uno has an op-amp buffer/driver to the LED, so will not have
|
||||
// this problem; it will behave like the other pins.
|
||||
setupInterrupt(13);
|
||||
#endif
|
||||
setupInterrupt(A0);
|
||||
setupInterrupt(A1);
|
||||
setupInterrupt(A2);
|
||||
setupInterrupt(A3);
|
||||
setupInterrupt(A4);
|
||||
setupInterrupt(A5);
|
||||
}
|
||||
|
||||
#define IS_PINCHANGE 0
|
||||
#define IS_EXTERNAL 1
|
||||
#define FLIP 0
|
||||
#define FLOP 1
|
||||
uint8_t pin3state=IS_PINCHANGE;
|
||||
uint8_t enabledToggle=FLOP;
|
||||
uint8_t toggleCounter=0;
|
||||
// In the loop, we just check to see where the interrupt count is at. The value gets updated by
|
||||
// the interrupt routine.
|
||||
void loop() {
|
||||
if (toggleCounter & 0x10) {
|
||||
EI_printPSTR("Toggle 2, 3, 8, A0...");
|
||||
delay(200);
|
||||
if (enabledToggle==FLOP) {
|
||||
if (pin3state==IS_PINCHANGE)
|
||||
disablePCInterrupt(3);
|
||||
else
|
||||
disableInterrupt(3);
|
||||
disablePCInterrupt(2);
|
||||
disableInterrupt(8);
|
||||
disableInterrupt(A0);
|
||||
enabledToggle=FLIP;
|
||||
}
|
||||
else {
|
||||
EI_printPSTR("3 is now a");
|
||||
if (pin3state == IS_PINCHANGE) {
|
||||
setupExInterrupt(3);
|
||||
EI_printPSTR("n external interrupt.\r\n");
|
||||
pin3state=IS_EXTERNAL;
|
||||
} else {
|
||||
setupExInterrupt(3);
|
||||
EI_printPSTR(" pin change interrupt.\r\n");
|
||||
pin3state=IS_PINCHANGE;
|
||||
}
|
||||
setupPCInterrupt(2);
|
||||
setupInterrupt(8);
|
||||
setupInterrupt(A0);
|
||||
enabledToggle=FLOP;
|
||||
}
|
||||
toggleCounter=0;
|
||||
}
|
||||
// Bug: 0 is not (technically) a proper test because (technically) we have Arduino pin 0.
|
||||
// But we don't support pin 0 in this sketch (it's used for Serial print).
|
||||
if (pinChangeInterruptFlag) {
|
||||
EI_printPSTR("Pin Change interrupt, pin "); Serial.println(pinChangeInterruptFlag);
|
||||
pinChangeInterruptFlag=0;
|
||||
EI_printPSTR(", pin state: "); Serial.println(pinState);
|
||||
toggleCounter++;
|
||||
}
|
||||
if (externalInterruptFlag) {
|
||||
EI_printPSTR("External interrupt, pin "); Serial.println(externalInterruptFlag);
|
||||
externalInterruptFlag=0;
|
||||
EI_printPSTR(", pin state: "); Serial.println(pinState);
|
||||
toggleCounter++;
|
||||
}
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
# Arduino Makefile, see https://github.com/sudar/Arduino-Makefile (it's awesome!)
|
||||
BOARD_TAG = pro
|
||||
BOARD_SUB = 16MHzatmega328
|
||||
ARDUINO_PORT = /dev/ttyUSB0
|
||||
#BOARD_TAG = 2560
|
||||
#ARDUINO_PORT = /dev/ttyACM0
|
||||
ARDUINO_LIBS =
|
||||
AVR_TOOLS_DIR = /usr
|
||||
|
||||
CFLAGS_STD = -g
|
||||
CXXFLAGS_STD = -g
|
||||
|
||||
include /usr/share/arduino/Arduino.mk
|
||||
|
204
libraries/EnableInterrupt/examples/Mighty1284p/Mighty1284p.ino
Normal file
204
libraries/EnableInterrupt/examples/Mighty1284p/Mighty1284p.ino
Normal file
@@ -0,0 +1,204 @@
|
||||
// EnableInterrupt Simple example sketch for the ATmega 644/1284 series of chips.
|
||||
// Note that this sketch is kind of silly, because it uses printf's which depend on
|
||||
// Arduino's USB-serial converters that don't come with a naked 1284, naturally.
|
||||
// This sketch is merely to ensure a proper compile.
|
||||
|
||||
// See the Wiki at http://code.google.com/p/arduino-pinchangeint/wiki for more information.
|
||||
|
||||
// This example demonstrates the use of the EnableInterrupt library on all pins.
|
||||
// The library has only been tested on an Arduino Duemilanove and Mega ADK.
|
||||
|
||||
#include <EnableInterrupt.h>
|
||||
|
||||
volatile uint8_t externalInterruptCounter=0;
|
||||
volatile uint8_t anyInterruptCounter=0;
|
||||
|
||||
#ifdef MIGHTY1284
|
||||
#define PINCOUNT(x) pin ##x ##Count
|
||||
|
||||
// Do not use any Serial.print() in interrupt subroutines. Serial.print() uses interrupts,
|
||||
// and by default interrupts are off in interrupt subroutines. Interrupt routines should also
|
||||
// be as fast as possible. Here we just increment counters.
|
||||
#define interruptFunction(x) \
|
||||
volatile uint8_t PINCOUNT(x); \
|
||||
void interruptFunction ##x () { \
|
||||
anyInterruptCounter++; \
|
||||
PINCOUNT(x)++; \
|
||||
}
|
||||
|
||||
#define interruptExFunction(x) \
|
||||
volatile uint8_t PINCOUNT(x); \
|
||||
void interruptExFunction ##x () { \
|
||||
externalInterruptCounter++; \
|
||||
anyInterruptCounter++; \
|
||||
PINCOUNT(x)++; \
|
||||
}
|
||||
|
||||
#define updateOn(x) \
|
||||
if (PINCOUNT(x) != 0) { \
|
||||
printIt((char *) #x, PINCOUNT(x)); \
|
||||
if (externalInterruptCounter > 0) { \
|
||||
EI_printPSTR(" ext: "); Serial.println(externalInterruptCounter); \
|
||||
externalInterruptCounter=0; \
|
||||
}; \
|
||||
PINCOUNT(x)=0; \
|
||||
}
|
||||
|
||||
#define disablePCInterrupt(x) \
|
||||
disableInterrupt( x | PINCHANGEINTERRUPT)
|
||||
|
||||
#define setupPCInterrupt(x) \
|
||||
EI_printPSTR("Add PinChange pin: "); \
|
||||
EI_printPSTR(#x); \
|
||||
EI_printPSTR("\r\n"); \
|
||||
pinMode( x, INPUT_PULLUP); \
|
||||
enableInterrupt( x | PINCHANGEINTERRUPT, interruptFunction##x, CHANGE)
|
||||
|
||||
#define setupInterrupt(x) \
|
||||
EI_printPSTR("Add pin: "); \
|
||||
EI_printPSTR(#x); \
|
||||
EI_printPSTR("\r\n"); \
|
||||
pinMode( x, INPUT_PULLUP); \
|
||||
enableInterrupt( x, interruptFunction##x, CHANGE)
|
||||
|
||||
#define setupExInterrupt(x) \
|
||||
EI_printPSTR("Add External pin: "); \
|
||||
EI_printPSTR(#x); \
|
||||
EI_printPSTR("\r\n"); \
|
||||
pinMode( x, INPUT_PULLUP); \
|
||||
enableInterrupt( x , interruptExFunction##x, CHANGE)
|
||||
|
||||
interruptFunction(2);
|
||||
interruptExFunction(3);
|
||||
interruptFunction(4);
|
||||
interruptFunction(5);
|
||||
interruptFunction(6);
|
||||
interruptFunction(7);
|
||||
interruptFunction(8);
|
||||
interruptFunction(9);
|
||||
interruptFunction(10);
|
||||
interruptFunction(11);
|
||||
interruptFunction(12);
|
||||
interruptFunction(13);
|
||||
interruptFunction(A0);
|
||||
interruptFunction(A1);
|
||||
interruptFunction(A2);
|
||||
interruptFunction(A3);
|
||||
interruptFunction(A4);
|
||||
interruptFunction(A5);
|
||||
|
||||
volatile uint8_t otherCounter=0;
|
||||
void otherInterrupt3Function(void) { // Must appear after interruptFunction(3)
|
||||
pin3Count++;
|
||||
otherCounter++;
|
||||
}
|
||||
#else
|
||||
#error This sketch supports 1284p-based Arduino-likes only.
|
||||
#endif
|
||||
|
||||
void printIt(char *pinNumber, uint8_t count) {
|
||||
EI_printPSTR(" Pin ");
|
||||
Serial.print(pinNumber);
|
||||
EI_printPSTR(" was interrupted: ");
|
||||
Serial.println(count, DEC);
|
||||
}
|
||||
|
||||
// Attach the interrupt in setup()
|
||||
// NOTE: PORTJ2-6 (aka, "Pin '70', '71', '72', '73', '74'" are turned on as OUTPUT.
|
||||
// These are not true pins on the Arduino Mega series!
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
EI_printPSTR("--- START ------------------------------------\r\n");
|
||||
#ifdef DEBUG
|
||||
pinMode(PINSIGNAL, OUTPUT);
|
||||
#endif
|
||||
// PINS 0 and 1 NOT USED BECAUSE OF Serial.print()
|
||||
setupPCInterrupt(2); // by default, will be External Interrupt
|
||||
setupExInterrupt(3);
|
||||
setupInterrupt(4);
|
||||
setupInterrupt(5);
|
||||
setupInterrupt(6);
|
||||
setupInterrupt(7);
|
||||
setupInterrupt(8);
|
||||
setupInterrupt(9);
|
||||
setupInterrupt(10);
|
||||
setupInterrupt(11);
|
||||
setupInterrupt(12);
|
||||
#ifndef DEBUG
|
||||
// NOTE: Because the Arduino Duemilanove has an LED to ground and a 1k resistor in series with
|
||||
// it to the pin, Voltage at the pin should be hovering between 1-3 volts. 'nearly' ground. So
|
||||
// a wire to ground will not trip an interrupt, even though we have INPUT_PULLUP. A wire to PWR
|
||||
// will trigger an interrupt. The Uno has a op-amp buffer/driver to the LED, so will not have
|
||||
// this problem; it will behave like the other pins.
|
||||
setupInterrupt(13);
|
||||
#endif
|
||||
setupInterrupt(A0);
|
||||
setupInterrupt(A1);
|
||||
setupInterrupt(A2);
|
||||
setupInterrupt(A3);
|
||||
setupInterrupt(A4);
|
||||
setupInterrupt(A5);
|
||||
}
|
||||
|
||||
uint8_t otherToggle=1;
|
||||
uint8_t enabledToggle=1;
|
||||
uint8_t disableCounter=0;
|
||||
// In the loop, we just check to see where the interrupt count is at. The value gets updated by
|
||||
// the interrupt routine.
|
||||
void loop() {
|
||||
EI_printPSTR("------\r\n");
|
||||
delay(1000); // Perform the loop every second.
|
||||
if (disableCounter & 0x08) {
|
||||
EI_printPSTR("Toggle 2, 3, 8, A0...");
|
||||
delay(1000);
|
||||
if (enabledToggle==1) {
|
||||
disablePCInterrupt(2);
|
||||
disableInterrupt(3);
|
||||
disableInterrupt(8);
|
||||
disableInterrupt(A0);
|
||||
enabledToggle=0;
|
||||
}
|
||||
else {
|
||||
if (otherToggle == 1) {
|
||||
EI_printPSTR("3 is now a Pin Change Interrupt.\r\n");
|
||||
enableInterrupt(3, otherInterrupt3Function, CHANGE); // make sure we can switch functions.
|
||||
otherToggle=0;
|
||||
} else {
|
||||
EI_printPSTR("3 is now an External Interrupt.\r\n");
|
||||
otherToggle=1;
|
||||
setupExInterrupt(3);
|
||||
}
|
||||
setupPCInterrupt(2);
|
||||
setupInterrupt(8);
|
||||
setupInterrupt(A0);
|
||||
enabledToggle=1;
|
||||
}
|
||||
disableCounter=0;
|
||||
}
|
||||
updateOn(2);
|
||||
updateOn(3);
|
||||
updateOn(4);
|
||||
updateOn(5);
|
||||
updateOn(6);
|
||||
updateOn(7);
|
||||
updateOn(8);
|
||||
updateOn(9);
|
||||
updateOn(10);
|
||||
updateOn(11);
|
||||
updateOn(12);
|
||||
updateOn(13);
|
||||
updateOn(A0);
|
||||
updateOn(A1);
|
||||
updateOn(A2);
|
||||
updateOn(A3);
|
||||
updateOn(A4);
|
||||
updateOn(A5);
|
||||
EI_printPSTR("Consolidated interrupt count: "); Serial.println(anyInterruptCounter);
|
||||
if (otherCounter) {
|
||||
printIt((char *) "OTHER3", otherCounter);
|
||||
otherCounter=0;
|
||||
}
|
||||
externalInterruptCounter=0;
|
||||
disableCounter++;
|
||||
}
|
||||
|
14
libraries/EnableInterrupt/examples/OOSimple/Makefile
Normal file
14
libraries/EnableInterrupt/examples/OOSimple/Makefile
Normal file
@@ -0,0 +1,14 @@
|
||||
# Arduino Makefile, see https://github.com/sudar/Arduino-Makefile (it's awesome!)
|
||||
BOARD_TAG = pro
|
||||
BOARD_SUB = 16MHzatmega328
|
||||
ARDUINO_PORT = /dev/ttyUSB0
|
||||
#BOARD_TAG = 2560
|
||||
#ARDUINO_PORT = /dev/ttyACM0
|
||||
ARDUINO_LIBS =
|
||||
AVR_TOOLS_DIR = /usr
|
||||
|
||||
CFLAGS_STD = -g
|
||||
CXXFLAGS_STD = -g
|
||||
|
||||
include /usr/share/arduino/Arduino.mk
|
||||
|
129
libraries/EnableInterrupt/examples/OOSimple/OOSimple.ino
Normal file
129
libraries/EnableInterrupt/examples/OOSimple/OOSimple.ino
Normal file
@@ -0,0 +1,129 @@
|
||||
// EnableInterrupt OOSimple object-oriented example sketch.
|
||||
// See https://github.com/GreyGnome/EnableInterrupt and the README.md for more information.
|
||||
|
||||
#include <EnableInterrupt.h>
|
||||
|
||||
// Modify this at your leisure. See https://github.com/GreyGnome/EnableInterrupt/wiki/Usage#Summary
|
||||
#define ARDUINOPIN 8
|
||||
|
||||
class Simple {
|
||||
|
||||
public:
|
||||
Simple() {
|
||||
init();
|
||||
}
|
||||
void updateSimpleVariable();
|
||||
uint8_t getSimpleVariable();
|
||||
|
||||
private:
|
||||
volatile uint8_t _sv; // a simple variable. Notice that it is volatile.
|
||||
void init();
|
||||
};
|
||||
|
||||
void Simple::init() {
|
||||
_sv=0;
|
||||
}
|
||||
void Simple::updateSimpleVariable() {
|
||||
_sv++;
|
||||
}
|
||||
|
||||
uint8_t Simple::getSimpleVariable() {
|
||||
return _sv;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
void *createSimple() {
|
||||
return new Simple();
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
uint8_t getSimpleVariable(void *anObject) {
|
||||
return static_cast<Simple*>(anObject)->getSimpleVariable();
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
void updateSimpleVariable(void *anObject) {
|
||||
static_cast<Simple*>(anObject)->updateSimpleVariable();
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
void *simpleObject0; // this is numbered 0. You can create more, for example void *simpleObject1
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
// If you create more objects, you need to create more interruptFunctionN()'s
|
||||
// that update their simple variables, for example interruptFunction1() .
|
||||
void interruptFunction0() {
|
||||
updateSimpleVariable(simpleObject0);
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
// Attach the interrupt in setup()
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.println("---------------------------------------");
|
||||
|
||||
// If you want to enable more pins, you will need to recreate these 3 lines for
|
||||
// your new pin, object, and function.
|
||||
pinMode(ARDUINOPIN, INPUT_PULLUP); // See http://arduino.cc/en/Tutorial/DigitalPins
|
||||
simpleObject0 = createSimple();
|
||||
enableInterrupt(ARDUINOPIN, interruptFunction0, CHANGE);
|
||||
}
|
||||
|
||||
// In the loop, we just print our object's simple variable. It is updated by the interrupt routine.
|
||||
void loop() {
|
||||
Serial.println("---------------------------------------");
|
||||
delay(1000); // Every second,
|
||||
Serial.print("Pin was interrupted: ");
|
||||
Serial.print(getSimpleVariable(simpleObject0), DEC); // print the interrupt count.
|
||||
Serial.println(" times so far.");
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////// GORY DETAILS //////////////////////////////////////
|
||||
// This example demonstrates the use of the EnableInterrupt library on a single pin of your choice.
|
||||
// It demonstrates calling an object's method from an interrupt. Other objects can be created and called
|
||||
// by simply and creating more simpleObjectN's adding more interruptFunctionN()'s.
|
||||
//
|
||||
// This has only been tested on an Arduino Duemilanove and Mega ADK.
|
||||
// It is designed to work with the Arduino Duemilanove/Uno, Arduino Mega2560/ADK, the Arduino
|
||||
// Leonardo, and the Arduino Due. Please let me know how you fare on the Leonardo or Due.
|
||||
|
||||
// To use:
|
||||
|
||||
// 1. You must be using a fairly recent version of the Arduino IDE software on your PC/Mac,
|
||||
// that is, version 1.0.1 or later. Check Help->About Arduino in the IDE.
|
||||
|
||||
// 2. Wire a simple switch to any Analog or Digital pin (known as ARDUINOPIN, defined below)
|
||||
// that supports interrupts. See https://github.com/GreyGnome/EnableInterrupt/wiki/Usage#Summary
|
||||
// Attach the other end to a GND pin. A "single pole single throw momentary contact normally
|
||||
// open" // pushbutton switch is best for the most interrupting fun.
|
||||
// See https://www.sparkfun.com/products/97 and https://octopart.com/b3f-1000-omron-3117
|
||||
|
||||
// 3. When pressed, the switch will connect the pin to ground ("low", or "0") voltage, and interrupt the
|
||||
// processor. See http://arduino.cc/en/Tutorial/DigitalPins
|
||||
|
||||
// 4. The interrupt is serviced immediately, and the ISR (Interrupt SubRoutine) sets the value of a global
|
||||
// variable. Open Tools->Serial Monitor in the IDE to see the results of your interrupts.
|
||||
|
||||
// 5. Peruse the Examples directory for more elaborate examples.
|
||||
|
||||
// 6. Create your own sketch using the EnableInterrupt library!
|
||||
|
39
libraries/EnableInterrupt/examples/Simple/Makefile
Normal file
39
libraries/EnableInterrupt/examples/Simple/Makefile
Normal file
@@ -0,0 +1,39 @@
|
||||
## Arduino Makefile, see https://github.com/sudar/Arduino-Makefile (it's awesome!)
|
||||
#ARDUINO_DIR = /home/schwager/bin/arduino-1.6.8
|
||||
ARDUINO_DIR = /home/schwager/bin/arduino-1.8.5
|
||||
#ARDMK_DIR = /home/schwager/Projects/Arduino/libraries/EnableInterrupt/examples/Simple
|
||||
ARDMK_DIR = /usr/share/arduino
|
||||
#AVR_TOOLS_DIR = /home/schwager/bin/arduino-1.6.8/hardware/tools/avr
|
||||
AVR_TOOLS_DIR = /home/schwager/bin/arduino-1.8.5/hardware/tools/avr
|
||||
|
||||
BOARD_TAG = pro
|
||||
BOARD_SUB = 16MHzatmega328
|
||||
ARDUINO_PORT = /dev/ttyUSB0
|
||||
##BOARD_TAG = 2560
|
||||
##ARDUINO_PORT = /dev/ttyACM0
|
||||
#ARDUINO_LIBS =
|
||||
#AVR_TOOLS_DIR = /usr
|
||||
#
|
||||
#CFLAGS_STD = -g
|
||||
#CXXFLAGS_STD = -g
|
||||
#
|
||||
#include /usr/share/arduino/Arduino.mk
|
||||
|
||||
########################################################################
|
||||
## Arduino Make file. Refer to https://github.com/sudar/Arduino-Makefile
|
||||
#
|
||||
|
||||
#ARDUINO_DIR = /home/schwager/bin/arduino-1.6.4
|
||||
#BOARD_SUB = atmega1284p
|
||||
#CFLAGS_STD = -g -I /home/schwager/sketchbook/hardware/mighty-1284p-master/variants/standard
|
||||
#CXXFLAGS_STD = -g -I /home/schwager/sketchbook/hardware/mighty-1284p-master/variants/standard
|
||||
#
|
||||
|
||||
#ISP_PROG = usbasp
|
||||
# from boards.txt
|
||||
#BOARD_TAG = mighty_opt
|
||||
#ALTERNATE_CORE = mighty-1284p-master
|
||||
# This is set in the boards.txt file.
|
||||
#F_CPU = 16000000L
|
||||
|
||||
include /usr/share/arduino/Arduino.mk
|
31
libraries/EnableInterrupt/examples/Simple/Makefile-usbasp
Normal file
31
libraries/EnableInterrupt/examples/Simple/Makefile-usbasp
Normal file
@@ -0,0 +1,31 @@
|
||||
## Arduino Makefile, see https://github.com/sudar/Arduino-Makefile (it's awesome!)
|
||||
#BOARD_TAG = atmega328
|
||||
#ARDUINO_PORT = /dev/ttyUSB0
|
||||
##BOARD_TAG = 2560
|
||||
##ARDUINO_PORT = /dev/ttyACM0
|
||||
#ARDUINO_LIBS =
|
||||
#AVR_TOOLS_DIR = /usr
|
||||
#
|
||||
#CFLAGS_STD = -g
|
||||
#CXXFLAGS_STD = -g
|
||||
#
|
||||
#include /usr/share/arduino/Arduino.mk
|
||||
|
||||
########################################################################
|
||||
## Arduino Make file. Refer to https://github.com/sudar/Arduino-Makefile
|
||||
#
|
||||
|
||||
ARDUINO_DIR = /home/schwager/bin/arduino-1.8.4
|
||||
BOARD_SUB = atmega1284p
|
||||
CFLAGS_STD = -g -I /home/schwager/sketchbook/hardware/mighty-1284p-master/variants/standard
|
||||
CXXFLAGS_STD = -g -I /home/schwager/sketchbook/hardware/mighty-1284p-master/variants/standard
|
||||
#
|
||||
|
||||
ISP_PROG = usbasp
|
||||
# from boards.txt
|
||||
BOARD_TAG = mighty_opt
|
||||
ALTERNATE_CORE = mighty-1284p-master
|
||||
# This is set in the boards.txt file.
|
||||
#F_CPU = 16000000L
|
||||
|
||||
include /usr/share/arduino/Arduino.mk
|
67
libraries/EnableInterrupt/examples/Simple/Simple.ino
Normal file
67
libraries/EnableInterrupt/examples/Simple/Simple.ino
Normal file
@@ -0,0 +1,67 @@
|
||||
// EnableInterrupt Simple example sketch. Demonstrates operation on a single pin of your choice.
|
||||
// See https://github.com/GreyGnome/EnableInterrupt and the README.md for more information.
|
||||
#include <EnableInterrupt.h>
|
||||
|
||||
// Modify this at your leisure. Refer to https://github.com/GreyGnome/EnableInterrupt/wiki/Usage#Summary
|
||||
#if defined __AVR_ATmega640__ || defined __AVR_ATmega2560__ || defined __AVR_ATmega1280__ || \
|
||||
defined __AVR_ATmega1281__ || defined __AVR_ATmega2561__
|
||||
#define ARDUINOPIN 10
|
||||
#else
|
||||
// Pin 7 is useful on Arduino Uno, Leonardo, Mighty1284, ATtiny84...
|
||||
#define ARDUINOPIN 7
|
||||
#endif
|
||||
|
||||
volatile uint16_t interruptCount=0; // The count will go back to 0 after hitting 65535.
|
||||
|
||||
void interruptFunction() {
|
||||
interruptCount++;
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
#ifdef MIGHTY1284
|
||||
DDRA=0x0; DDRB=0x0; DDRC=0x0; DDRD=0x0; // set all pins as inputs
|
||||
PORTA=0xFF; PORTB=0xFF; PORTC=0xFF; PORTD=0xFF; // turn on all pullup resistors.
|
||||
#else
|
||||
pinMode(ARDUINOPIN, INPUT_PULLUP); // See http://arduino.cc/en/Tutorial/DigitalPins
|
||||
#endif
|
||||
enableInterrupt(ARDUINOPIN, interruptFunction, CHANGE);
|
||||
}
|
||||
|
||||
// In the loop we just display interruptCount. The value is updated by the interrupt routine.
|
||||
void loop() {
|
||||
Serial.println("---------------------------------------");
|
||||
delay(1000);
|
||||
Serial.print("Pin was interrupted: ");
|
||||
Serial.print(interruptCount, DEC);
|
||||
Serial.println(" times so far.");
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////// GORY DETAILS //////////////////////////////////////
|
||||
// This has only been tested on an Arduino Duemilanove and Mega ADK.
|
||||
// It is designed to work with the Arduino Duemilanove/Uno, Arduino Mega2560/ADK, the Arduino
|
||||
// Leonardo, and the Arduino Due. Please let me know how you fare on the Leonardo or Due.
|
||||
|
||||
// To use:
|
||||
|
||||
// 1. You must be using a fairly recent version of the Arduino IDE software on your PC/Mac,
|
||||
// that is, version 1.0.1 or later. Check Help->About Arduino in the IDE.
|
||||
|
||||
// 2. Wire a simple switch to any Analog or Digital pin (known as ARDUINOPIN, defined below)
|
||||
// that supports interrupts. See https://github.com/GreyGnome/EnableInterrupt/wiki/Usage#Summary
|
||||
// Attach the other end to a GND pin. A "single pole single throw momentary contact normally
|
||||
// open" // pushbutton switch is best for the most interrupting fun.
|
||||
// See https://www.sparkfun.com/products/97 and https://octopart.com/b3f-1000-omron-3117
|
||||
|
||||
// 3. When pressed, the switch will connect the pin to ground ("low", or "0") voltage, and interrupt the
|
||||
// processor. See http://arduino.cc/en/Tutorial/DigitalPins
|
||||
|
||||
// 4. The interrupt is serviced immediately, and the ISR (Interrupt SubRoutine) modifies the value of
|
||||
// the global variable interruptCount. Open Tools->Serial Monitor in the IDE to see the results of your
|
||||
// interrupts.
|
||||
|
||||
// 5. Peruse the Examples directory for more elaborate examples.
|
||||
|
||||
// 6. Create your own sketch using the EnableInterrupt library!
|
||||
|
@@ -0,0 +1,47 @@
|
||||
// EnableInterrupt Simple example sketch. Demonstrates operation on a single pin of your choice.
|
||||
// See https://github.com/GreyGnome/EnableInterrupt and the README.md for more information.
|
||||
#include <EnableInterrupt.h>
|
||||
|
||||
// Modify this at your leisure. Refer to https://github.com/GreyGnome/EnableInterrupt/wiki/Usage#Summary
|
||||
#define ARDUINOPIN 10
|
||||
|
||||
volatile uint16_t interruptCount=0; // The count will go back to 0 after hitting 65535.
|
||||
|
||||
void interruptFunction() {
|
||||
interruptCount++;
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
pinMode(ARDUINOPIN, INPUT_PULLUP); // See http://arduino.cc/en/Tutorial/DigitalPins
|
||||
enableInterrupt(ARDUINOPIN, interruptFunction, CHANGE);
|
||||
}
|
||||
|
||||
// In the loop we just display interruptCount. The value is updated by the interrupt routine.
|
||||
void loop() {
|
||||
Serial.println("---------------------------------------");
|
||||
delay(1000);
|
||||
Serial.print("Pin was interrupted: ");
|
||||
Serial.print(interruptCount, DEC);
|
||||
Serial.println(" times so far.");
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////// GORY DETAILS //////////////////////////////////////
|
||||
|
||||
/* The EnableInterrupt library was designed to present a single API for interrupts to all
|
||||
* the Arduino processors. The problems have traditionally been caused by the varying and
|
||||
* complicated pin interrupt schemes of the ATmega line of processors. The SAM processors
|
||||
* present a more straightforward interrupt design. They already do what the EnableInterrupt
|
||||
* library is trying to present: To enable an interrupt on a pin, simply set up that pin
|
||||
* with the type of interrupt you want, no conversion to an "Interrupt Number" [see the
|
||||
* attachInterrupt() docs].
|
||||
*
|
||||
* This means that the EnableInterrupt library's work on the Due and Zero is trivial: if
|
||||
* called on those platforms, we simply create a macro that converts enableInterrupt() and
|
||||
* disableInterrupt() to attachInterrupt()/detachInterrupt().
|
||||
*
|
||||
* Since that's all it does, the ONLY advantage the EnableInterrupt library offers is as
|
||||
* a consistent API across the chip families. If you are not interested in this then don't use
|
||||
* the EnableInterrupt library.
|
||||
*/
|
@@ -0,0 +1,14 @@
|
||||
# Arduino Makefile, see https://github.com/sudar/Arduino-Makefile (it's awesome!)
|
||||
BOARD_TAG = pro
|
||||
BOARD_SUB = 16MHzatmega328
|
||||
ARDUINO_PORT = /dev/ttyUSB0
|
||||
#BOARD_TAG = 2560
|
||||
#ARDUINO_PORT = /dev/ttyACM0
|
||||
ARDUINO_LIBS =
|
||||
AVR_TOOLS_DIR = /usr
|
||||
|
||||
CFLAGS_STD = -g
|
||||
CXXFLAGS_STD = -g
|
||||
|
||||
include /usr/share/arduino/Arduino.mk
|
||||
|
@@ -0,0 +1,39 @@
|
||||
// SimpleWithLibrary example sketch for the EnableInterrupt library. Demonstrates how to use
|
||||
// the EnableInterrupt library with a sketch that services an interrupt pin, and uses a library
|
||||
// that also requires the EnableInterrupt library.
|
||||
|
||||
// This sketch has only been compiled to the Arduino Uno (ATmega328).
|
||||
// This sketch is only known to compile. It has not been tested functionally.
|
||||
|
||||
// See https://github.com/GreyGnome/EnableInterrupt and the README.md for more information.
|
||||
#define EI_ARDUINO_INTERRUPTED_PIN
|
||||
#include <EnableInterrupt.h>
|
||||
#define USELESSPIN 10
|
||||
#include "Useless.h"
|
||||
|
||||
#define ARDUINOPIN 9
|
||||
|
||||
volatile uint16_t interruptCount=0;
|
||||
|
||||
void interruptFunction() {
|
||||
interruptCount++;
|
||||
}
|
||||
|
||||
// UselessClass uses the EnableInterrupt library.
|
||||
UselessClass uselessObject=UselessClass(USELESSPIN, CHANGE);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
pinMode(ARDUINOPIN, INPUT_PULLUP); // See http://arduino.cc/en/Tutorial/DigitalPins
|
||||
enableInterrupt(ARDUINOPIN, interruptFunction, CHANGE);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Serial.println("---------------------------------------");
|
||||
delay(1000);
|
||||
Serial.print("Pin was interrupted: ");
|
||||
Serial.print(interruptCount, DEC);
|
||||
Serial.println(" times so far.");
|
||||
Serial.print("Useless interrupt count: ");
|
||||
Serial.print(uselessObject.getUselessVariable(), DEC);
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
// FOR TESTING, TO DEMONSTRATE HOW TO USE ENABLEINTERRUPT IN A LIBRARY.
|
||||
// See Useless.h for more information.
|
||||
#include "Useless.h"
|
||||
|
||||
volatile uint8_t uselessVariable=0;
|
||||
|
||||
void uselessFunction() {
|
||||
uselessVariable++;
|
||||
}
|
||||
|
||||
void UselessClass::init(uint8_t pin, uint8_t mode) {
|
||||
pinMode(pin, INPUT_PULLUP);
|
||||
enableInterrupt(pin, uselessFunction, mode);
|
||||
}
|
||||
|
||||
uint8_t UselessClass::getUselessVariable() {
|
||||
return uselessVariable;
|
||||
}
|
||||
|
||||
void UselessClass::reset() {
|
||||
uselessVariable=0;
|
||||
}
|
||||
|
||||
void UselessClass::disable(uint8_t pin) {
|
||||
disableInterrupt(pin);
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
// This is a useless library. To use such a useless thing, with the EnableInterrupt library,
|
||||
// you need to #define LIBCALL_ENABLEINTERRUPT in your library, like so:
|
||||
#define LIBCALL_ENABLEINTERRUPT
|
||||
// Thus, none of the functions or ISRs will get compiled but their prototypes are declared
|
||||
// so you can use them as illustrated in the Useless.cpp.
|
||||
|
||||
// You also need to #include the EnableInterrupt.h file in your sketch. After you #include the
|
||||
// EnableInterrupt.h file, #include the library's .h file (ie, this one in this example). This
|
||||
// will compile the requisite components. See the SimpleWithLibrary.ino sketch.
|
||||
|
||||
#include <stdint.h>
|
||||
#include <Arduino.h>
|
||||
|
||||
#define EI_ARDUINO_INTERRUPTED_PIN
|
||||
#include <EnableInterrupt.h>
|
||||
|
||||
class UselessClass {
|
||||
public:
|
||||
UselessClass(uint8_t pin, uint8_t mode) {
|
||||
init(pin, mode);
|
||||
}
|
||||
uint8_t getUselessVariable();
|
||||
void reset();
|
||||
void disable(uint8_t pin);
|
||||
private:
|
||||
void init(uint8_t pin, uint8_t mode);
|
||||
};
|
||||
|
100
libraries/EnableInterrupt/examples/Testing/Testing.ino
Normal file
100
libraries/EnableInterrupt/examples/Testing/Testing.ino
Normal file
@@ -0,0 +1,100 @@
|
||||
|
||||
|
||||
// include the EnableInterrupt library - see the links in the related topics section above for details
|
||||
#define EI_ARDUINO_INTERRUPTED_PIN // to enable pin states functionality
|
||||
#include <EnableInterrupt.h>
|
||||
|
||||
|
||||
//DEBUG settings
|
||||
#define DEBUG 1 // 0 - no debug
|
||||
|
||||
|
||||
// Assign your channel in pins
|
||||
#define CHANNEL1_IN_PIN 2
|
||||
#define CHANNEL2_IN_PIN 3
|
||||
#define CHANNEL3_IN_PIN 4
|
||||
#define CHANNEL4_IN_PIN 5
|
||||
#define CHANNEL5_IN_PIN 6
|
||||
#define CHANNEL6_IN_PIN 7
|
||||
#define CHANNEL7_IN_PIN 8
|
||||
#define CHANNEL8_IN_PIN 9
|
||||
|
||||
|
||||
|
||||
|
||||
volatile uint16_t interruptCountA=0; // The count will go back to 0 after hitting 65535.
|
||||
volatile uint16_t PinStateSumB=0; // The count will go back to 0 after hitting 65535.
|
||||
|
||||
// shared variables are updated by the ISR and read by loop.
|
||||
// In loop we immediatley take local copies so that the ISR can keep ownership of the
|
||||
// shared ones. To access these in loop
|
||||
// we first turn interrupts off with noInterrupts
|
||||
// we take a copy to use in loop and the turn interrupts back on
|
||||
// as quickly as possible, this ensures that we are always able to receive new signals
|
||||
volatile uint8_t InterruptedPinShared;
|
||||
volatile uint8_t PinStateShared;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
|
||||
|
||||
if (DEBUG !=0) {
|
||||
Serial.begin(9600);
|
||||
Serial.println("setup started ");
|
||||
}
|
||||
|
||||
enableInterrupt(CHANNEL1_IN_PIN, interruptFunction,CHANGE);
|
||||
enableInterrupt(CHANNEL2_IN_PIN, interruptFunction,CHANGE);
|
||||
|
||||
if (DEBUG !=0) {
|
||||
Serial.println(" setup completed ");
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
static uint8_t InterruptedPin;
|
||||
static uint8_t PinState;
|
||||
noInterrupts(); // turn interrupts off quickly while we take local copies of the shared variables
|
||||
InterruptedPin = InterruptedPinShared;
|
||||
PinState = PinStateShared;
|
||||
interrupts(); // we have local copies of the inputs, so now we can turn interrupts back on
|
||||
// as soon as interrupts are back on, we can no longer use the shared variables here
|
||||
|
||||
//Printing
|
||||
if (DEBUG !=0) {
|
||||
Serial.print("interruptCountA:");
|
||||
Serial.print(interruptCountA);
|
||||
Serial.println("");
|
||||
Serial.print("PinStateSumB:");
|
||||
Serial.print(PinStateSumB);
|
||||
Serial.println("");
|
||||
Serial.print("InterruptedPin:");
|
||||
Serial.print(InterruptedPin);
|
||||
Serial.println("");
|
||||
Serial.print("PinState:");
|
||||
Serial.print(PinState);
|
||||
Serial.println("");
|
||||
|
||||
}
|
||||
|
||||
|
||||
}// end of loop
|
||||
|
||||
|
||||
void interruptFunction() {
|
||||
//interruptCountA increased each time interrupt called
|
||||
interruptCountA++;
|
||||
//save values to use them outside the interrupt function
|
||||
InterruptedPinShared=arduinoInterruptedPin;
|
||||
PinStateShared=arduinoPinState;
|
||||
//PinStateSumB increased each time arduinoPinState=1 detected
|
||||
PinStateSumB=PinStateSumB + arduinoPinState ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
24
libraries/EnableInterrupt/examples/test.sh
Normal file
24
libraries/EnableInterrupt/examples/test.sh
Normal file
@@ -0,0 +1,24 @@
|
||||
#!/bin/bash
|
||||
|
||||
examples="
|
||||
AllPins2560
|
||||
AllPins328
|
||||
ATtinyBlink
|
||||
HiSpeed
|
||||
HiSpeedAllPins2560
|
||||
HiSpeedAllPins328
|
||||
InterruptedPin2560
|
||||
InterruptedPin328
|
||||
Mighty1284p
|
||||
OOSimple
|
||||
Simple
|
||||
SimpleWithLibrary
|
||||
"
|
||||
|
||||
for example in $examples; do
|
||||
echo $example
|
||||
sleep 2
|
||||
( cd $example; rm -rf build-*; make)
|
||||
echo $example done
|
||||
sleep 2
|
||||
done
|
المرجع في مشكلة جديدة
حظر مستخدم