Week 8: Learning Progress Light

My idea for this week’s exercise is to create a ‘traffic light’ for learning progress where one can track how close one is to finishing an exercise. On turning the know, first a red, then a yellow, and then a green LED lights up. Then one can press the button to mark a task as completed and some ‘light confetti’ (blinking LEDs) show up to congratulate the learner.

In the end, this was not too difficult to create but it took me some time to understand the difference between analog and digital input but now it seems more clear after using analog input as well.

int greenledPin = 5;
int yellowledPin = 4;
int redledPin = 3;
int buttonPin = 2;

void setup() {
  // put your setup code here, to run once:
  pinMode(greenledPin, OUTPUT);
  pinMode(yellowledPin, OUTPUT);
  pinMode(redledPin, OUTPUT);
  pinMode(buttonPin, INPUT);
  Serial.begin(9600); //bit mode. 9600 commuting back and forth per minute
}

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

  int knobValue = analogRead(A0);
  
  if (681 < knobValue) {
    digitalWrite(greenledPin, HIGH);
  } else {
    digitalWrite(greenledPin, LOW);
  }
  if (341 < knobValue) {
    digitalWrite(yellowledPin, HIGH);
  } else {
    digitalWrite(yellowledPin, LOW);
  }
  if (100 < knobValue) {
    digitalWrite(redledPin, HIGH);
  } else {
    digitalWrite(redledPin, LOW);
  }

  int buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH) {
    digitalWrite(redledPin, HIGH);
    digitalWrite(yellowledPin, HIGH);
    digitalWrite(greenledPin, HIGH);
    delay(200);
    digitalWrite(redledPin, LOW);
    digitalWrite(yellowledPin, LOW);
    digitalWrite(greenledPin, LOW);
    delay(200);
    digitalWrite(redledPin, HIGH);
    digitalWrite(yellowledPin, HIGH);
    digitalWrite(greenledPin, HIGH);
    delay(200);
    digitalWrite(redledPin, LOW);
    digitalWrite(yellowledPin, LOW);
    digitalWrite(greenledPin, LOW);
    delay(200);
    digitalWrite(redledPin, HIGH);
    digitalWrite(yellowledPin, HIGH);
    digitalWrite(greenledPin, HIGH);
    delay(200);
    digitalWrite(redledPin, LOW);
    digitalWrite(yellowledPin, LOW);
    digitalWrite(greenledPin, LOW);
    delay(200);
    digitalWrite(redledPin, HIGH);
    digitalWrite(yellowledPin, HIGH);
    digitalWrite(greenledPin, HIGH);
    delay(200);
    digitalWrite(redledPin, LOW);
    digitalWrite(yellowledPin, LOW);
    digitalWrite(greenledPin, LOW);
  }

  Serial.println(buttonState);
}

 

Leave a Reply