arduino code(made by chat gpt and mr D)

arduino code(made by chat gpt and mr D)

Seungwoo Byun and 2 OthersGeraldo Moran
Anxuan Xie

const int lightSensorPin = A0;  // Analog pin for the light sensor
const int redPin = 10;          // Digital pin for the red LED of the RGB LED
const int greenPin = 11;        // Digital pin for the green LED of the RGB LED
const int bluePin = 12;         // Digital pin for the blue LED of the RGB LED

void setup() {
  pinMode(lightSensorPin, INPUT);
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);

  Serial.begin(9600);  // Initialize serial communication at 9600 bps
}

void loop() {
  int lightValue = analogRead(lightSensorPin);  // Read the analog value from the light sensor

  // Map the light value to the LED brightness (assuming the sensor values range from 0 to 1023)
  int brightness = map(lightValue, 0, 1023, 0, 255);

  // Set the color of the RGB LED based on the light value
  analogWrite(redPin, brightness);
  analogWrite(greenPin, brightness);
  analogWrite(bluePin, brightness);

  // Display the light sensor reading on the Serial Monitor
  Serial.print("Light Sensor Reading: ");
  Serial.println(lightValue);

  delay(100);  // Optional delay to slow down the changes and make it more visible
}