Well, that's fun. So I find out I'm using the wrong pin, even though I seem to be able to trigger the interrupt with P2, I thought I should make the code match.
Only when I try to upload, the Digispark "adds" to windows (USB add device sound) over and over - about every 1-2 seconds.
Also, my code seems to be running straight away - the 5 second delay doesn't seem to be there? I've little idea how I managed to accomplish this - does anyone know how to make it behave? I thought it was just windows7 being persnickety, but I shouldn't get flashing lights for a few seconds!
The code I believe to be loaded on the chip:
#define DEBUG 1 // Set to 1 to enable, 0 to disable
#if DEBUG
#define DebugPin 1 // Digispark model A onboard LED
#define DebugBlink 75
#define DebugPause 300
#define debugDelay(ms) delay(ms) // Change if you need a special delay function (e.g. if you use libraries that need regular refresh calls)
const byte Int0Pin = 0; //I want to change this to 2, but I'm not sure I need it at all?
void _debugBlink(int n) {
for ( int i = 0 ; i < n ; i++ ) {
digitalWrite(DebugPin, HIGH);
debugDelay(DebugBlink);
digitalWrite(DebugPin, LOW);
debugDelay(DebugBlink);
}
debugDelay(DebugPause);
}
void Blink() {
for ( int i = 0 ; i < 3 ; i++ ) {
digitalWrite(DebugPin, HIGH);
debugDelay(DebugBlink * 3);
digitalWrite(DebugPin, LOW);
debugDelay(DebugBlink * 3);
}
debugDelay(DebugPause);
}
void _debugSetup() {
pinMode(DebugPin, OUTPUT);
}
#define debugBlink(n) _debugBlink(n) // Do the blink when DEBUG is set
#define debugSetup() _debugSetup()
#else
#define debugBlink(n) // Make the calls disappear when DEBUG is 0
#define debugSetup()
#endif
void setup() {
// Interrupts
//I could later swap out for enableInterrupt() function, supposed to be cleaner.
pinMode(Int0Pin, INPUT); //Define interrupt pin as INPUT, no pull-up.
attachInterrupt(Int0Pin, Blink, RISING); //dPTI for compatibility across devices, triggers on rising edge
}
void loop(){
debugBlink(10);
delay(5000);
}
Sorry it's kinda choppy, I grabbed a blink code online as a reality check and built from there.