Cylon Project
servello
Posts: 113
Greetings,
Is it possible to blink LED's and play tones at the same time with the BS2? I am trying to come up with a satisfactory project wherein the LED's chase back and forth with the 'Cylon' sound playing. So far I've written separate code for each function, but can't figure out how to have them combined. I do have a file written by someone else that does work - but I am unhappy with the frequency used. I think mine is much closer to the actual Cylon/Knight Rider sound.
I'll attach the three separate codes as well as a photo of the circuit. Any help will be much appreciated.
Post Edited (servello) : 11/11/2009 8:23:38 AM GMT
Is it possible to blink LED's and play tones at the same time with the BS2? I am trying to come up with a satisfactory project wherein the LED's chase back and forth with the 'Cylon' sound playing. So far I've written separate code for each function, but can't figure out how to have them combined. I do have a file written by someone else that does work - but I am unhappy with the frequency used. I think mine is much closer to the actual Cylon/Knight Rider sound.
I'll attach the three separate codes as well as a photo of the circuit. Any help will be much appreciated.
Post Edited (servello) : 11/11/2009 8:23:38 AM GMT
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·"If you build it, they will come."
To go into some more detail that Erco was stating and that you are running into, is that the BASIC Stamp in a single thread operator; which means it can only do a single task as a time. So you will not able to toggle and LED while playing some music at the same time. However, what you can so is put the sound that you want to create in the middle of the routines you have blinking the LEDS.
For example:
· TOGGLE LED
· Generate·a Sound
· TOGGLE LED
· Generate·a Sound
· and so on
So you will have to break up the program and perhaps use the frequency in the same manor you have now where that value is the tone you want to use, but you will have to increment that value other than a FOR...NEXT loop. I hope that helps
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Respectfully,
Joshua Donelson
www.parallax.com
*** Begin Rant ***
I take great care in posting forum messages. I am always polite, I obey the forum rules, and I am always extremely descriptive and usually include code and images. On top of that, I search high and low both on the forum and on the internet in general - for the answers I seek.
I mention this because most of my posts seem to be either ignored or passed off with a quick retort. I once asked a question and reminded a forum member that he had forgotten to include an attachment from a previous post - only to have the original poster reply to everyone in the thread except me!
I have seen many posters that are rude, type terribly, ignore the rules ask questions that have been answered Ad Nauseum without bothering to do a simple search - for instance, this one comes up all the time - - "Basic Stamp Not Found" - -
Yet these same posters quite often get:
a) Many replies
b) Quick replies
c) Verbose answers
Forgive me, but I just don't understand why this is. I have even asked if I had done something wrong, or offended someone or broke a forum rule. And yet, nothing.
*** End Rant ***
Again, thanks for the reply. It will be helpful.
Dominic
Dominic,
This does happen from time to time, but do not feel you are the only one to have posts which get quick short replies, or none at all. Many times it deals with subject matter, which other people are not interested in. It is in human nature to group around things you enjoy and distance yourself from items you do not.
There will always be a percentage of people who do not respond to posts well, and possibly leave a person out. I do not let this affect me. I am who I am, and will help where I can no matter how others do me.
There are many here who help plenty. Others come to get information and leave as fast as they get the answer.
Most active participants expect a hierarchy which should work but sometimes doesn't. The upper level people help the middle, the middle help the lower, so on and so forth. Unfortunately it doesn't always work this way.
When the previous breaks down, the answers sometimes get specific with verbage. Have you ever talked to someone too educated in a specific subject matter. When I do, my eye's are crossed within the first two minutes of conversation. This happens when the upper guys help the lower guys directly. They forget that their terminology may be over the helpie's head. This is not point at you in this case, just the way it happens much of the time.
You just have to get in here and roll around in the mud with the rest of us.
I hope the situation doesn't run you away. We can always use more active members of the forum.
You will find.......many people here are tinkerers. They want to figure out a solution for themselves, and can't understand why someone couldn't or wouldn't want to. They try to inspire you to try different things, for you to be the same. There are many things here because of diversity, and people finding new ways of doing things.
James L
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
James L
Partner/Designer
Lil Brother SMT Assembly Services
Are you addicted to technology or Micro-controllers..... then checkout the forums at Savage Circuits. Learn to build your own Gizmos!
Thank you for your reply. Your post was both thoughtful and instructive.
I guess because *I* think and act a certain way, I expected *everyone else* to do the same. Which is of course, absurd. This forum consists of people who *volunteer* their time and know-how to provide help and direction; which they do very well. We are indeed lucky to have this great community.
Anyway . . .
I hope a few more people will post some suggestions as this is a fundamental issue with the BS2 (ability to only do one thing at a time), and would be very helpful to all newbies.
Take care,
Dominic
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Deus tantum me iudicabit
The probem is that your led animation will never be smooth -- the time to play sounds will vary, so to make it more interesting, we'll have a padding pause that will be adjusted after each sound (or not) to make things *reasonably* consistent. You won't get fast animation though, you need to pick a time for the padding that is a little more than your longest sound:
So in the second example, you should get approx. 2 secs between each shift of the leds, with time between for sound of varying length. Of course, this also has a problem, which is that you will have varying space between sounds. Really depends on the kind of sounds/speed you want. There are other tricks for interleaving, but this may help get you started. Of course, other micros are better suited to tasks like this which appear to run concurrently (e.g. Prop, SX, AVR, etc).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
Thanks, Zoot.
I've either got alot of research and work ahead of me or I might just try to accomplish this with an Arduino. I have no parts for Propeller or SX chips (I also have no idea of how to program them). I do have an Arduino and can maybe find some pre-written code already done.
Best,
Dominic
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Deus tantum me iudicabit
use one to generate sound and send a pulse to the other controller to start the led cycle?
ie basic stamp is coded to play sounds and arduino is coded to control led's
Dominic,
That is one draw back to a processor like the Basic Stamp. Because the LED's and the sound are active concurrently, it is hard to control both with a Stamp. That is why many us the more experienced guys have moved up to the Propeller or the SX.
I personally think the Propeller is the better choice of the two, but you are correct about the programming. The propeller's programming can be intimidating.
But, I will say, if you ever start with a Propeller, you will be reluctant to use anything else. Having 8 independent processes going on at once is great. Each clicking along, playing nice with each other (but still doing their own thing)..........it's really hard to go back to a linear type process.
I'll just about use a propeller to blink a simple LED....even though is is like killing a fly with a sledgehammer. I like it's raw power, and rather use it, unless the process is just too simple not to (or I can't justify it's price for the project).
Sorry the Stamp isn't working out for your task, but you have found a reason to dive deeper in to the addictive realm of micro-processor electronics.
James L
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
James L
Partner/Designer
Lil Brother SMT Assembly Services
Are you addicted to technology or Micro-controllers..... then checkout the forums at Savage Circuits. Learn to build your own Gizmos!
That's a idea I hadn't thought of. Thanks, modkil.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Deus tantum me iudicabit
The BASIC Stamp is my Microcontroller of choice and I'll never stop playing with it. And I just might delve into the Propeller one day.
Until then, do you think I could offload the sound to a ISD_25120P and run it through the BS2?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Deus tantum me iudicabit
Dominic,
That sounds like a great idea. Although you would only be controlling the ISD25120p with the stamp for syncing the sound with the lights. The stamp will be controlling the lights, and queuing the ISD25120P for synced sound.
I think that should work. Getting all the bits to play in the right time frame may be a task, but I think it can be done.
James L
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
James L
Partner/Designer
Lil Brother SMT Assembly Services
Are you addicted to technology or Micro-controllers..... then checkout the forums at Savage Circuits. Learn to build your own Gizmos!
I had a thought -- here's a variation of my code -- in this case it checks for a maximum duration on sound data and compares to the maximum frame -- this lets as many sounds play in a row as "will fit" within the LED frame:
This code should do cylon lights on 8 leds at approx 75ms per each, and play "songs" within the frames.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
Post Edited (Zoot) : 11/13/2009 6:09:11 AM GMT
Still, it sounds a bit silly to think that nobody out there has done this before. The LED Chaser is one of the foundational circuits that almost every newcomer attempts. I should think that the accompanying sound effect would be the next logical step.
Thanks for everyone's input.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Deus tantum me iudicabit
Damn, Zoot you're programming skills are impressive!
I am in no way capable of writing code like that; I'm going to have to spend some time with this. I'll try to see what you've got going on there.
Dominic
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Deus tantum me iudicabit
The short version is something like this:
I'm way simplifying here, but hopefully it gives an idea. Ideally, everything that can be should be LOOKUPS rather than IF/THEN/ELSE/ENDIF --- lookups always take about the same time to evaluate *regardless of the outcome* which means the the loop will run more consistently in speed -- which leads to a smoother appearance. IF/THEN is notorious for taking wildly different execution times depending on the results of the various evaluations.
In my actual implementations I usually have separate variable set up for the frame speeds for each module -- and I use modulo for varying speeds (esp. with Words which don't roll over as quickly), i.e. a speed controlled led flash in the same context as above:
Where "speed" lets the leds change after 1 tick, 2 ticks, 3 ticks, etc.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
Post Edited (Zoot) : 11/13/2009 6:45:07 AM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Deus tantum me iudicabit
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
Post Edited (Zoot) : 11/13/2009 6:59:39 AM GMT
You should give classes in LED's - with downloadable pdf's - [noparse];)[/noparse]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Deus tantum me iudicabit