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 no translation for that post!




Marshmello Helmet C...
 
Share:
Notifications
Clear all

[Solved] Marshmello Helmet Code

13 Posts
3 Users
0 Likes
2,734 Views
(@ronnieblaze)
Active Member
Joined: 5 years ago
Posts: 7
Topic starter  

I have built and wired all the leds for a Marshmello helmet. I found the code below but the original author made it for a 12 x 54 matrix. My current setup has more rows. So would it be possible to keep the effect and remove the matrix part of the code?

Here is a youtube link to see the code in action.

https://youtu.be/goOs4tyvBH4?t=210


   
ReplyQuote
(@ronnieblaze)
Active Member
Joined: 5 years ago
Posts: 7
Topic starter  
If this helps, this is how it looked.  This was my first version. and i lost the code for this one. 

   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2663
 

Hi RonnieBlaze!

Wow, nice job! 

I assume this is what you mean; replace the XY function for something easier and more flexible?
I'm not sure if the XY function (with huge array) is the most efficient way to do this - calculate XY instead of looking it up.

Just taking a stab at it, untested since I do not have a matrix of LEDs available at the moment.

I replaced some of the constants with defines as well (should be more memory efficient) - I hope I'm, not overlooking something here, since I do not fully understand why there was an array created. There could be a very good reason for that though, I'm just not seeing it (I may need more coffee since it's still early in the morning  ).

// Params for width and height
#define kMatrixWidth = 54;
#define kMatrixHeight = 12;
#define NUM_LEDS (kMatrixWidth * kMatrixHeight)
#define LAST_VISIBLE_LED NUM_LEDS-1
CRGB leds[ NUM_LEDS ];
uint16_t XY (uint16_t x, uint16_t y) {
  if ( (x >= kMatrixWidth) || (y >= kMatrixHeight) ) {
    return (LAST_VISIBLE_LED + 1);
  }
  return (y*kMatrixWidth)+x-1;
}

Since you're using FastLED, you can replace all showStrip() calls with FastLED.show() - this way you will not need the definition of the showStrip() function.
For this reason you can also get rid of the setPixel() function and replace calls like

setPixel(i,red,green,blue);

with

leds = CRGB( red,green,blue);

You can also remove the function setAll()  since it's not being used (you're using the better fill_solid() function). 

I also did some cleanup of the code, I personally prefer to see setup() and loop() first, and "helper" functions at the end.
I did remove some of the global variables (I try to use those as little as possible), and replaced some of the "while" loops with "for" loops.
You're referring to the "leds" array by address of the first LED (leds[0]), which should not be needed and can be done by just using "leds".

Apologies for taking the liberty to make a few changes - not trying to be a smart ass, it just helps me read the code. 
Of course, this code should be tested to see if everything still works as before - which I can't since I don't have a matrix available. The code does compile properly though.
Since the your previous code took way too much memory for my Arduino Uno, you may like the outcome of the modified code. It still takes up quite a bit of the dynamic memory (only 16 bytes left), but the previous code actually ran 1280 bytes short on memory (I suppose this is why you were asking?).

For comparison, the old code:

Sketch uses 4320 bytes (13%) of program storage space. Maximum is 32256 bytes.
Global variables use 3328 bytes (162%) of dynamic memory, leaving -1280 bytes for local variables. Maximum is 2048 bytes.
Not enough memory

and the new code:

Sketch uses 2894 bytes (8%) of program storage space. Maximum is 32256 bytes.
Global variables use 2032 bytes (99%) of dynamic memory, leaving 16 bytes for local variables. Maximum is 2048 bytes.
Low memory available, stability problems may occur.

All this results in:

// Modified V2 Mello Head
#include "FastLED.h"
// Params for width and height
#define kMatrixWidth 54
#define kMatrixHeight 12
// LED strip PIN
#define PIN 2 
// Number of LEDs
#define NUM_LEDS (kMatrixWidth * kMatrixHeight)
// FastLED LEDs array
CRGB leds[ NUM_LEDS ];
// Global variable for Hue (for functions that use this)
byte cycleHue = 0;

void setup()
{
  FastLED.addLeds<WS2811, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
}
void loop() {
  FastLED.setBrightness(50);
  //myLights();
  slantBars();
   
  // AllRunningLights();
  // FastLED.setBrightness(50);
  // FlashLights();  
}
void slantBars() {
  static byte slantPos = 0;
  for (byte x = 0; x < kMatrixWidth; x++) {
    for (byte y = 0; y < kMatrixHeight; y++) {
      leds[XY(x, y)] = CHSV(cycleHue, 255, quadwave8(x * 32 + y * 32 + slantPos));
    }
  }
  slantPos -= 4;
}
void RunningLights(byte red, byte green, byte blue, int WaveDelay) {
  int Position = 0;
  int myCounter = 0;
    
  for(int i=0; i<NUM_LEDS*3; i++)
  {
    if(myCounter<6) {
      Position++; // = 0; //Position + Rate;
      for(int i=0; i<NUM_LEDS; i++) {
        // sine wave, 3 offset waves make a rainbow!
        //float level = sin(i+Position) * 127 + 128;
        leds = CRGB( 127, 127, 127);
        float level = sin(i+Position) * 127 + 128;
        leds = CRGB( ((sin(i+Position) * 127 + 128)/255)*red,
                        ((sin(i+Position) * 127 + 128)/255)*green,
                        ((sin(i+Position) * 127 + 128)/255)*blue );
      }
      
      FastLED.show();
      myCounter++;
    } 
    else { 
      return; 
    }
  }
}
void AllRunningLights() {
   for(int myCounter = 0; myCounter<5; myCounter++) {
      RunningLights(0x00,0x80,0xff, 10);
      RunningLights(0xEE,0x00,0xEE, 10);
      RunningLights(0xff,0xff,0xff, 10);
      RunningLights(0xff,0x70,0x00, 10);
      RunningLights(0xff,0x10,0x10, 10);
      RunningLights(0x26,0xff,0x00, 10);
   } 
   return;
}
void myLights() {
   fill_solid( leds, NUM_LEDS, CRGB( 0, 128, 255) ); //1
   FastLED.show();
}

void FlashLights() {
   for(int myCounter=0; myCounter<10; myCounter++) {
  
     fill_solid( leds, NUM_LEDS, CRGB( 0, 128, 255) ); //1
     FastLED.show();
     delay(100);
     fill_solid( leds, NUM_LEDS, CRGB( 0, 0, 0) );
     FastLED.show();
     delay(40);
     fill_solid( leds, NUM_LEDS, CRGB( 238, 0, 238) ); //2
     FastLED.show();
     delay(100);
     fill_solid( leds, NUM_LEDS, CRGB( 0, 0, 0) );
     FastLED.show();
     delay(40);
     fill_solid( leds, NUM_LEDS, CRGB( 255, 255, 255) ); //3
     FastLED.show();
     delay(100);
     fill_solid( leds, NUM_LEDS, CRGB( 0, 0, 0) );
     FastLED.show();
     delay(40);
     fill_solid( leds, NUM_LEDS, CRGB( 255, 112, 0) ); //4
     FastLED.show();
     delay(100);
     fill_solid( leds, NUM_LEDS, CRGB( 0, 0, 0) );
     FastLED.show();
     delay(40);
     fill_solid( leds, NUM_LEDS, CRGB( 255, 16, 16) ); //5
     FastLED.show();
     delay(100);
     fill_solid( leds, NUM_LEDS, CRGB( 0, 0, 0) );
     FastLED.show();
     delay(40);
     fill_solid( leds, NUM_LEDS, CRGB( 38, 255, 0) ); //6
     FastLED.show();
     delay(100);
     fill_solid( leds, NUM_LEDS, CRGB( 0, 0, 0) );
     FastLED.show();
     delay(40);
   } 
   
   return;   
}
// Convert X,Y to actual LED location
uint16_t XY (uint16_t x, uint16_t y) {
  if ( (x >= kMatrixWidth) || (y >= kMatrixHeight) ) {
    return (NUM_LEDS);
  }
  return (y*kMatrixWidth)+x-1;
}
// Increment the global hue value for functions that use it
void hueCycle(byte incr) {
    cycleHue+=incr;
}

I've attached the INO file as well, and hope this is what you were looking for.
And I hope I didn't ruin the code 

Let me know if it works as before (or not) and feel free to ask questions if you have any.


   
ReplyQuote
(@ronnieblaze)
Active Member
Joined: 5 years ago
Posts: 7
Topic starter  

Hi Hans,

Thank you for looking at the code and cleaning it up.  I am having a problem getting it to run but I am starting to think that could be because I am currently using a Wemos D1 R2 mini pro and not a Arduino uno/mega/ETC.

In my continued search for trying to find the original code that i ran on a uno,  I do believe i finally found it (attached). But i do not have my uno to test it..  It is with a friend that is doing all the led strip soldering for me, so he can test the strips as he goes.

The code is based on the Running Lights effect, So I am really not sure why it does not want to work.


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2663
 

Hi RonnieBlaze,

Can you tell me what is happening when you run the code? (in comparison with your code that you posted initially)
Do you see error messages? Or very odd behavior?

I'd recommend testing with an Arduino Uno first - so you get more familiar with the Arduino's. Then later when you migrate to another board, at least you can see that the code is supposed to work and that code made need some adaptation for that specific board.

As I do not have a Wemos available, I wouldn't know what kind of issue you may or may not run into.
When looking at some bare minimum info I found online; there may be an issue with the PIN layout (compared to the Uno, you may have to choose different pins) and the available voltage on the board (3.3V vs 5V - your LED strip most likely wants 5V, where as your board may only provide 3.3V for the LED strip data pin).


   
ReplyQuote


(@ronnieblaze)
Active Member
Joined: 5 years ago
Posts: 7
Topic starter  

Hans,

Visually it looks to be running faster.  The leds that are moving seem to be going 2 or 3 times faster they are almost a blur when moving. And I agree i need to wait until i get my uno back from my friend so i can flash the same code to both controllers and look at the difference.

The main look i would like to achieve is similar to Theatre Chase ( https://www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/#LEDStripEffectTheatreChase) but with 4 leds on the middle 2 being brighter then the ones on the end, and a 4 led spacing to the next group (example below), having them scroll for a bit then have a random color change.  I will work with your Theatre Chase sample code and see what if anything i can get working.

xXXx----xXXx----xXXx----xXXx----xXXx


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2663
 

Ah OK, well, running too fast shouldn't be a problem (and I did optimize a few things, so that could be why).
You could try adding a short delay after each FastLED.show();. something like this:

FastLED.show();
delay(20);

Assuming you run the code that I modified.


   
ReplyQuote
(@cacapeepee)
New Member
Joined: 4 years ago
Posts: 3
 

ronnieblaze, 

hi i am currently trying to build my mello head but im having trouble getting the code even run into the leds. I can get the strand test to work and it works good but when i try to get the mello code to run it gets and error. can you help me? im in desperate need of help


   
ReplyQuote
(@ronnieblaze)
Active Member
Joined: 5 years ago
Posts: 7
Topic starter  

I gave up trying to get the "mello code" to work,  it only had the one pattern to it, I have since changed using a UNO to using a LOLIN D1 mini Pro V2.0.0 running WLED

The wemos d1 has more memory then the UNO does, it has wireless and it is alot smaller.  Since changing to the WLED it has alot of different patterns and palettes all buit in to it that i can change on the fly from my phone.


   
ReplyQuote
(@cacapeepee)
New Member
Joined: 4 years ago
Posts: 3
 

Wow thanks for the fast reply!
did you get too wiring the helmet?
I haven't started I have a 10 inch acrylic cylinder ( im making for my son for halloween) I wanted to see if you can give me advice or tips on how to wire it?


   
ReplyQuote


(@ronnieblaze)
Active Member
Joined: 5 years ago
Posts: 7
Topic starter  

If you have not seen this video i would highly recommend you watch it. I made mine basically the same way he did. I used a 12" concrete cardboard tube as the insert. It was a pain sizing it since it was way bigger then 12".  You just have to give your self extra spacing for the lights.

https://www.youtube.com/watch?v=URAbwZQuRxc


   
ReplyQuote
(@cacapeepee)
New Member
Joined: 4 years ago
Posts: 3
 

thanks! I've seen the video before but, I want the least amount of weight for my son so i'm going the super gluing the leds to the cylinder route.

what about the eye holes what did you use to cover them?


   
ReplyQuote
(@ronnieblaze)
Active Member
Joined: 5 years ago
Posts: 7
Topic starter  

for the eyes i used a thin sheet of petg

and tinted it with this, you could just use normal window tint also


   
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: