Simulate fireflies in a jar
These programs are written for the AVR ATtiny85 microcontroller. They also run on the ATtiny45, and the two smaller ones should even run on the ATtiny25 with only 2k of flash memory, but I have not tested it. They are written to be compiled in avr-gcc.
The full simulation program is
pyralis.c. The other two programs are
simpler versions and can easily be extended to model other behaviors.
Makefile will build and install
pyralis.c. It will need
to be modified for chips other than the ATtiny85 and for programmers
other than the USBtinyISP. Pre-compiled .hex files are provided for
all three programs that are ready to install.
t84 contains a port of the firmware to the ATtiny84,
an AVR with more output pins than the ATtiny45/85. The simulation
program there can simulate 12 fireflies.
More information is at http://kjordahl.net/firefly.html.
Time-stamp: <Wed Jul 27 23:51:05 EDT 2011>
pyralis.hex to be compiled for attiny45, which seems to
run correctly on both ATtiny45 and ATtiny85 (the reverse is not true,
as I just found out). 14-Jan-2010
- A very simple program using timer1 for PWM but just
_delay_ms()for timing flashes and intervals. Only one male at a time, moving sequentially from one LED to the next. No randomness, sequence repeats every 6 flashes. (uses only 338 bytes of flash memory)
- The simplest possible program using internal timers for both PWM and generating interrupts. Simulates a pair of fireflies, the male is always flashing every 6 s, from a random location each flash. The female will [pseudo-]randomly appear and disappear, responding 2 s after the male’s flash. (uses 1344 bytes of flash memory)
- The full simulation program. Starts with one male flashing with a period of 5.9 ± 0.6 s. Additional males will arrive randomly at different times and periods, and will fall into sync with existing males. Females may respond if all males are flashing in sync, 2.1 ± 0.2 s later. Appearance of an unsynchronized male will cause the female to stop responding. The end state is usually 6 males flashing and one female responding. After a randomly selected number of cycles (lasting 5-25 minutes), the system will reset with no flashing males or females, and gradually build up again. The likelihood of new males or females appearing each cycle is reset as well, changing the character of the interactions each time around. Random number generator seed is stored to use a different one each time. (currently uses 2488 bytes of flash memory)
- A trial program to use software PWM to drive 8 LEDs independently. I didn’t find it to be fast enough to run a firefly simulations. Based on Atmel Application Note AVR136.
- Trivial blinky program for testing ATtiny84.
- Port of
pyralis.cto ATtiny84. Uses 12 LEDs in two sets of six. Also uses a button to switch on and off in software.
Buck, J., Synchronous rhythmic flashing of fireflies II. The Quarterly Review of Biology, 63(3):265–289, 1988.
Case, J., Flight studies on photic communication by the firefly Photinus pyralis, Integrative and Comparative Biology, 44(3), 250, doi:10.1093/icb/44.3.250, 2004.
Lewis, S. M. and C. Cratsley, Flash signal evolution, mate choice, and predation in fireflies, Ann. Rev. Ent., doi:10.1146/annurev.ento.53.103106.093346, 2008.
Lloyd, J.. Studies on the flash communication system in Photinus fireflies, Museum of Zoology, University of Michigan, 1966.
These programs are free software: you can redistribute them and/or modify them under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. A copy of the GPL version 3 license can be found in the file COPYING or at http://www.gnu.org/licenses.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.