Power to the People of Iran

..and welcome to eeeGadgets! This blog is dedicated to everything associated with the wide (and interesting) field of mobile computing. The main focus is on presenting all the various hardware modifications I made to my eeePC, but I will also give short reviews of other interesting Mobile Internet Devices I come across. Further I want to share some tips and tricks I found out to be helpful in getting the most performance out of Ubuntu linux...
On the right side under "LABELS" you can navigate between various assorted article categories. Also, on the very bottom of the site you will find some useful weblinks, as well as a small broadband connection speed test (which can be very useful sometimes).
If you want to, you can subscribe to my RSS news feed too, to be always up to date about my latest articles - simply click on "subscribe now!" in the little box on the right side. Alternatively, you can subscribe to my simple email newsletter by clicking here.
For questions, feedback, suggestions, criticism and everything else, don't hesitate to contact me:

....have fun reading!

If you like my site and want to support me , you can always donate to my personal "coffee funds" using the PayPal "donate" button further down on the right! :)

Friday, May 22, 2009

what have fireflies got to do with BASIC?

During the last days I've been quite excited about a certain idea I want to report about here, and which I think is quite an entertaining project. During one of my web journeys I recently happened to stumble upon this link over at instructables.com and was fascinated: I was looking at a 5x5 LED matrix that initially blinked its LEDs randomly, but somehow "magically" (with the support of 25 light-dependent resistors) synchronized them very slowly, to finally reach a state of absolute synchronicity - and all this with 25 totally independent control circuits, all based on 25 single atTiny13 microprocessors!! The whole thing should be considered as being a model of large swarms of thousands of male fireflies in sout-eastern asia, which are capable of synchronizing their blinking to attract more female fireflies over a greater distance. For more detailed explanations about the background (and how to set up a physical logic model using AtTiny13 chips and C coding) I want to forward you to the instructables link above as well as to this scientific paper explaining the underlying mathematical theory behind this..

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

; variables
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

; 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

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"
pause 100

next Counter

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

gosub pulse

pause 700

next Counter

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!)...
sleep 3
goto main

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
pause 300
low 2

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.

No comments:

Broadband Connection Test:

Just click on "Speedtest starten" to evaluate your actual downlink in MBit/sec (takes 10 seconds approx.)

(c) dsl-speed-messung.de - DSL Speed Test