Makeshift method for using an external clock/debugger

So as we all know, the arduino sadly does not include a debugger and correctly using an external oscillator basically means not using an arduino anymore.

Since this is going to be used for debugging purposes, the 'clock' used will either be very slow or manually triggered. For reference the clock i'm referring to is the one built by Ben Eater.

I thought i would take the input of the clock and set it as interrupt on pin 2 on Uno. And after having the written the code, i insert a bit to wait until the interrupt function is called to let it move on.

This is my first stab at it, it doesn't work on tinker cad, i'm a bit lazy so i haven't built the circuit. I decided to use blinking LED for a classic callback.

Original Code:

void setup() { pinMode(13, OUTPUT); } void loop() { digitalWrite(13, HIGH); delay(1000); digitalWrite(13, LOW); delay(1000); } 

My attempt at external clock:

// C++ code // const byte interrupt_pin = 2; volatile byte move_on = LOW; void setup() { pinMode(13, OUTPUT); pinMode(interrupt_pin, INPUT); Serial.begin(9600); attachInterrupt(digitalPinToInterrupt(interrupt_pin), step, RISING); } void step() { move_on = !move_on; } void loop() { noInterrupts(); digitalWrite(13, HIGH); Serial.println("high"); interrupts(); while(!move_on){delay(10);} //wait for clock step(); //reset for next step noInterrupts(); digitalWrite(13, LOW); Serial.println("low"); interrupts(); while(!move_on){delay(10);} //wait for clock step(); noInterrupts(); } 

Any thoughts, ideas, suggestions?

Touch here for the full post on the Arduino Apprentices tumblr

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s