Click here to Skip to main content
13,199,311 members (72,264 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I am trying to flash an LED and sound a piezo at the same time, as a buggy is reversing.
I am using flowcode and cannot have the two outputs high together and at different frequencies. At the moment I'm pulsing the Piezo for 250ms at 40us / 40us - then turning the LED on for 250ms then looping

I suspect I can do this properly with a C code macro in the flowcode, but not sure how to do it.
At the moment the macro looks like this (i have excluded the motors clarity)

Master loop - 3s (reversing period)
Loop1 for 4000(approx)
PortB - 00000001
Delay - 40us
PortB - 00000000
Delay - 40us
End Loop1
PortB - 00000010
Delay - 250ms
PortB - 00000000
Master loop - end
Posted 30-Jan-13 1:54am
OriginalGriff 30-Jan-13 8:01am
Why can't you have them both high at different frequencies? It would appear to be two separate bits on teh output, and LED's don't generally take much power.

Is 250ms / 40uS long enough for the piezo to actually respond? They are physical objects, after all.
Christophe73 30-Jan-13 8:16am
Yes the piezo will sound. To have them both operating at the same time would mean they are operating based on the same delay - the LED would not flash it would appear on constantly.

The flowcode operates sequentially so if i pulse the piezo at one frequncy for 250ms i must wait for the 250ms period to finish before i can pulse the LED at a seperate frequency - so they are not on together.
OriginalGriff 30-Jan-13 9:34am
So why not use a frequency of 50uS and turn the bleeper on or off each "tick", and the LED each five "ticks" - it's easy to code, it's easy to understand, and it should work's what I do when I need two dissimilar frequencies!
Christophe73 30-Jan-13 9:38am
This is my 1st attempt at a PIC project and I'm using flowcode, I have no experience with C Code, but i have a C Code macro option, but don't know were to start, could you post your version and I'll try it and tinker.
Christophe73 31-Jan-13 6:32am
9 million members , 37,000 online and no one can help this beginner code this???

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.171020.1 | Last Updated 30 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100