Not understanding pssing a global variable
Wolfbrother
Posts: 129
I am hoping to pass a global variable to a running cog, while updating it my main cog running. To test this I have modified an example from Harprits book, called Harpritstones2. This seems to work like a champ, I increment the tones in the first cog and the second cog seems to play them just fine. I wanted to add a 1/2 second pause between each note played, so I thought I could just play a zero frequency tone for 1/2 second, I would do this by storing the passed tonenumber into a temp variable, changing tonenumber to a zero frequency in the DAT lookup, waiting 1/2 second and then returning the tonenumber back to where it was by making it equal to stored temp value. That program is called Harpritstones21
Doesn't seem to work, I can play the first tone, it then goes to the second tone, without a pause ( which does make sense to me, based on how I wrote it) Once the ToneNumber changes to 9 ( the zero frequency in the DAT table) the tones never come back. I have run serial terminal to make sure the values are changing correctly, but no tones follow.
I have attached all the programs and a notepad copy of my serial terminal output, what am I missing here?
Thanks,
Dave
Doesn't seem to work, I can play the first tone, it then goes to the second tone, without a pause ( which does make sense to me, based on how I wrote it) Once the ToneNumber changes to 9 ( the zero frequency in the DAT table) the tones never come back. I have run serial terminal to make sure the values are changing correctly, but no tones follow.
I have attached all the programs and a notepad copy of my serial terminal output, what am I missing here?
Thanks,
Dave
Comments
Thanks,
Dave
You should change the loop to
I don't see a reason for having the inner loop as it's immediately repeated by the outer loop. So, it can be removed.
That seems to work just fine. I wasn't convinced I needed the nested repeats either. Thank you. Based on your idea, I modified the program to use a flag to either output a tone or not. I think this is much cleaner. If you have any suggestions about this idea I would welcome it.
Thanks,
Dave
Harpritstones24.spin