# Modify this code?

**URL:** <https://forum.arduino.cc/t/modify-this-code/953425>\
**Category:** General Guidance\
**Created:** [January 30, 2022, 11:24pm UTC](https://forum.arduino.cc/t/modify-this-code/953425 "2022-01-30T23:24:47Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon47908823](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@anon47908823](https://forum.arduino.cc/u/anon47908823)\
**Post date:** [January 30, 2022, 11:24pm UTC](https://forum.arduino.cc/t/modify-this-code/953425/1 "2022-01-30T23:24:47Z")

</div>

Could someone modify this code so that instead of a normal LED, an RGB LED will turn on and blink red, green, blue? For like 1 second per color? Thanks, I'm brand new so treat me like an idiot please

Code:

> **[Turn On LED in Dark With LDR and Arduino](https://thecustomizewindows.com/2018/05/turn-on-led-in-dark-with-ldr-and-arduino/)**
>
> Turn On LED in Dark With LDR and Arduino. Very easy circuit diagram with minimum components. These basic projects with components are helpful to learn using sensor based logic.

---

<div class="post-metadata">

**Author:** ![LarryD](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/larryd/32/215550_2.png) [@LarryD](https://forum.arduino.cc/u/LarryD)\
**Post date:** [January 30, 2022, 11:26pm UTC](https://forum.arduino.cc/t/modify-this-code/953425/2 "2022-01-30T23:26:03Z")

</div>

What code ?

When was the assignment given to you ?

---

<div class="post-metadata">

**Author:** ![anon57585045](https://avatars.discourse-cdn.com/v4/letter/a/ed8c4c/32.png) [@anon57585045](https://forum.arduino.cc/u/anon57585045)\
**Post date:** [January 30, 2022, 11:33pm UTC](https://forum.arduino.cc/t/modify-this-code/953425/4 "2022-01-30T23:33:22Z")

</div>

This is probably part of the same assignment:  
[https://forum.arduino.cc/t/help-turning-a-motor/953416](https://forum.arduino.cc/t/help-turning-a-motor/953416)

---

<div class="post-metadata">

**Author:** ![anon47908823](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@anon47908823](https://forum.arduino.cc/u/anon47908823)\
**Post date:** [January 30, 2022, 11:47pm UTC](https://forum.arduino.cc/t/modify-this-code/953425/5 "2022-01-30T23:47:03Z")

</div>

Sorry I forgot the actual code. I edited the message, there you go.

---

<div class="post-metadata">

**Author:** ![Paul\_B](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/paul_b/32/216376_2.png) [@Paul\_B](https://forum.arduino.cc/u/Paul_B)\
**Post date:** [January 31, 2022, 1:18am UTC](https://forum.arduino.cc/t/modify-this-code/953425/6 "2022-01-31T01:18:32Z")

</div>

> [@anon47908823](#):
>
> I edited the message, there you go.

Yes, but did not provide the code. 🙄

Perchance read the [instructions for posting](https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum/679966#posting-code)?

---

<div class="post-metadata">

**Author:** ![johnwasser](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/johnwasser/32/214270_2.png) [@johnwasser](https://forum.arduino.cc/u/johnwasser)\
**Post date:** [January 31, 2022, 4:18pm UTC](https://forum.arduino.cc/t/modify-this-code/953425/7 "2022-01-31T16:18:12Z")

</div>

```cpp
const byte RedLEDPin = 2;
const byte GreenLEDPin = 3;
const byte BlueLEDPin = 4;

void setup()
{
  Serial.begin(115200);

  pinMode(RedLEDPin, OUTPUT);
  pinMode(GreenLEDPin, OUTPUT);
  pinMode(BlueLEDPin, OUTPUT);
}

void loop()
{
  int sensorReading = analogRead(A0);
  Serial.println(sensorReading);

  if (sensorReading >= 1000)
  {
    digitalWrite(RedLEDPin, HIGH);
    delay(1000);
    digitalWrite(RedLEDPin, LOW);

    digitalWrite(GreenLEDPin, HIGH);
    delay(1000);
    digitalWrite(GreenLEDPin, LOW);

    digitalWrite(BlueLEDPin, HIGH);
    delay(1000);
    digitalWrite(BlueLEDPin, LOW);
  }

  delay(500);
}
```

---

<div class="post-metadata">

**Author:** ![anon47908823](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@anon47908823](https://forum.arduino.cc/u/anon47908823)\
**Post date:** [February 1, 2022, 1:48am UTC](https://forum.arduino.cc/t/modify-this-code/953425/8 "2022-02-01T01:48:22Z")

</div>

thank you so much!!!!

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [July 31, 2022, 1:49am UTC](https://forum.arduino.cc/t/modify-this-code/953425/9 "2022-07-31T01:49:22Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
