/*
   Project:       KITT car LEDs
   Description:   Flashes LEDs back and forth with speed control
   Creation date: 4/15/23
   Author:        AnonEngineering - Original code
   Author2:       jim lee   - Added the autoPOT thing.
*/

#include <autoPOT.h>


// ************ resulting program ************

autoPOT thePOT(A0);   // Our background POT object.
int     speed;        // The delay value from the POT

void setup() {

  speed = 0;
  for (int i = 2; i <= 9; i++)  { // setup the pins as OUTPUTs
    pinMode(i, OUTPUT);
  }
  thePOT.setCallback(gotValue);     // Tell the POT what to call on changes.
}

// New values arrive here.
void gotValue(int newVal) { speed = newVal; }


void loop() {

  idle();
  for (int ledPin = 2; ledPin <= 9; ledPin++) {
    digitalWrite(ledPin, HIGH);
    sleep(speed);
    digitalWrite(ledPin, LOW);
  }
  // now go the other
  for (int ledPin = 9; ledPin >= 2; ledPin--) {
    digitalWrite(ledPin, HIGH);
    sleep(speed);
    digitalWrite(ledPin, LOW);
  }
}
$abcdeabcde151015202530fghijfghij