-
-
I'm in the process of trying to make an LED coat like this one for a party next week. I'm driving 500 WS2811s with this poor little espruino pico because it's all I've got right now. I have no issues with powering them all, I have that figured out. What I am struggling with is generating the patterns. Too much math is happening to push out 3*500 random numbers to make the LED light change snappy. Basically it's a slideshow. It all works fine, just slow as hell.
What I want to do is either output a 25 light pattern x 20, but I can't figure out how (or if its even possible).
Anyone have any advice on how to do it? I thought about concatenating the array into a larger array (thus saving a bunch of math steps), or just trying to output the same array multiple times in one go using require("neopixel").write but cant seem to make it happen.
If there is no solution, I'll just use static patterns, but it would be cool for them to be animated.
Pic attached for desired outcome.
-
I guess I'll post this for others to find since I figured it out as I was making this post.
So despite making sure I don't execute at boot event after reset, I couldn't seem to clear my code from flash without doing E.setBootCode() which I understand might be problematic if my code crashes.
I solved the problem by re-flashing the firmware and it seems to have fixed it.
-
Sorry, been out of town for a bit. I will clarify the situation here and in the OP. The power is fine for I would say somewhere in the 24 hour range. I tested it friday eve, then Sat aft it didn't work anymore. I had been having ongoing issues with power drain for a while, so I figured it must be the LEDs. The main issue is that when I leave things on the power drained even though there was no real appearance of activity.
As allObjects indicated above this would be consistent with the LEDs draining it at 300mah. Past certain point it doesn't work anymore.
I don't need to turn more than 10 on at any time, so I don't need more than 4xAAs. Because I'm using garbage batteries, voltage output is about 5v, so its fine for the WS2812Bs. I prefer AAs vs. custom battery pack because I don't want to charge the thing all the time, I want to be able to swap out AAs and drive on. (its for a game).
It seems like the relay is the answer at this point.
I'll post process.env to satisfy your curiosity tomorrow night!
-
-
I am using an Espruino to run a project with 3 buttons and an LED light strip. One of the buttons increases an led light position by flashing the next light on the strip. The other decreases an led light position by flashing the next light on the strip in an opposite direction, and the last button randomly illuminates 10 lights between the first light and the current position for a minute or two. Unless a button was recently pressed all lights should be off. The project is powered by 4x AA batteries.
And everything works great, except for some reason, the battery dies after an hour or two even if the lights are off. I'm guessing I'm failing to implement deep sleep properly. As far as I can guess I am not violating any of the 5 conditions in any way that deep sleep should not execute eventually.
So why is this happening? I've included my code below. Also deepest apologies for my shitty code. I'm not a coder or anything, I just made it work.
Goes without saying a simple on/off switch would solve the problem but I have one, and I keep forgetting to turn it off so I'd love a software solution.
var rgb = new Uint8ClampedArray(300*3); var rando = new Uint8ClampedArray(10); //array to store 10 random numbers var position = 200; var k = 0; var pos = 0; //Add function digitalWrite(B7,1); pinMode(A8, "input_pulldown"); setWatch(function() { doAdd(); }, A8, { repeat: true, debounce : 100, edge: "rising" }); //Subtract function digitalWrite(B3,1); pinMode(B3, "input_pulldown"); setWatch(function() { doSub(); }, B3, { repeat: true, debounce : 100, edge: "rising" }); //Random function digitalWrite(B4,1); pinMode(B5, "input_pulldown"); setWatch(function() { doRand(); }, B5, { repeat: true, debounce : 100, edge: "rising" }); function setPosition() { pos = (position*3)+2; rgb[pos] = 10; } function doAdd() { position++; doPosition(); setDeepSleep(1); } function doSub() { if (position > 20) { position--; } doPosition(); setDeepSleep(1); } function doPosition() { setPosition(); require("neopixel").write(B15, rgb); k = setTimeout (doOff,300); } function onInit() { doOff(); } function setOff() { for (var i=0;i<rgb.length;i+=3) { rgb[i ] = 0; rgb[i+1] = 0; rgb[i+2] = 0; } } function doOff() { setOff(); require("neopixel").write(B15, rgb); setDeepSleep(1); } function setRand() { setOff(); var colourio = 0; for (var i=0;i<rando.length;i++) { //puts data into rando array rando[i] = parseInt(Math.random()*(position+1)); //put a random number into one of the array positions if (i>0){ for (var t=0; t<i; t++) { //checks to see if the LED has been selected randomly if (rando[i] == rando[t]){ i=i-1; } } } } rando.sort(function(a, b) { return a - b; }); console.log(rando); console.log(position); for (var w=0;w<rando.length;w++) { pos = (rando[w]*3); rgb[pos] = 10; } setDeepSleep(1); } function doRand() { clearTimeout(); k = 0; setRand(); require("neopixel").write(B15, rgb); k = setTimeout (doOff,120000); } onInit();
-
Yeah I considered adding animations to the randomizer function. It's just flair really so not worth the effort right now, but I'm going to make it so I can connect a cable to the prototype so if I want to mess with the code I can.
There's not really any value to adding a screen as the game keeps track of all the stuff itself, but if we really wanted to go crazy at some point you could load a thing that keeps track of the expansions so you can manually select/deselect them (or random decks) and make it fully customizeable.
I thought about making it sellable at some point (have to make one first), but I've kinda missed the boat. The game peaked years ago, so its more of a niche thing, mainly for myself, because card storage and selection is REALLY inefficient as a whole and takes up about 25% of playtime I would say.
-
Sorry for the disappearing act, I was otherwise engaged.
So I'm using 3x AAs which provide 4.5 volts, more than enough to do the job. The way I have it configured now, 10x LEDs light up for 1 minute in their random configuration. When increasing or decreasing the total number of LEDs, one LED illuminates for 500ms.
The big picture project is to build a modular deck holder for the Dominion game to hold all the cards for all the random expansions, and based on the number of decks, (which is changed by adjusting the "max" number of leds using +/- buttons in the diagram below) randomly select 10 decks and display those lights on for 60 seconds, allowing you to pull the decks out of the box.
So now I have the electronics but, I actually need to build the holder. With even as little as 3 hours of functional power, that means over 180 randoms +/-. I doubt I will play 180 games in a year, so it meets my needs. Also, I am only outputting at 20 out of 255, so I'm assuming the reduced brightness will also prolong the battery. I'm fairly confident that 3AA should last me one or more years assuming the batteries are not hot garbage. With rechargeable, the brightness may be lower but still good.
And to answer questions, ref: limitations, obviously has to be portable, and I want the batteries to be easily replaceable.
I'm fairly confident that the current setup and code work to my requirements.
Cross posted from my other thread:
Imagine the black bars being full slots in a holder, and the white bars being empty slots, that could be filled.[+] increases the length of the strip flashing the next light in the strip to show where the "max" is at for the random (green dot in this case).
[-] decreases the length of the strip as per above.
[rnd] lights up 10x random "full" slots (cyan dots as an example) for 1 minute. If you press the button again, it lights up a new random 10 lights for 1 minute.
-
Good point on the data sheet. I guess that makes the most sense. The issue applied on both with USB + battery and just battery pack. The working version does not use pinMode(B15,"af_opendrain").
My programming background is basically VB in HS, some random C/C++/C# and excel macros, so hardly a pro. Just a baseline knowledge to make things happen.
Either way, after overcoming the issue above, I have actually completely finished (the electronics part anyways) my project, and a aside from a brief flash at startup as it conducts onInit() and blacks everything out, which ultimately confirms that its turning on, it works perfectly.
Now for the frigging 100 hours of 3d printing the pieces its going into.
-
Alright I've got it all figured out. For whatever reason, (either by design or by fluke) my strip defaults to on, so on init I need to turn everything off before doing things off the battery pack. The reason is the draw is too high which makes the lights appear to be out or red when on. I anticipated this, but I did not anticipate the lights to be on by default. Here is how I executed the code to turn everything off, so I could then start turning what I want on:
var rgb = new Uint8ClampedArray(300*3); function setOff() { for (var i=0;i<rgb.length;i+=3) { rgb[i ] = 0; rgb[i+1] = 0; rgb[i+2] = 0; } } function doOff() { setOff(); require("neopixel").write(B15, rgb); } function onInit() { doOff(); } onInit();
Wiring as per below. Moving the resistor also had an effect on how strong the lights that I wanted to turn on would be when I wanted them on.
I can now turn the lights on at will. Big success.
Thanks again for everyone's help.
-
That's right. It is one whole strip. zig zagging through the assembly.
Ultimately 3 functions. One to increase the number (ideally illuminating the light its at), one to reduce the number (illuminating the spot its at) and one to generate a random 10 numbers up to and including where its at and leave them on for 3 mins.
Its pretty straightforward (I think)
-
I made a huge step. So all the lights go on by default, but I can turn them off manually with require("neopixel").write(B15, [0,0,0]); I can also turn specific ones on in correct colour combos. ALSO, the reddish colour is definitely due to voltage drop.
I just don't know why it all defaults to but hey that's a start. The resistor and using the 3.3v output was the issue.
-
Ok, so I've made some interesting progress.
I have discovered that the whole strip lights up, but when connecting the 5v line from the strip to the 3.3v out on the Pico, and execute the following code:
require("neopixel").write(B15, [255,0,0, 0,255,0, 0,0,255]);
Those pixels go very dim but turn the required colour. The remainder of the lights stay on in a redish colour (which I assume is due to voltage drop but would otherwise I assume, be white).
Its almost like its wired in revers but I have checked the hell out of things so I am fairly confident.
In response to your questions:
1) Tutorial: http://www.espruino.com/Individually+AddÂressable+LEDs
2) Literally: just working with the line above -
No way more simple than that. See graphic below.
Imagine the black bars being full slots in a holder, and the white bars being empty slots, that could be filled.[+] increases the length of the strip flashing the next light in the strip to show where the "max" is at for the random (green dot in this case).
[-] decreases the length of the strip as per above.
[rnd] lights up 10 random "full" slots (cyan dots as an example) for 3 minutes. If you press the button again, it lights up a new random 10 lights for 3 minutes.
-
-
-
-
So I wired the WS2812B to the Espruino. up to the WS2812B strip, but I can't get it to do anything other light up completely.
I used the first line of test code which is:
require("neopixel").write(B15, [255,0,0]);But the code doesn't even to take effect.
Wiring diagram as per below. Note that the power source is a 4xAA battery pack which is delivering 5.3v. I get that 4xAAs can't power a whole strip, but they should power one LED.
What am I doing wrong?
-
Nice! Thanks again! Yeah, see all my life I've coded with linear execution in mind, so it took a while to wrap my head around it. The first thing I went for was delay when I couldnt make it work which is obviously wrong.
Ultimately the big picture is to design something that lights up 10 random lights on a strip of WS2812B LEDs, of a pre-determined length, the length of which is determined by pressing a button to increment the length of the strip, a button to decrease the length of the strip, and a button to randomize 10 lights within the boundaries of the strip and illuminated them for 3 minutes.
The above piece was me just trying to work with the built in LED for now, and then using the output on the LEDs once I get it all figured out.
-
Right. So the problem with my execution was it was just smashing through it all at once and thus not giving it the time to properly execute. That's what I didn't fully grasp in your first explanation.
If I understand correctly, by using if/else within a function using the timers, it will execute in a time appropriate fashion with proper controls, instead of firing everything at once and then having it wait until later to find all the variables have changed as part of the initial for execution..
Ironically your last code is similar to something else I tried which used setInterval and a clearInterval inside of a setTimeout, but as the loop executed, the intervals conflicted with each other due to their method of execution.
Again, thanks so much for your help!
-
Thanks so much for your help. No joke I have probably logged 10 hours into trying to solve this problem on my own, learning the hard way that setIntevals with the same name execute concurrently from a loop instead of sequentially and that one clearInterval blows the whole thing up. Definitely not an efficient use of time but I learned a lot.
One thing with your last example though is that I want to retain the data in memory. If I do a for counter with that code, would I still accomplish the overall goal? (alternatively I could always transfer the data into a new array and then pull/destroy the data from new that array, but that seems inefficient?
-
So I'm trying to design a circuit to blink out 10 randomly generated numbers in a row on the Pico onboard LED, with a break between each number. Being that I know very little about java, it's been a bit of a struggle. I've been using combinations of setTimeout and setInterval, but I can't seem to figure out how to blink the numbers one after the other.
I've come to the point where I'm using an array to generate concurrent timers as per below. Both g and rando are Uint8ClampedArray(10). h is declared globally but doesn't work any better locally. I've started with 4 to keep it simple.
for (h=0;h<4;h++) { console.log(h); g[h] = setTimeout('console.log(rando[h]);', rando[h]*400); }
outputs the following:
new Uint8ClampedArray([16, 17, 1, 9, 8, 7, 15, 18, 19, 1]) 0 1 2 3 //output of console.log(h) during the loop 8 //output of what should be the first 4 numbers of the rando array. 8 8 8
WTF am I doing wrong and/or what am I missing to get this thing to blink out 10 random numbers with a space in between?
Any help would be appreciated
So I know this thread is super old but I wanted to say thanks to @Gordon that was the trick I was looking for!
I was able to use it also to make a sound reactive LED hat using some advice you gave someone else! Thanks for helping me as I am new to the coding world!