{BEGINNER TO CODING} Need help coding led strips

i am using led strips i purchased off of adafruit they are analog led strips.

i have 3 of these strips connected to a arduino mega but i am just looking to light each strip up a different color one red, one green, one blue. i know this is simple but i cant find code to just light a strip up an individual color. even if you just write the code for one strip to light up a color that should be good enough when i look at the code for led strips with effects like fading in and out it confuses me. thank you to anyone who can help.

The Adafruit site has a nice example: Arduino Code | RGB LED Strips | Adafruit Learning System

hello i am new to electronics and coding and was wondering if anyone can help me with the problem i am having. i am doing a school project where i am programming three led strips to light up but only one will light up at a time and it will be randomly. and then i want to put a touch sensor at each strip so when touched the strip will turn off and a new one will light up. i have code that basically does this....It generates a number 1-100 and numbers 1-33 will turn strip 1 green numbers 34 - 66 will turn strip green and numbers 67-100 will turn strip 3 green. here is the code.

also i used an arduino mega for this project along with some analog rgbw strips i got off of adafruit i will be using a shield for capacitive touch but for right now i need to get the code right with the simple ones.

#define REDPIN 3
#define GREENPIN 4
#define BLUEPIN 2
 
 #define REDPINTWO 8
#define GREENPINTWO 9
#define BLUEPINTWO 7
 
 #define REDPINTHREE 12
#define GREENPINTHREE 13
#define BLUEPINTHREE 11
 
#define FADESPEED 5     
 
void setup() {
  pinMode(REDPIN, OUTPUT);
  pinMode(GREENPIN, OUTPUT);
  pinMode(BLUEPIN, OUTPUT);
  pinMode(REDPINTWO, OUTPUT);
  pinMode(GREENPINTWO, OUTPUT);
  pinMode(BLUEPINTWO, OUTPUT);
   pinMode(REDPINTHREE, OUTPUT);
  pinMode(GREENPINTHREE, OUTPUT);
  pinMode(BLUEPINTHREE, OUTPUT);
}
 
 
void loop() {
 int randomNum = random(1,100); 
 Serial.println(randomNum);

if(randomNum<=33){
  digitalWrite(GREENPIN,255);
  digitalWrite(GREENPINTHREE,0);
  digitalWrite(GREENPINTWO,0);
  delay(3000);
  }

 else if(randomNum>=34 && randomNum<=66){
  digitalWrite(GREENPINTHREE,255);
  digitalWrite(GREENPIN,0);
  digitalWrite(GREENPINTWO,0);
  delay(3000); 
  }

  else {
  digitalWrite(GREENPINTHREE,0);
  digitalWrite(GREENPIN,0);
  digitalWrite(GREENPINTWO,255);
  delay(3000);
    }

  
  
}

so right now it switches strips by by time and i want to use the touch sensors to change the colors. i dont know what the easiest way of doing this would be when i tried to write code it didnt work what so ever. thank you to anyone who can help i hope my description was detailed enough.

Isn't the whole point of a school project like this to learn how to do it yourself, rather than paying other people to do it for you?

if someone shows me how to do it then i wont need to ask next time i need to do something like this. i dont want to pay someone to do it for me i want someone to explain how to do it so i can learn how to do it. i would post it in the coding section of the forum but whenever i post questions in there they tell me to post it here.

This belongs in "project guidance" rather than "gigs & collaborations" which is for paid jobs.

For your code:

First of all I suggest you to put the pins in arrays, then take a random number 0-2, and light the strip with the number chosen. That makes it a lot easier already, as you can simply use the number chosen as index for the strip to light. Like this:

const byte redLED[3] = {2, 3, 4};

void loop() {
  byte strip = random(0, 2);
  for (byte i = 0; i++; i < 3) {
    digitalWrite(redLED[strip], (strip == i) ? HIGH : LOW);
  }
  delay(3000);
}

Just set your pin numbers and add the other two strips and this does the same as your code.

Line 6 sets the pins of all the three strips, as the other two have to be switched off of course.

Now the tricky bit: the change upon touch.

  1. build a touch sensor.
  2. get it to work: upon touch, just print the message "touched" (this will be the hardest part).
  3. take a new random number upon touch and set the LEDs again (quite trivial).

i recently posted this in the gigs and colaborations section but it was the wrong section to post it in. someone who i am very grateful for sent me this code which basically says pick a random number 1-3 and light one of the strips up green and it cycles randomly. i just need to tell it to wait until the touch sensor is touched to change colors here is the code so far.

const byte greenLED[3] = {4, 8, 12};
const byte touchPin[1] = {9};
 

void setup() {
     pinMode(4, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(12, OUTPUT);
pinMode(touchPin, INPUT);
  
}

void loop() {
     
     int touchValue = digitalRead(touchPin);
     
     byte strip = random(3);
  
  
     for
    (byte i = 0; i++; i < 3){
    digitalWrite(greenLED[strip], (strip == i) ? HIGH : LOW);
  
     }
   
   
}

i tried putting in a do while but then i cant get the code to compile. if anyone could help i would greatly appreciate it i am new to coding.

Original thread was moved already. No need to start again.

wvmarle made the most important suggestion.

Break your code into functions.
Get each piece of the project working by itself - only then plug the pieces of code together.

  • Wiring - check that you have that all sorted - including adequate power supply
  • Get the LEDs working - so you can control whatever functionality you need,
  • Touch sensing - one first, test with serial (no LEDs) - you will eventually have three sensors?
  • Random number selection from a touch event.
  • Tie the touch+random number to set the LEDs the way you need them

Three threads merged.