LED to music code


Closed Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Nov 2014
    Posts
    8

    Default LED to music code

    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!

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: LED to music code

    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.

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: LED to music code

    Do a google search for "pic color organ code" and you should find lots of examples.
    Tim Barr

  4. #4
    Join Date
    Nov 2014
    Posts
    8


    Did you find this post helpful? Yes | No

    Default Re: LED to music code

    Quote Originally Posted by peterdeco1 View Post
    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?
    Last edited by Dickeysbbq; - 14th November 2014 at 07:23.

  5. #5


    Did you find this post helpful? Yes | No

    Default Re: LED to music code

    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

  6. #6
    Join Date
    Nov 2014
    Posts
    8


    Did you find this post helpful? Yes | No

    Default Re: LED to music code

    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.
    Last edited by Dickeysbbq; - 28th November 2014 at 05:09.

  7. #7
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: LED to music code

    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.
    Last edited by Archangel; - 28th November 2014 at 06:02.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  8. #8
    Join Date
    Nov 2014
    Posts
    8


    Did you find this post helpful? Yes | No

    Default Re: LED to music code

    Quote Originally Posted by Archangel View Post
    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

  9. #9
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: LED to music code

    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.
    Last edited by Archangel; - 28th November 2014 at 07:43.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  10. #10
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: LED to music code

    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.

Similar Threads

  1. Replies: 5
    Last Post: - 21st January 2014, 17:10
  2. Replies: 11
    Last Post: - 29th November 2013, 17:42
  3. LED 'Dot' Bargraph Issues - Newbie Code!
    By SOTASOTA in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 15th February 2013, 20:25
  4. Replies: 5
    Last Post: - 7th February 2012, 18:58
  5. Driver code for 14 segment LED display
    By Durward Searcy in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 12th December 2004, 21:08

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts