// Include the required libraries
#include <Arduino.h>
// Define the pins for photoresistor and LED bar graph
const int photoresistorPin = PA0; // Analog input pin
const int ledPins[] = {PB11, PB1, PB2, PB3, PB4, PB5, PB6, PB7,PB8,PB9}; // LED bar graph pins
void setup() {
// Initialize serial communication
Serial.begin(9600);
// Initialize LED pins as output
for (int i = 0; i < 10; i++) {
pinMode(ledPins[i], OUTPUT);
}
}
void loop() {
// Read the value from photoresistor
int sensorValue = analogRead(photoresistorPin);
// Convert the sensor value to LED bar graph value (0-7)
int barValue = map(sensorValue, 0, 1023, 0, 10);
// Display the LED bar graph
displayBarGraph(barValue);
// Print the sensor value to serial monitor
Serial.print("Sensor value: ");
Serial.println(sensorValue);
// Delay for stability
delay(1000);
}
void displayBarGraph(int value) {
// Turn on LEDs according to the value
for (int i = 0; i < 10; i++) {
digitalWrite(ledPins[i], i < value ? LOW : HIGH);
}
}