Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Comment what each line does in Arduino #define LED_1_PIN 12 #define LED_2_PIN 11 #define LED_3_PIN 10 #define BUTTON_PIN 2 #define POTENTIOMETER_PIN A2 unsigned long previousTimeLED1Blink

Comment what each line does in Arduino

#define LED_1_PIN 12 #define LED_2_PIN 11 #define LED_3_PIN 10

#define BUTTON_PIN 2

#define POTENTIOMETER_PIN A2

unsigned long previousTimeLED1Blink = millis(); unsigned long blinkDelayLED1 = 500;

int LED1State = LOW;

void setup() { Serial.begin(9600); Serial.setTimeout(10);

pinMode(LED_1_PIN, OUTPUT); pinMode(LED_2_PIN, OUTPUT); pinMode(LED_3_PIN, OUTPUT);

pinMode(BUTTON_PIN, INPUT); }

void loop() { // action 1 if (Serial.available() > 0) { int data = Serial.parseInt(); if ((data >= 100) && (data <= 4000)) { blinkDelayLED1 = data; } }

// action 2 unsigned long timeNow = millis(); if (timeNow - previousTimeLED1Blink > blinkDelayLED1) { if (LED1State == LOW) { LED1State = HIGH; } else { LED1State = LOW; } digitalWrite(LED_1_PIN, LED1State); previousTimeLED1Blink += blinkDelayLED1; }

// action 3 int potentiometerValue = analogRead(POTENTIOMETER_PIN); int intensity = potentiometerValue / 4; analogWrite(LED_2_PIN, intensity);

// action 4 if (digitalRead(BUTTON_PIN) == HIGH) { digitalWrite(LED_3_PIN, HIGH); } else { digitalWrite(LED_3_PIN, LOW); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions