Hi all,
Thanks to everyone who helped so far with my re-working of the wheel project to make some form of disco lighting unit. I now have a revised idea and need some advice on the best way to go about it.
I have managed to make a bass beat extractor filter, which triggers an NE555 to provide a 5v logic pulse which is fed to an input on the 16F628a PIC, so when its high the pattern advances. ( A video best explaining this can be downloaded from http://www.micro-heli.co.uk/discolights2.avi )
Recently I had an option where a swich toggled the state of a variable and depending on the state of the variable the code would run the music routeen or simply chase at a speed dictated by a pot. However I would like to have the option of having the selection done automatically. The idea is that if the music input is low for a period of time in seconds (15, 20 40 what ever) the code runs the selected pattern in chase mode, then if the pin goes high due to the beat being detected, the code runs the sequence in step with the music. Obviously each time the pin goes high the timer has to be reset.
I've listed the body of the code with the comments where I think the checking needs to be done... but although I've glanced at the manual, I'm not sure what would be the ideal command to use, or how to impliment this, so help is required
Code:;************* set up varibles ************ i var byte ;used for for next loops D var byte ;used to store the result of the pot on port A1 and thus set timing delay scale var byte ;used in the POT command Scale = 254 ;used to set range SW1 var PORTA.6 ;pattern cycle switch on RA6 mus var PORTA.2 ;music input pin A2 SWcount var byte ;used to count the button SW1 presses steps VAR BYTE ;used to store the number of steps in the pattern sequence counts VAR BYTE ;used in the FOR NEXT loop to run through the sequence ;************* main program **************** counts = 0 ;set the value of counts to the start of each pattern swcount=1 ;set default to pattern 1 music: if sw1=0 then swcount=swcount+1 ;cycles through the patterns by adding 1 to SWcount pause 70 ;debounce delay If swcount >7 then swcount=1 ;error trap for exceeding max patterns gosub sel1 ;go to subroutine to select pattern based on SWcount value If mus = 1 then counts = counts+1 ;****if mus = 0 then start timer. If timer > 30 seconds then goto chase **** gosub sel2 ;go to subroutine to display pattern in current step If counts >= steps then counts = 0 ;if counts then reset counts to 1 goto music: ;************* Subroutines ***************** Chase: Pot PORTA.1,scale,D ;used to read value from 10k pot pause 70 ;debounce delay gosub sel1 ;go to subroutine to select pattern based on Swcount value FOR counts = 1 TO steps ;advance to through the entries gosub sel2 ;go to subroutine to advance through sequence PAUSE D ;pause period set by varible D if mus =1 then goto music NEXT counts ;advance through loop to next position Sel1: if swcount = 1 then read Patt1, steps ;read the first value in data string patt1 and place it in steps if swcount = 2 then read Patt2, steps If swcount = 3 then read Patt3, steps if swcount = 4 then read Patt4, steps if swcount = 5 then read Patt5, steps If swcount = 6 then read Patt6, steps If swcount = 7 then Read patt7, steps return Sel2: if swcount = 1 then READ (Patt1+counts), PORTB ;read the next value in patt1 and display it on PORTB if swcount = 2 then READ (Patt2+counts), PORTB if swcount = 3 then READ (Patt3+counts), PORTB if swcount = 4 then READ (Patt4+counts), PORTB if swcount = 5 then READ (Patt5+counts), PORTB if swcount = 6 then READ (Patt6+counts), PORTB if swcount = 7 then READ (Patt7+counts), PORTB RETURN




Bookmarks