Aidan Singh
***Includes Bonus***
int ledPins[4] = {28,29,30,31};
int potPin = 32;
int switchPin1 = 33;
int switchPin2 = 34;
int tempo=1000;
unsigned long lastStepTime = 0;
int currentStep = 0;
int totalSteps = 4;
void setup() {
for(int i=0;i<4;i++){
pinMode(ledPins[i], OUTPUT);
}
pinMode(switchPin1, INPUT);
pinMode(switchPin2, INPUT);
}
void stepForwards(){
if(millis() >= lastStepTime + tempo) {
lastStepTime = millis();
digitalWrite(ledPins[currentStep],LOW);
currentStep++;
if(currentStep == totalSteps){
currentStep = 0;
}
digitalWrite(ledPins[currentStep],HIGH);
}
}
void stepBackwards(){
if(millis() >= lastStepTime + tempo) {
lastStepTime = millis();
digitalWrite(ledPins[currentStep],LOW);
currentStep--;
if(currentStep < 0){
currentStep = 3;
}
digitalWrite(ledPins[currentStep],HIGH);
}
}
void stepRand(){if(millis() >= lastStepTime + tempo) {
lastStepTime = millis();
digitalWrite(ledPins[currentStep],LOW);
currentStep = random(0, 4);
digitalWrite(ledPins[currentStep],HIGH);
}
}
void loop(){
tempo =analogRead(A13);
if(digitalRead(switchPin2) == HIGH){
if(digitalRead(switchPin1) == HIGH){
stepForwards();
}else{
stepBackwards();
}
}else{
stepRand();
}
}