My good friend and FlashBrighton veteran Jo Summers has been enthusing at me for some time about the Arduino boards. And I just knew that as soon as I started playing with one, I would get obsessed, so I’ve been putting it off for a while.
I knew you could use Arduinos to interface with the computer, and Flash. But what I didn’t quite register was that you could program these little chips independently of the computer! Once you program them, you can disconnect them and (as long as you give them a power supply) they will continue to do exactly what you want them to do! So actually I haven’t done any work getting them working with Flash at all, I’ve been much more interested in getting them to work independently.
And 2 weeks later, in true predictable seb-style, I’ve made a particle system on the Arduino. I know. I’m sorry.
It all started when we decided to give away 8 workshop kits at the recent FlashBrighton Flex3 launch event, (which appears to have started a mini Brighton epidemic), and I knew I could put off my hardware tinkering no longer.
I love LEDs, or light emitting diodes. You know the little red lights you get in stuff? Ever since I started playing with electronics as a kid – my dad was a physics lecturer and he used to bring home components for me to play with. So naturally the first thing I started playing with was LEDs.
But the arduino only has 13 outputs, so you can only control 13 LEDs? Well that’s cool, but it’s not cool enough. So I started looking into alternatives. And I discovered Charlieplexing! You can read all about charlieplexing here on the instructables site – it’s a complicated way of wiring LEDs that enables you to control many with few connections, and with only 6 outputs, you can control 30 LEDs!
(Photo by Jeremy Keith)
And that was cool for a while, but not enough. My need for LEDs was not going to be satisfied. So then I borrowed one of these cool 8 x 8 LED matrices from Nexus.
Once I figured out how to wire it up, and using the Arduino Matrix library, I got to work.
The only real trick here is that I’m working internally with a much higher resolution that the actual 8×8 grid, and then rounding to the nearest pixel when displaying each particle. This gives a really smooth movement. I’m only actually lighting one LED per particle but due to the Persistence of Vision (POV) effect it looks like there are more. And the final trick is to add a diffuser. It’s kinda like a hardware blur filter 🙂 It really tricks the eye into seeing the separate particles.
The code’s a bit hacky, but it’s just a prototype. I’ll explain it in more detail later if you’re interested! I just wanted to get this up before I went to sleep. Code below…
#include #include #include Matrix myMatrix = Matrix(13,11,12); const int numparticles = 4; int velx[numparticles]; int vely[numparticles]; long posx[numparticles]; long posy[numparticles]; int res = 7; int maxnum = 8<<res; int maxspeed = 30; int count = 0; int row; int col; int i; void setup() { int i; myMatrix.setBrightness(15); for(int i = 0; i<numparticles; i++) { velx[i] = random(11)+5; vely[i] = random(11)+5; posx[i] = (i%2)<<res; posy[i] = (i/2)<<res; } } void loop() { myMatrix.clear(); // clear display for( i = 0; i>res; col = posy[i]>>res; myMatrix.write(row, col, HIGH); posx[i]+=velx[i]; posy[i]+=vely[i]; if(posx[i]=maxnum) { posx[i] = maxnum+(maxnum-posx[i]); velx[i]= -velx[i]; vely[i] = vely[i]+random(-1,1); if(vely[i]>maxspeed) vely[i] = maxspeed; else if(vely[i]<-maxspeed) vely[i] = -maxspeed; } if(posy[i]=maxnum) { posy[i] = maxnum+(maxnum-posy[i]); vely[i]=-vely[i]; velx[i] = velx[i]+random(-1,1); if(velx[i]>maxspeed) velx[i] = maxspeed; else if(velx[i]<-maxspeed) velx[i] = -maxspeed; } } delay(1); }
13 replies on “Arduino particles!”
Haha, good work! 🙂
Close Encounters of the third kind?
Oooh we have an Arduino special on Thurs courtesy of Tinker.it!
//www.lfpug.com/27th-march-2008-27032008/
Awesome! This remember me my old times on demoscene. I have coded this kind of routine on MS-DOS using VESA driver and was lokking good, but the idea theplay with Arduino is just fantastic.
If you can control de brightness, you also can play with Metaballs! So… next time a plasma effect maybe?
Keep the good work guy!
//www.BricoGeek.com
Very nice. Do you have any instructions on wiring it up “properly”? I have the same setup but cannot get the matrix class to run at all. I can light up all the LEDs but only manually and of course the matrix class would save a lot of work. Any hints would be greatly appreciated.
Keep up the good work, first time here and some cool stuff on your blog.
@iestyn and mike – thanks guys!
@tink – hope it went well!
@oscar sounds cool! I’ve played a little with plasma in Flash (and also have a background in the demo scene of the early 90s!) You can’t really get different brightnesses unless you do manual pulse width modulation (PWM) and I’m not sure the controller is fast enough… will be my next project though!
@Jan G actually I corrected a link, this matrix isn’t the one from SparkFun, it’s a nexus one from here : //80.189.97.157/Products/displays/bxxcdm.htm
The wiring is pretty straightforward – there are only 5 pins, one is ground, one is 5V and the other 3 are explained in the source code.
I’m currently trying to get the SparkFun full colour array working, but struggling right now!
Let me know how you get along!
Seb
Hi Seb! I clicked this link on Make because it looked cool and then was slightly shocked to see your name at the top.. with hindsight, I should have guessed it was you! 😉
Good work!
Jamie
Hey, this is cool!
Can you simulate fire with this?
@ Jamie – nice to see you here 🙂 glad you like it…
@ Gllad, sure why not! Well you’ve got the source, so why not give it a go? 🙂
cheers!
Seb
Well, well, I also clicked this link and then had to smile when I saw your name at the top… I’ll be stealing your code once again 😉 On a par with the flying cows and with much less memory!
Funny how the same things seem to appeal to the same people over and over …
[…] Great first tutorial, I just did the first 3 lessons of this one. Very clear. – Arduino and Flash – Seb’s experiments with Flash particles & […]
[…] March my LED particle experiments with the Arduino caused a little spike in my web stats with over 6000 views on my youtube […]
[…] Great first tutorial, I just did the first 3 lessons of this one. Very clear. – Arduino and Flash – Seb’s experiments with Flash particles & […]