Two things at once? (newbie)

jodicalhon

New Member
Hi all, I'm totally new to the picaxe (or any microcontrollers) and have just got a couple of 08's and started mucking about. Built myself a rather dodgy looking download cable and resurrected an old breadboard to stick the circuit on.

After blundering about for a while, I have successfully downloaded a few minor (LED flashing) programs.

I've managed to attach an LDR to the ADC input, check its performance in the debug window, and write a program (heavily plagiarised!) to flash an LED when the light is above a certain level, and sound a two-tone alarm using a piezo element when the light level drops.

So far, so good!

How do I get the LED flashing and the piezo sounding at the same time? That is, when the light level drops, how do I organise a visual as well as audible alarm?

Thanks for any help on this. I'm having fun so far!

Jo C
 

ylp88

Senior Member
First of all: <i>WELCOME TO PICAXE!!! </i>

If the piezo has in-built oscillation circuitry (as many do) it should be simple. Just connect the piezo to an output pin and the LED to another. Then it is as simple as using the HIGH command to activate the piezo then going to the part of the code which makes the LED flash.

I won't post code just to let you have a try first. It is always more satisfying tackling the problem yourself (with minor help included ;) ). If you are still stuck, just give us a shout and I (or one of the many othe great people 'round here) will give you more guidance!

Best of luck...

<i><b>ylp88 </i> </b>

<i>(yay! 600th post...) </i>

ADDENDUM: Some people also recommend the use of a catcher diode across a mechanical buzzer in order to protect the PICAXE from reverse EMF and voltage spikes caused by the buzzer.

Edited by - ylp88 on 11/8/2005 10:42:01 AM
 

MartinM57

Moderator
Depends if you want an academically elegant software solution or you want an engineering solution that does what you want...

...if the latter, then just buy a flashing LED - minimal increase in cost and does exactly what it says on the tin !
 

Rickharris

Senior Member
In addition to clarify how it works. You can only do one thing (instruction) at a time. With the exception that when an output is turned on/off it will stay on/off until the programme changes it.

Some other commands run in background (servo for example) and so seem to continue whilst other things are happening .

The microprocessor can only deal with one thing at a time BUT can operate so fast it can seem that several things happen at once.

 

Michael 2727

Senior Member
Hi Jo, n welcome.

If you use the &quot;tune&quot; instruction on the 08-M
to play your sounds, there is the option to
set one of 2 other outputs to flash an LED
with each note or alternately flash.

Extract &gt;&gt;&gt;&gt;
Syntax:
TUNE LED, speed, (note, note, note...)
- LED is a variable/constant (0 -3) which specifies if other outputs flash at the
same time as the tune is being played.
0 - No outputs
1 - Output 0 flashes on and off
2 - Output 4 flashes on and off
3 - Output 0 and 4 flash alternately &lt;&lt;&lt;&lt;&lt;&lt;

Look here &lt; picaxe_manual2.pdf &gt; under tune.

PS: ( as you said, also stolen from the PICAXE manual )

All tunes play on a piezo sounder or speaker, connected to output 2 (leg 5) of the
PICAXE-08M. Some sample circuits are shown later in this section.

Edited by - Michael 2727 on 11/9/2005 4:52:36 AM
 

jodicalhon

New Member
Thanks all. After playing around a bit more I'm beginning to get a better idea of how it works. Plenty more to learn yet!

The FLED's a great idea. Yeah, I was thinking of a software solution. Seems that, having started using code I was getting blinded by it, forgetting the simple solutions!

Thanks again. Be seeing ya!

Jo C
 
Top