Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: PIC
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
Comments
OriginalGriff at 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 at 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 at 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 fine...it's what I do when I need two dissimilar frequencies!
Christophe73 at 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 at 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
0 OriginalGriff 405
1 Maciej Los 285
2 Peter Leow 128
3 Kornfeld Eliyahu Peter 119
4 DamithSL 119


Advertise | Privacy | Mobile
Web03 | 2.8.140709.1 | Last Updated 30 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid