Warning Signs
Fireflies appear to be flashing their blinkers at random to the untrained eye. You might not be able to figure out the pattern, but taking a closer look will show you that there are several reasons behind the flashing, one of which involves sending a warning. This might mean to exhibit frustration with other members of the species or alternatively to send a threat.
Identification and Mating
The reasons behind the light signals don't stop there -- they are also used as a method of identification. Individual species exhibit their own patterns. Alternatively, individuals within each species can flash specific patterns to differentiate between males and females. Like every other species, sexual selection plays a heavy hand in firefly behavior. A higher flash rate makes a male more sexually attractive to the opposite sex, increasing his chances at mating successfully.
Light Production
The name that comes with the science behind light production in animals is bioluminescence. The key to bioluminescence lay in an enzyme known as "luciferase." When luciferase is fed the right ingredients, it will glow and create light. The key mixture involves oxygen, ATP, luciferin, as well as calcium. When fireflies intake oxygen, they are able to produce light; when they don't, the lack of oxygen prevents light.
Controlling the Glow
The intake of oxygen, which occurs through tracheole tubes, combined with nitric oxide serve to control the flash rate. When the firefly produces nitric oxide, it serves as an open gate, allowing oxygen molecules to release from the mitochondria and flow into the light organ, which allows it to light up. The reason for the fluctuation between light on and light off is nitric oxide's structure, which breaks down quickly.