Multiple led strips and a button

Hello guys, I'm a design student and totally new to this and very bad at coding for now. So my project is a lamp and it consists of 3 different length and different color neopixel strips, 3 same color single neopixel leds and a touch sensor. The sensor has to control everything: one touch turns on the strips, two touches turn on the single leds and a long touch turns everything off. I have a sort of working code, but it only turns on one strip and turns it off after a while, I need the leds to work until they are turned off. I hope my explanation is clear enough. I tried to do it by myself but it proved useless. I would be insanely thankful if you could help.
This is the code that I have:

#include <Adafruit_NeoPixel.h>
#define PIN 3
#define NUMPIXELS 22
int touch = 8;  
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int delayval = 50; 



void setup() {
  pixels.begin();
  Serial.begin(9600);
  pinMode(touch, INPUT);
#if defined(__AVR_ATtiny85__) && (F_CPU == 160000000000000)
  clock_prescale_set(clock_div_1);
#endif
  pixels.begin(); 
}



void loop() {

   pixels.clear(); 
  int touchValue = digitalRead(touch);
  if (touchValue == HIGH){
    Serial.println("touched");
    for(int i=0; i<NUMPIXELS; i++) { 
      pixels.show();   
  for(int i=0;i<NUMPIXELS;i++){
    pixels.setPixelColor(i, pixels.Color(200,0,95)); 
    pixels.show(); 
    delay(delayval); 
   }

   }
   
   }else{
    
    Serial.println("not touched");
     for(int i=0; i<NUMPIXELS; i++) {
  
      pixels.setPixelColor(i, pixels.Color(0, 0, 0));
  
      pixels.show();   
  
    }
  }
  delay(10);

}

Strip one is connected to pin 3 and has 22 leds
Strip two is connected to pin 5 and has 36 leds
Strip three is connected to pin 6 and has 53 leds
Single led one is connected to pin 9
Single led two is connected to pin 10
Single led three is connected to pin 11
The button is pin 8

:astonished:

160,000,000,000,000

160000000 megahertz

Must be a knew chinese knock off

I wasn't even sure what that meant, you see, I found two working codes online (the strip code and the button code) and combined them, it worked so I went with it. Now I just reached a standstill. Like I said, a complete beginner, sorry :smiley:

The members said that the frequency in your code do not looks realistic. Where do you find it?

What do you expecting from the forum?

Your code is very far from what you described in the post #1. You want to connect and manage 6 different strips or leds, and right now there is only one in the code.
If you have a specific questions - forum can help you, but do not expect that someone will write code for you.

You can make the code easier to read by using ctrl-T in the IDE to auto format the code. Then the indentation follows a standard pattern that people find much easier to follow.

void loop() {
  pixels.clear();
  int touchValue = digitalRead(touch);
  if (touchValue == HIGH) {
    Serial.println("touched");
    for (int i = 0; i < NUMPIXELS; i++) {
      pixels.show();
      for (int i = 0; i < NUMPIXELS; i++) {
        pixels.setPixelColor(i, pixels.Color(200, 0, 95));
        pixels.show();
        delay(delayval);
      }
    }
  } else {
    Serial.println("not touched");
    for (int i = 0; i < NUMPIXELS; i++) {
      pixels.setPixelColor(i, pixels.Color(0, 0, 0));
      pixels.show();
    }
  }
  delay(10);
}

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