Digital Lecture Assignment 9

Aidan Singh

Arduino Code:

int potVal = 0;
int tempo = 1000;
int lastTime = 0;
int ledPins[4] = {29,30,31,32};
int lastStep = 0;
int currentStep = 0;
int totalSteps = 4;

void setup() {
  Serial.begin(9600);
  for(int i = 0; i< 4; i++){
    pinMode(ledPins[i], OUTPUT);
  }
}

void loop() {
  readPot();
  if(millis() > lastTime + tempo ){
    serialCommunication();
    lastTime = millis();
    digitalWrite(ledPins[lastStep], LOW);
    digitalWrite(ledPins[currentStep], HIGH);
    lastStep = currentStep;
    currentStep++;
    if(currentStep == totalSteps){
      currentStep = 0;
    }
  }
}

void readPot(){
  potVal =analogRead(A18);
  tempo = map(potVal, 0, 1023, 100, 1000);
}

void serialCommunication(){
  Serial.write(currentStep);
  //delay(50);
}


Processing Code:

Leave a comment

Design a site like this with WordPress.com
Get started