1 inputs and then 1 outputs
// Constants
const int potPin = A0; // Analog input pin for potentiometer
const int ledPin = 9; // Digital output pin for LED
// Variables
int sensorValue = 0; // Variable to store the sensor reading
int outputValue = 0; // Variable to store the output value
void setup() {
pinMode(ledPin, OUTPUT); // Set the LED pin as an output
}
void loop() {
sensorValue = analogRead(potPin); // Read the sensor value (0-1023)
outputValue = map(sensorValue, 0, 1023, 0, 255); // Map the sensor value to the LED brightness range (0-255)
analogWrite(ledPin, outputValue); // Set the LED brightness based on the mapped value
}
Comments
Post a Comment