ArduinoArduino Mega 2560Exact chip

Mega: light chase

A 10-LED bar graph on the Mega’s pins 22 to 31; the knob on A8 sets the speed.

Mega: light chase in Argynix Lab

The code

sketch.inoC++
// The Mega's extra pins: a 10-LED bar graph on pins 22 to 31 chases its light.
// The knob on A8 (one of the Mega's 16 analog inputs) sets the speed.
// One LED is lit at a time, so one 220 Ω resistor on the shared cathodes limits them all.

void setup() {
  for (int p = 22; p <= 31; p++) pinMode(p, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  for (int i = 0; i < 10; i++) {
    for (int p = 0; p < 10; p++) digitalWrite(22 + p, p == i);
    delay(map(analogRead(A8), 0, 1023, 20, 300));
  }
  Serial.print("knob:");
  Serial.println(analogRead(A8));
}