private void SimpleSample_Loaded(object sender, RoutedEventArgs e)
        {
            // First we need to create the controller. This is the object that is responsible for controlling the
            // output of the system. The visual controller is an extension of the controller that feeds data back to 
            // a UI. Two controller are provided in the SDK, a software PWM controller, and a SPI bus controller.
            m_controller = new VisualLedController();

            // This is only needed for the VisualController
            m_controller.AddVisualListener(this);

            // Now create the LEDs. All we need to do is tell the system if they are multi color or single colored.
            m_led1 = new Led(LedType.RBG);
            m_led2 = new Led(LedType.RBG);
            m_led3 = new Led(LedType.RBG);
            m_led4 = new Led(LedType.RBG);
            m_led5 = new Led(LedType.RBG);

            // Next wrap the LEDs in an animated LED object so we can make them animated nicely.
            m_animatedLed1 = new AnimatedLed(m_led1);
            m_animatedLed2 = new AnimatedLed(m_led2);
            m_animatedLed3 = new AnimatedLed(m_led3);
            m_animatedLed4 = new AnimatedLed(m_led4);
            m_animatedLed5 = new AnimatedLed(m_led5);

            // Last, associate the LEDs with the controller. This actually binds the LED objects to a given controller.
            // The only thing we must specify here is what slot the LED is in. What a slot means is defined by whatever
            // controller you're using, for example in PWM a slot is the same as a pin; for SPI the slot is the same as the output
            // For RGB LEDs the slot passed is for the first pin (red), blue and green are assumed to be slot + 1 and slot + 2.
            m_controller.AssociateLed(0, m_led1);
            m_controller.AssociateLed(3, m_led2);
            m_controller.AssociateLed(6, m_led3);
            m_controller.AssociateLed(9, m_led4);
            m_controller.AssociateLed(12, m_led5);

            // Now set the intensity on the LEDs to match the UI.
            m_led1.Intensity = 1.0;
            m_led2.Intensity = 1.0;
            m_led3.Intensity = 1.0;
            m_led4.Intensity = 1.0;
            m_led5.Intensity = 1.0;

            // Setup the animation thread.
            m_timer = new DispatcherTimer();
            m_timer.Tick += AnimationTimer_Tick;
            m_timer.Interval = new TimeSpan(0, 0, 1);
            m_timer.Start();

            // Done.
            isSetup = true;
        }
示例#2
0
        public LedController()
        {
            // Create the controller
            m_controller = new TLC5947Controller(6,13);
            m_controller.ToggleAnimation(true);

            // Create the LED array
            m_leds = new AnimatedLed[5];

            // Create the LEDs
            m_leds[0] = new AnimatedLed(LedType.RBG, true);
            m_leds[1] = new AnimatedLed(LedType.RBG, true);
            m_leds[2] = new AnimatedLed(LedType.RBG, true);
            m_leds[3] = new AnimatedLed(LedType.RBG, true);
            m_leds[4] = new AnimatedLed(LedType.RBG, true);

            // Associate the LEDs
            m_controller.AssoicateLed(0, m_leds[0].GetLed());
            m_controller.AssoicateLed(3, m_leds[1].GetLed());
            m_controller.AssoicateLed(6, m_leds[2].GetLed());
            m_controller.AssoicateLed(9, m_leds[3].GetLed());
            m_controller.AssoicateLed(15, m_leds[4].GetLed());
        }
示例#3
0
 private void SetWindValue(AnimatedLed led, double wind)
 {
     // Fade from blue to white.
     led.Animate(wind, wind, 1.0, 1, TimeSpan.FromSeconds(1), AnimationType.Linear);
 }
示例#4
0
 private void SetTempValue(AnimatedLed led, double temp)
 {
     // Fade between blue and red.
     double blue = 1 - temp;
     double red = temp;
     led.Animate(red, 0, blue, 1, TimeSpan.FromSeconds(1), AnimationType.Linear);
 }
示例#5
0
        private void SetColor(AnimatedLed led, double value, TimeSpan time)
        {
            double red = 0, green = 0, blue = 0;

            // Wrap the value if we hit 1.
            if (value == 1)
            {
                value = 0;
            }

            // Find what bucket we are in
            int rangeBot = (int)Math.Floor(((value) * m_blueRange.Length));
            int rangeTop = rangeBot + 1;
            if (rangeTop == m_blueRange.Length)
            {
                rangeTop = 0;
            }

            // Find where we are in that bucket-
            double placeInRange = ((value * m_blueRange.Length * m_blueRange.Length) % m_blueRange.Length) / 6.0;
            if(value == 1.0)
            {
                // Special case
                placeInRange = 1;
            }

            // Find the values per color
            red = m_redRange[rangeBot] + (m_redRange[rangeTop] - m_redRange[rangeBot]) * placeInRange;
            green = m_greenRange[rangeBot] + (m_greenRange[rangeTop] - m_greenRange[rangeBot]) * placeInRange;
            blue = m_blueRange[rangeBot] + (m_blueRange[rangeTop] - m_blueRange[rangeBot]) * placeInRange;

            // Animate the LED
            led.Animate(red, green, blue, 1.0, time, AnimationType.Linear);
        }