Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You will be writing an analog input/output program that allows you to control th

ID: 3815318 • Letter: Y

Question

You will be writing an analog input/output program that allows you to control the brightness of a single LED with a single input. First, write a program that reads the analog voltage drop across a potentiometer. This value should range from 0 to 1023 as the potentiometer is adjusted. Next, use this input value to adjust the brightness of an LED from off (0) to full-on (1023). In order to do this, you will need to set up the microcontroller to drive the LED using a PWM signal (use one of the 8-bit timers on PORTD). The resulting demonstration should be such that the LED smoothly transitions from off to full-on as the dial is increased from 0 to 1023.

Explanation / Answer

what we are going to done:

What we done:

1. Read the input from analog pin A0
2.Adjusted the value to a condensed range using tha map() function
3.passed the value to analogwrite() which in turn adjusts the brightness of the LED.

const int analogInputPin = A0; // Analog input pin that the potentiometer is attached to
const int analogOutputPin = 9; // Analog output pin that the LED is attached to

int sensorValue = 0;        // value read from the pot
int outputValue = 0;        // value output to the PWM (analog out)

void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
}

void loop() {
// read the analog in value:
sensorValue = analogRead(analogInputPin);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255);
// change the analog out value:
analogWrite(analogOutputPin, outputValue);

// print the results to the serial monitor:
Serial.print("sensor = ");
Serial.print(sensorValue);
Serial.print(" output = ");
Serial.println(outputValue);

// wait 2 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(2);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote