Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.

wabash9000

Member Since 05 Oct 2010
Offline Last Active Jul 13 2013 03:33 AM
-----

#4165 Deadmau5 mask

Posted by wabash9000 on 24 October 2010 - 08:22 AM

hey guys, just finished my first netduino project. It's my Halloween costume for this year.

Big thanks to members hooked up and to bliptronics for help working out the input from my iphone.

Posted Image

http://www.youtube.com/watch?v=1OWVp4aJjic

/* Code to read the Spectrum Analyzer chip from bliptronics.com
 * http://www.bliptronics.com/item.aspx?ItemID=116
 * 
 * Important: Connect a wire from the 3.3v to the ahref on the shield to work with netduino.
 * 
 * * Based on code from bliptronics.com and arduino community assistance.
 * Port by: Joseph Francis
 */

using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;

namespace BlipSpectrumAnalyzer
{
    public class Program
    {
        static OutputPort spStrobe = new OutputPort(Pins.GPIO_PIN_D12, false);
        static OutputPort spReset = new OutputPort(Pins.GPIO_PIN_D13, false);
        static OutputPort redled = new OutputPort(Pins.GPIO_PIN_D1, false);
        static OutputPort greenled = new OutputPort(Pins.GPIO_PIN_D2,false);
        static OutputPort blueled = new OutputPort(Pins.GPIO_PIN_D3, false);
        static TimeSpan ts = new TimeSpan();
        static int beatCount;
        static int color;
        static AnalogInput spReadL = new AnalogInput(Pins.GPIO_PIN_A0);
        static AnalogInput spReadR = new AnalogInput(Pins.GPIO_PIN_A1);
        static bool music = false;
        const int MUSIC_MIN = 190;
        static Thread t = new Thread(new ThreadStart(light));

        static public void setupSpecrum()
        {
            spReset.Write(true);
            Thread.Sleep(1);
            spReset.Write(false);
            Thread.Sleep(1);
            beatCount = 0;
            color = 0;
        }


        static public void readSpecrum()
        {
            byte Band;
            for (Band = 0; Band < 7; Band++)
            {
                //--- Trigger strobe to make multiplexer jump
                spStrobe.Write(true);
                spStrobe.Write(false);
                if (Band == 0)
                {
                    int cVal = spReadL.Read();
                    cVal += spReadR.Read();
                    cVal /= 2;
                    Debug.Print(cVal.ToString());
                    if (cVal < MUSIC_MIN && ((Utility.GetMachineTime()-ts) > new TimeSpan(0, 0, 5) || ts.Equals(new TimeSpan())))
                    {
                        t = new Thread(new ThreadStart(light));
                        t.Start();
                        Thread.Sleep(454);

                    }
                    else if (cVal > 800)
                    {
                        if (!t.IsAlive)
                        {
                            t = new Thread(new ThreadStart(light));
                            t.Start();
                            ts = Utility.GetMachineTime();
                        }
                    }
                    else
                    {
                        Debug.Print(Utility.GetMachineTime().ToString());
                        if ((ts - Utility.GetMachineTime()) > new TimeSpan(0, 0, 5))
                        {
                            beatCount = 0;
                        }
                    }
                }
            }           
        }
        public static void light()
        {
            switch (color)
            {
                case 0:
                    Debug.Print("RED TICK " + beatCount);
                    redled.Write(true);
                    beatCount++;
                    
                    Thread.Sleep(125);
                    redled.Write(false);
                    break;
                case 1:
                    Debug.Print("GREEN TICK " + beatCount);
                    greenled.Write(true);
                    beatCount++;
                    Thread.Sleep(125);
                    greenled.Write(false);
                    break;
                case 2:
                    Debug.Print("BlUE TICK " + beatCount);
                    blueled.Write(true);
                    beatCount++;
                    Thread.Sleep(125);
                    blueled.Write(false);
                    break;
            };
            if (beatCount == 4)
            {
                beatCount = 0;
                color++;
                if (color == 3)
                {
                    color = 0;
                }
            }
        }
        public static void Main()
        {
            setupSpecrum();
            while (true)
            {
                readSpecrum();
            }
        }

    }
}



home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.