Weekly assignment – Week #9

For this week’s assignment, my goal was to get more comfortable with the different components of Arduino and making circuits. I decided to use a potentiometer for analog input and a button for the digital. With potentiometer, I aimed to control the dim level of a red LED, and with the button I wanted to control the yellow LED. Here is the result:

Here is my code:

#define LED_PIN_1 8
#define BUTTON_PIN 7

#define LED_PIN_2 11
#define POTENTIOMETER_PIN A1

void setup() {
  pinMode(LED_PIN_1, OUTPUT);
  pinMode(BUTTON_PIN, INPUT);

  pinMode(LED_PIN_2, OUTPUT);
}
void loop() {

  int potentiometerValue = analogRead(POTENTIOMETER_PIN);
  int brightness = potentiometerValue / 4;
  analogWrite(LED_PIN_2, brightness);

  if (digitalRead(BUTTON_PIN) == HIGH) {
    digitalWrite(LED_PIN_1, HIGH);
  }
  else {
    digitalWrite(LED_PIN_1, LOW);
  }
}

It was a simple setup but completing this assignment made me feel more comfortable with Arduino. Also, a big shoutout to the IM Lab assistants and their Saturday vibes💅🏻.

Leave a Reply