LED Strip control

Hello,

I am new to Arduino. My goal is to make a project where each button will switch on 10 leds on 5M LED strip. I plant to use 30 buttons. Can somebody, anybody help me.

Below is my sketch........

#include<FastLED.h>

#define NUM_LEDS 300
#define LED_PIN 10


CRGB leds[NUM_LEDS];

//const int buttonPins[] = {1,2,3,4,5};


int buttonstate = 0;
int pinNo;
int dot = 10 * pinNo;

void setup() {
 FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
 FastLED.setBrightness(50);
 for (int pinNo = 0; pinNo < 4; pinNo++){ // sampling 4 buttons
   pinMode(pinNo, INPUT);
   }
// pinMode (buttonPins[i], INPUT);
 
}

void loop() {


buttonSetup();


// for(int a= dot; a< dot+9; a++)
// leds[a]= CRGB::White;
// FastLED.show();

}

void buttonSetup(){

 
buttonstate = digitalRead(pinNo);
 if(buttonstate == LOW)
{
 for(int pinNo= dot; pinNo< dot+9; pinNo++)
 leds[pinNo]= CRGB::White;
 FastLED.show();
}else
if(buttonstate == HIGH)
{
 for(int pinNo=0; pinNo<NUM_LEDS; pinNo++)
 leds[pinNo] = CRGB:: Black;
 FastLED.show();
 }
}
 

 
 

What is the problem?

Welcome to the forum

Which Arduino board will you be using ?

depending a bit on how you wire the switch i would use INPUT_PULLUP

pinMode(pinNo, INPUT_PULLUP);

also this is a poor choice of variable name, that name has been used once already and that it does not cause any issue is fortunate.

for(int pinNo=

I donot understand..

what ?

Please answer questions. Reply #3 and to some extent, reply #2.

Arduino Mega

What's your problem?

I uploaded the code. Nothing happened. But when I upload a single button it works.

Upload what code? The one you posted seems to have a single button...

Is this question really, "I don't even have a faint clue how to code multiple buttons, please show me how to do it"?

Although you could use 30 individual buttons on a Mega it would probably make more sense to use a keypad. Note that the keypad buttons do not have to be physically arranged in rows and columns if you need a different layout

I really want to learn to build this myself. Can you show me what I am getting wrong?

First you have to show us what you are doing. Otherwise you get 30 buttons that aren't the right kind, doing not what you want.

We can't show you what you are doing wrong, because you haven't done anything. :slight_smile:

Look:
https://www.arduino.cc/reference/en/libraries/keypad/

If you mean a picture, all I have is an led strip and a four buttons connect to pull-up resistor. The goal of my project is make an animated led strip with a push button making changes on 10 separated LEDs attached to the same strip. Just working with my imagination. Keypad would pack the entire button in one place. I want the buttons separated with the segmented LEDs to cover the room.

This is sounding singularly dental! :face_with_raised_eyebrow:

As I said before, the buttons in a keypad do not have to be laid out in a row/column layout. It is how they are wired that matters

Ok, so the buttons don't really need pull up resistors if you use the internal pull ups from the mega.
Personally i don't think it makes much sense what you want to do, but hey, if that's what you want to do, let's see if we can manage.

he does have a point there. You've shown us the code that includes a single button, which has commented out sections referring to other buttons.
Set it up for all the button you have at the moment, and please try not to use the same name for different variables.

  • What will that look like according to you ? (post the code)
  • what does that do that it shouldn't and does not do what it should ?
  • How have you wired things up ? Please show us a schematic (not fritzing !)

You are right. It will not work. I will be using the keypad instead.
Some ideas are just ideas...

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