PDA

View Full Version : Disco lighting controller - again



malc-c
- 1st January 2007, 13:41
I have been developing this version of my disco light controller, and learing a lot about electronics an pbp along the way. However I've hit a small problems with getting LEDs to chase correctly to the beat of the music.

I have managed to filter the base beat using an NE555 and this provides a nice +5 logic pulse in time with the beat. However I'm finding that using the code below the lights cycle through the sequence too quick. What I'm after is for the LEDs to step through the sequence one at a time, where as at the moment it loops round, still finds the beat is present and jumps another setp, loops round again and does the same, until the beat isn't present. Whilst I could put in a larger pause, this could then cause problems of the code missing a beat on tracks with a faster beat. Is there anyway to detect just the initial change from low to high of the pin, thus ignoring the remainder of the time the pin is high, and then reset itself when the pin goes low again ? Or would this be too complicated ??

Here's the code for the music section



music:

read patt[swcount],steps ;read the first value of the selected patter and place it in the variable steps
READ PATT[SWCOUNT]+ C,PORTB ;reads the step value for selected pattern and send it to PORTB
If switch2=1 then C=C+1
pause 10
If C=steps then C=1
goto music:

keithdoxey
- 1st January 2007, 16:50
Hi Malc

Assuming your PIC doesnt need to do anything else until the next beat then wait for the beat to disappear



music:

read patt[swcount],steps ;read the first value of the selected patter and place it in the variable steps
READ PATT[SWCOUNT]+ C,PORTB ;reads the step value for selected pattern and send it to PORTB
If switch2=1 then C=C+1
pause 10
If C=steps then C=1
****** add a bit here ******
goto music:


Add these lines at the point shown or if you need to update the display first then add the after you have updated the display.



While Switch2=1 ' beat signal is still high
pause 1 ' short pause
Wend ' its gone low now so we can carry on


Hope that helps

malc-c
- 1st January 2007, 17:04
Thanks again mate,

I'll give it a try later and let you know how well it works

mister_e
- 1st January 2007, 23:25
Or you poll an interrupt flag. Some interrupts source can be triggered by a rising OR falling edge. This said, it save few bytes of code.

Food for thought :D