Testing the Arduino

I already wanted to get an Arduino to do some experiments, but the final push was seeing Ben Eater using an Ardino Mega do do some debugging on his 6502 computer. Now that we have built up the astable and monostable timers and the Arduino also arrived it was time to test it.

The setup I used is quite simple: connect GND to the common ground, and pin 2 to the clock signal from the breadboard and then hook up an interrupt with pin 2 that prints out something. For the HW setup just two jumper wires are needed.

Arduino set up to monitor the clock signal

And the SW isn’t too complicated either.

#define CLOCK 2

unsigned int pushed;
unsigned long lasttime;

void setup() {
  Serial.begin(57600);
  Serial.println("Hello World");

  pushed = 0;

  pinMode(CLOCK, INPUT);
  attachInterrupt(digitalPinToInterrupt(CLOCK), onClock, RISING);
  
  lasttime = millis();
}

void onClock() {
  unsigned long time = millis();
  unsigned long delta = time-lasttime;
  lasttime = time;

  pushed = pushed + 1;

  Serial.print(delta);
  Serial.print("  You have pushed a button ");
  Serial.print(pushed);
  Serial.println(" times.");
}

void loop() {
  // put your main code here, to run repeatedly:
}