Hi all,
I've been reading something over at instructables that triggered my interest: an array of LEDs simulating the self-organizing behaviour of a swarm of blinking fireflies. The LEDs start out by emitting random flashes of light, but with time they synchronize to each other and finally they all blink synchronized (each of the LEDs has a small Atiny12 and a light-dependent resistor) Since I like the idea I want to copy this with several picAXE08 (I don't like atmel chips since I can't write code for them).
But before going out and buying a whole bunch of picaxe08, I thought I'd like to have some opinions on the software I wrote for it - specifically my fears are that the individual "fireflies"/circuits will not differ enough in their initial delay before they start their blink'n sync adventures..
I've tried to fill a word variable with "random" value and then use only 1 byte of that, can anyone have a look at the code please and tell me what they think - will this cause the fireflies initial (still unsynchronized) behaviour to be "individual" enough, or will the more or less all start at the same time?
Will the program work at all?
thanks
heres my code
I've been reading something over at instructables that triggered my interest: an array of LEDs simulating the self-organizing behaviour of a swarm of blinking fireflies. The LEDs start out by emitting random flashes of light, but with time they synchronize to each other and finally they all blink synchronized (each of the LEDs has a small Atiny12 and a light-dependent resistor) Since I like the idea I want to copy this with several picAXE08 (I don't like atmel chips since I can't write code for them).
But before going out and buying a whole bunch of picaxe08, I thought I'd like to have some opinions on the software I wrote for it - specifically my fears are that the individual "fireflies"/circuits will not differ enough in their initial delay before they start their blink'n sync adventures..
I've tried to fill a word variable with "random" value and then use only 1 byte of that, can anyone have a look at the code please and tell me what they think - will this cause the fireflies initial (still unsynchronized) behaviour to be "individual" enough, or will the more or less all start at the same time?
Will the program work at all?
thanks
heres my code
Code:
; *** FIREFLY.BAS ************ Version 1.0 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 PICaxe08 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) 15/05/2009
; Dennis Schulze
; variables
symbol Power = w4 ;determines how urgently the firefly wants to pulse or how hard it "desires" to do so
symbol Brightness=b2 ;this later contains the reading of the LDR value
symbol Ambient =b3 ;initial ambient light intensity value is stored here for comparison reasons
symbol BlinkCounter = b4 ;Counter needed for initialisation blinking loop
symbol RndDelay = b1 ;this will be seeded with a random number for individual delay time
; constants
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
;counters
let BlinkCounter = 1 ;reset all counters
let Power = 1 ;
;randomize a bit to give individuality
random w0 ;generate "random" 16bit number (hopefully differing enough between individual PICaxe ICs)..
let RndDelay = b1 * 24 ;take the last 8bit of it and multiply by 24 to give several seconds delay at most
; initialisation blinking loop
for BlinkCounter = 1 to 5 ; blink five times
gosub pulse
pause 700
BlinkCounter = BlinkCounter + 1
next BlinkCounter
pause 1500 ; wait long enough to make sure that absolutely NO firefly is blinking at the moment
readadc 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..
readadc 1, Brightness ;...while watching the surrounding fireflies too!
if Brightness >= Daylight then ; unless its daytime (fireflies are sleeping during daytime!)...
sleep 3
endif
if Brightness > Ambient then ;......perceiving pulses from other fireflies will
Power = Power + 50 ;..strongly increase our fireflys desire to pulse with them!
endif
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
; (equals satisfaction about just having pulsed)
endif
loop ; starts building desire for another pulse again (while slowly approximating the other's frequencies)
;subroutine
pulse:
high 2 ; give a short flash of light
pause 300
low 2
return