Minimal Picaxe LED blinker
May 23, 2010
I just found a different way to make an LED blink with a picaxe 28x1:
let pin7 = b0 >> 7
' do other important stuff here
The variable in b0 is incremented in every new loop. It will roll over from 255 to 0 and start over again. The output pin (pin7 in this case) takes the value (0 or 1) from the most significant bit in b0. Only when b0 is 128 or higher, will the pin go high (and the Diode will Emit Light). When b0 rolls over, back to values below 128, the LED will no longer receive power. So in this example, the LED will be on 50% of the time and off 50% of the time. It would take the code a total of 256 loops around the code to complete one LED blink cycle. The user sees the LED light up only once per blink cycle.
The interesting part is that there is no pause in the code. This code could be extended to do anything in "real time" and keep the LED blinking. The speed of the blink would be slowed down by the extra code, because it would take the code longer to loop around.
The value "7" can be any value in the range 0-7, where 0 will give you the fastest blinking (128 blinks per roll over of b0).
On a Picaxe28x1, the slowest setting 7, without any extra code, results in approximately 120 blinks per minute or 2 Hz. Apparantly, the Picaxe manages to roll over the byte twice per second. That translates into roughly 512 gotos per second.
A little piezo speaker can make the faster blink rates audible (which is all the rage according to our webmaster). Value 0 produces a tone of approximately 256 Hz, I guess.