Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is most likely no translated for the post!





Struggling with my ...
 
Share:
Notifications
Clear all

Struggling with my LED-Matrix (Trollo_meo)


 Hans
(@hans)
Noble Member Admin
Joined: 8 years ago
Posts: 1758
Topic starter  

Moved to the forum, from this comment.

Original question:


 

Hey it’s me again

I’m struggling once again with my LED-Matrix….

I’ve made big changes to my source code…

1. I’m using different switches now

2. I’m having an active low circuit 

3. I kicked out some projects

Now I’m running in a new problem…

My project wasn’t working so I started with a program which was (it was the funmode)

The program uses the Neopixel Library.

I got everything to work and I wanted to slowly add the other programs.

With the Twinklerandom from this page I started to struggle…. (It’s the “Random Color Twinkle” Programm from this page)

The Twinklerandom was working well but the other wasn’t…

I found out that it was cuz one variable was too big…

It’s the NUM_LED’s variable that I use in the Twinklerandom function.

Now I’m having the problem that I can only run this program with 193 LED’s and not with the 340 that I have in my LED strip.

Am I missing an important point?

This isn’t my full code I was focussing on 2 Programs and add another one when these r working fine. And continue with that till I have all my projects in the programm.

 

Code:

//includes
#include <Adafruit_NeoPixel.h> //Funmode
#include "FastLED.h" //Aufblinken
//defines
#define PIN 6
#define DATA_PIN 6
#define NUM_LEDS 193
//Funktion-Initialisierung
void funmode();
//void TwinkleRandom(int, int, int, boolean);
//Eingangspins
int aufblinkeneinput = 11;
int funmodeinput = 9;
//andere
CRGB leds[NUM_LEDS];
Adafruit_NeoPixel strip = Adafruit_NeoPixel(340, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
  strip.begin();
  strip.show();
  Serial.begin(9600);
  LEDS.addLeds<NEOPIXEL,DATA_PIN>(leds,NUM_LEDS);
  
  //Eingangspins als INPUT definieren
  pinMode(aufblinkeneinput, INPUT);
  pinMode(funmodeinput, INPUT);
}
void loop() {
  if(digitalRead(aufblinkeneinput) == LOW) {
    TwinkleRandom(1800,100,150,false);
  }
  if(digitalRead(funmodeinput) == LOW) {
    funmode();
  }

//Hauptfunktion im Loop
//1. Aufblinken
void TwinkleRandom(int Count, int SpeedDelay, int fadespeed, boolean OnlyOne) {
  setAll(0,0,0);
  for (int i=0; i<Count; i++) {
    fadeall(fadespeed);
    setPixel(random(NUM_LEDS),random(0,255),random(0,192),random(0,128));
    showStrip();
    delay(SpeedDelay);
    if(OnlyOne) { 
      setAll(0,0,0); 
    }
  }
// delay(SpeedDelay);
}
//3. Funmode
void funmode() {
    // Some example procedures showing how to display to the pixels:
  colorWipe(strip.Color(255, 0, 0), 50); // Red
  colorWipe(strip.Color(0, 255, 0), 50); // Green
  colorWipe(strip.Color(0, 0, 255), 50); // Blue
  // Send a theater pixel chase in...
  theaterChase(strip.Color(127, 127, 127), 50); // White
  theaterChase(strip.Color(127, 0, 0), 50); // Red
  theaterChase(strip.Color( 0, 0, 127), 50); // Blue
  rainbow(20);
  rainbowCycle(20);
  theaterChaseRainbow(50);
}



//Deklaration der Hauptfunktionen

//1. Aufblinken
void setPixel(int Pixel, byte red, byte green, byte blue) {
  leds[Pixel].r = red;
  leds[Pixel].g = green;
  leds[Pixel].b = blue;
}
void setAll(byte red, byte green, byte blue) {
  for(int i = 0; i < NUM_LEDS; i++ ) {
    setPixel(i, red, green, blue); 
  }
  showStrip();
}
void showStrip() {
  FastLED.show();
}
void fadeall(int scale) { for(int i = 0; i < NUM_LEDS; i++) { leds[i].nscale8(scale); } }

//3. Funmode
// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, c);
      strip.show();
      delay(wait);
  }
}
void rainbow(uint8_t wait) {
  uint16_t i, j;
  for(j=0; j<256; j++) {
    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i+j) & 255));
    }
    strip.show();
    delay(wait);
  }
}
// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
  uint16_t i, j;
  for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
    for(i=0; i< strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
    }
    strip.show();
    delay(wait);
  }
}
//Theatre-style crawling lights.
void theaterChase(uint32_t c, uint8_t wait) {
  for (int j=0; j<10; j++) { //do 10 cycles of chasing
    for (int q=0; q < 3; q++) {
      for (int i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, c); //turn every third pixel on
      }
      strip.show();
      delay(wait);
      for (int i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, 0); //turn every third pixel off
      }
    }
  }
}
//Theatre-style crawling lights with rainbow effect
void theaterChaseRainbow(uint8_t wait) {
  for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel
    for (int q=0; q < 3; q++) {
        for (int i=0; i < strip.numPixels(); i=i+3) {
          strip.setPixelColor(i+q, Wheel( (i+j) % 255)); //turn every third pixel on
        }
        strip.show();
        delay(wait);
        for (int i=0; i < strip.numPixels(); i=i+3) {
          strip.setPixelColor(i+q, 0); //turn every third pixel off
        }
    }
  }
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  if(WheelPos < 85) {
   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else {
   WheelPos -= 170;
   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}

ReplyQuote
Topic Tags
 Hans
(@hans)
Noble Member Admin
Joined: 8 years ago
Posts: 1758
Topic starter  

So what I understand from your question is that this function works with 193 LEDs but not with 340 ...?

void TwinkleRandom(int Count, int SpeedDelay, int fadespeed, boolean OnlyOne) {
setAll(0,0,0);
for (int i=0; i<Count; i++) {
fadeall(fadespeed);
setPixel(random(NUM_LEDS),random(0,255),random(0,192),random(0,128));
showStrip();
delay(SpeedDelay);
if(OnlyOne) {
setAll(0,0,0);
}
}
// delay(SpeedDelay);
}

I'll just go through my usual thinking process here;

  1. Form what I could find in the Arduino reference (random()), it takes a "long" datatype, which is a 32bit number and has a range from -2,147,483,648 to 2,147,483,647. I'd say sufficient for your purposes. 😊 
  2. The function setPixel() takes and integer, which worse case would have a range of -32,768 to 32,767, still enough for 340 LEDs. 👍 
  3. NUM_LEDS is actually not a variable, it is a "define" which basically means that wherever you have "NUM_LEDS" in the code, the compiler will replace that text with the defined number (eg. 193 or 340) before it actually compiles the code. So it is not limited by anything. 👍 

While going through the code (with steps 1, 2, and 3) I did notice how the function setPixel was defined.
I think in your code, the setPixel function is using the code for the FastLED library and not for NeoPixel.

The function for NeoPixel should be:

void setPixel(int Pixel, byte red, byte green, byte blue) {
   strip.setPixelColor(Pixel, strip.Color(red, green, blue));
 }

Or maybe even better change all references to setPixel to setPixelColor.
For example:

void TwinkleRandom(int Count, int SpeedDelay, int fadespeed, boolean OnlyOne) {
setAll(0,0,0);
for (int i=0; i<Count; i++) {
fadeall(fadespeed);
setPixelColor(random(NUM_LEDS),random(0,255),random(0,192),random(0,128));
showStrip();
delay(SpeedDelay);
if(OnlyOne) {
setAll(0,0,0);
}
}
// delay(SpeedDelay);
}

Maybe this is the culprit?


ReplyQuote

Like what you see and you'd like to help out? 

The best way to help is of course by assisting others with their questions here in the forum, but you can also help us out in other ways:

- Do your shopping at Amazon, it will not cost you anything extra but may generate a small commission for us,
- send a cup of coffee through PayPal ($5, $10, $20, or custom amount),
- become a Patreon,
- donate BitCoin (BTC), or BitCoinCash (BCH).

Share: