Ask AI on The Internet
Ask Another Question Browse Other QuestionsQuestion: write me a code to turn the green light into red
Assuming you are working with an Arduino and an RGB LED, here is a simple code to turn the green light off and the red light on: ```cpp #include <Arduino.h> // Define the pins for the LED. const int redPin = 9; const int greenPin = 10; const int bluePin = 11; void setup() { // Set the LED pins as outputs. pinMode(redPin, OUTPUT); pinMode(greenPin, OUTPUT); pinMode(bluePin, OUTPUT); // Turn on the green LED and turn off the red and blue LEDs. analogWrite(redPin, 0); analogWrite(greenPin, 255); analogWrite(bluePin, 0); // Wait for 2 seconds before turning the green LED off and the red LED on. delay(2000); } void loop() { // Turn the green LED off and the red LED on. analogWrite(redPin, 255); analogWrite(greenPin, 0); // You may add any functionality in this loop as per your requirement. } ``` Make sure to connect the RGB LED's pins to the appropriate pins on your Arduino board, with the red LED pin set to pin 9, the green LED pin set to pin 10, and the blue LED pin set to pin 11. Customize the pin numbers as needed.
Think your answer is better than the AI's? Post it below.
Question Tags
If you want your question answered by an AI, click here.
Comment Section