PDA

View Full Version : LED to music code



Dickeysbbq
- 12th November 2014, 04:52
Hey, I was wondering if anyone had code for or could help me write my own using the PIC16F88 to blink LEDs to a given song. What I would really like is to be able to set a color to different musical frequencies. So for example green would flash for lower frequencies (bass), blue for slightly higher frequencies, yellow/orange for higher than that (treble), red for higher yet, etc.

Thanks for the help!

peterdeco1
- 12th November 2014, 18:42
Hi. I did something like this several years ago using PULSIN. It is not too accurate though because music contains many different frequencies at a single time. I did however change the code to ADCIN. It would light up different colors of LEDs depending on the volume level. Hope this helps.

falingtrea
- 12th November 2014, 19:09
Do a google search for "pic color organ code" and you should find lots of examples.

Dickeysbbq
- 14th November 2014, 06:18
Hi. I did something like this several years ago using PULSIN. It is not too accurate though because music contains many different frequencies at a single time. I did however change the code to ADCIN. It would light up different colors of LEDs depending on the volume level. Hope this helps.

Yeah that’s why I was thinking to use like 3 or 4 colors and set each to a frequency range of musical pitch. I'm unfamiliar with the PULSIN command of PIC Basic would you still happen to have your code?

peterdeco1
- 17th November 2014, 15:17
I found it. I didn't use PULSIN, I used COUNT. Again I had inconsistent results. Maybe you can play with COUNT duration for better results. I used an array of red, green and blue leds. Lighting up 2 or more colors like red and blue makes purple.

Count PORTA.3, 10, FREQ
IF FREQ > 9 Then BLUEGREENLED
IF FREQ > 8 Then REDLED
IF FREQ > 7 Then GREENREDLED
IF FREQ > 6 Then GREENLED 'looking FOR 600HZ
IF FREQ > 5 Then BLUELED 'LOOKING FOR 500HZ
IF FREQ > 4 Then REDLED 'LOOKING FOR 400HZ
IF FREQ > 3 Then REDBLUELED '300HZ
IF FREQ > 2 Then WHITELED '200 HZ
IF FREQ < 1 Then Pause 300
IF FREQ < 1 Then Low PORTB.0 : Low PORTB.4 : Low PORTB.7 'OFF LEDS

Dickeysbbq
- 28th November 2014, 03:59
Anyone else have any experience programming LEDs to flash with a PIC? I'm looking into the PULSIN command but still a little confused on how exactly this is used to control the flashing of LEDS to music.
Thanks.

Archangel
- 28th November 2014, 04:56
The CLUE is pulsin, notice the word IN. This indicates data is going IN to the PIC. It would apply if you were sending data into the PIC to change the LEDs flash rate. To change something like LED brightness you would need PULSOUT or a PWM. Is this part of your other post about servos? Certainly the usage is similar and also applies to motor speed control, servo position, dimming lights . . .
Going back to those 70s color organs, had an audio output transformer in reverse, 8 ohm secondary used as primary with an R/C filter controlling 3 SCRs which switched the lamps.

Dickeysbbq
- 28th November 2014, 05:28
The CLUE is pulsin, notice the word IN. This indicates data is going IN to the PIC. It would apply if you were sending data into the PIC to change the LEDs flash rate. To change something like LED brightness you would need PULSOUT or a PWM. Is this part of your other post about servos? Certainly the usage is similar and also applies to motor speed control, servo position, dimming lights . . .
Going back to those 70s color organs, had an audio output transformer in reverse, 8 ohm secondary used as primary with an R/C filter controlling 3 SCRs which switched the lamps.

It is related, thank you for trying to help and I'm not trying to be rude here but it seems like you may know a fair amount on this yet are holding back. I appreciate you trying to get me to do the research however this is really only a very small part of the entire project I'm working on and would really like to just get it done as this is my first time using PICs so don't know a lot.

Thanks

Archangel
- 28th November 2014, 06:32
When I hold back, I simply do not post. There are much better coders here than Me, my main function here is to remove spam. Perhaps if you were to detail what you are trying to do, and possibly post some code for us to work with. I am going to take a far reach here and guess anamitronics? Like the old pizza shop robots? Tell me if I am way off base here. Lots of people here DO hold back when: 1. you have not attempted or shown that you have made an effort 2.When you are on the cusp of figuring it out, as you will become skilled more quickly if you do it yourself 3. if they sense you are a student who didn't pay proper attention in class.

Large projects can easily go sideways. Try to get each function to stand alone, as much as possible, then you can add them to main as include files much the same as "C" does or make them into sub routines.

Scampy
- 2nd December 2014, 21:15
I played about with a similar project a few years back. basically I had 16 patterns stored in the PIC, and then used a low pass filter to trigger the PIC so that it stepped through each pattern to the beat of the music. It worked to a fashion, and when the speed of the chase was set right it looked quite good.

The issue you are going to have is that you want a multi-frequency cross-over with tightly defined frequency bands which can then be fed to the PIC. To have the PIC connected to the music and then let it work out which frequencies could be done, but you would need a fast sampling loop and I don't think PBP has any direct commands for sampling the audio spectrum to place them into variables such as the example posted.

You will also find that you will get more assistance if you are open and post up real code you have written and are having issues with. - You must remember that some of the guys here are in this professionally and whilst they don't mind helping they won't write code for you for free. But they will (and often do) help when you post full code listings and help steer you down the correct path when things are not going to plan.