And, of course, to a video of "the real McCoy" - real fireflies sitting in a tree, blinking like there would be no tomorrow:
To put it shortly: I decided I wanted something like this hanging on my wall too!
..but since neither the AtTiny nor its "C" language appeal to me, and since further I'm NOT in posession of any ATMEL programmer to accomplish this new goal of mine, I decided that I needed to use something simpler. I instantly thought of the "picaxe" microcontrollers (which are intended for schools originally, sold by a company called "rev-ed.co.uk", these things are basically a customized "microchip" PIC microcontroller with a bootloader enabling easy direct programming via serial cable, and programmable in a very easy-to-learn BASIC dialect), which would surely allow me to arrive at a nice blinking and syncing LED array in not too much time.
Now while I have not started to assemble any circuit yet, I already have written a small piece of BASIC code which, I think, is quite easy to understand and fun to read - and so I will present it here for the amusement of my dear readers.
here it is:
; *** FIREFLY.BAS ************ Version 1.1 beta ******* SELF-SYNCHRONIZING NETWORK OF LED FIREFLIES ***
; this program is intended for simulation of a swarm of fireflies by many individually controlled LEDs, designed
; to run on a PICaxe08M with a LDR connected to pin 1 and one LED wired to pin 2 (each firefly needs one PICaxe)
; Since they are totally independent besides of sharing the same reset switch, one can easily combine any number of
; fireflies to form a large array of blinking, self-organizing LEDs... pressing the "reset" switch will of course disturb
; the fireflies and their uniform blinking pattern, like walking right into a swarm would disturb real blinking fireflies too,
; probably, and it takes awhile before they start blinking and syncing again...
; Copyright (c) 22/05/2009
; Dennis Schulze
symbol Power = w4 ;determines how urgently the firefly wants to pulse or how hard it "desires" to do so
symbol Brightness=w3 ;this later contains the reading of the LDR value
symbol Ambient =w2 ;initial ambient light intensity value is stored here for comparison reasons
symbol Counter = b2 ;Counter needed for initialisation blinking loop
symbol RndDelay = b1 ;this will be seeded with a random number for individual delay time
symbol Daylight=195 ; above this light intensity threshold the firefly does not glow at all (i.e. if its not "night")
symbol MaxPower = 80 ; Urgency threshold that triggers an immediate pulse
let Counter = 1 ;reset all counters
let Power = 1 ;
gosub pulse ; firefly wakes up
;randomize a bit to give individuality - "the learning phase" during sunset!
for Counter = 1 to 10 ; read out ten times...
read 0, w0 ; ...a random value from EEPROM..
readadc10 1, Brightness ; ......and the current LDR value....
w0 = w0 + Brightness ; combine the values giving a seed....
random w0 ;....which is used for seeding RANDOM with some highly individual value
write 0, w0 ; seed stored for next readout cycle, "randomness accumulates"
let RndDelay = b1 * 24 ; now use last 8bit of the random word w0, multiply with 24 to give max 6 sec delay
let Counter = 1 ; reset counter
; initialisation blinking loop
for Counter = 1 to 5 ; blink five times
pause 500 ; wait a little bit
readadc10 1, Ambient ; then read out ambient light intensity and store value in "Ambient"
pause RndDelay ; pause for an "individual" (hopefully) amount of time before doing anything else
main: do ; main loop
let Power = Power + 1 ; slowly start incrementing the fireflie's desire to blink..
readadc10 1, Brightness ;...while watching the surrounding fireflies too!
if Brightness >= Daylight then ; unless its daytime (fireflies are sleeping during daytime!)...
if Brightness > Ambient then ;......perceiving pulses from other fireflies will
Power = Power + 30 ;..strongly increase our fireflys desire to pulse with them!
if Power > MaxPower then ; if the desire is strong enough...
gosub pulse ; ...the firefly bursts out a light pulse
let Power = 1 ; what a relief for the firefly! "desire" is reset to initial value
endif ; (equals satisfaction about just having pulsed)
loop ; starts building desire for another pulse again (while slowly approximating the other's frequencies)
high 2 ; give a short flash of light
Thats all for now, only code and no soldering yet. Thus the code is not functional since not tested, and it still has some flaws (like for example the needed initial randomness in blinking rate is not implemented yet), but rest assured that I will update on this blog as soon as physical results can be presented. I just need to order the needed chips and stuff. In the meantime you can read more about the project over at the picaxe forums where I started a topic about this self-organizing stuff too, and got many great replies concerning ideas for good "true" random number generation and other stuff.