/// <summary> /// Writes an LED value to the device. /// </summary> /// <param name="led">LED value to write.</param> private void WriteLEDValue(APA102LED led) { var sendBright = (int)((31.0m * led.Brightness)) & 31; WriteByte(Convert.ToByte(224 | sendBright)); WriteByte(Convert.ToByte(led.Blue)); WriteByte(Convert.ToByte(led.Green)); WriteByte(Convert.ToByte(led.Red)); }
/// <summary> /// Initializes the APA102. /// /// Caution: /// This is required before accessing other /// methods in this class. /// </summary> /// <returns>Task.</returns> public void Initialize(GpioController gpioController) { Logger.Log(this, "InitializeAsync"); // Setup LEDs. for (int i = 0; i < NUMBER_OF_LEDS; i++) { leds[i] = new APA102LED(); } // Setup pins. dataPin = gpioController.OpenPin(GPIO_NUMBER_DATA); clockPin = gpioController.OpenPin(GPIO_NUMBER_CLOCK); csPin = gpioController.OpenPin(8); dataPin.SetDriveMode(GpioPinDriveMode.Output); clockPin.SetDriveMode(GpioPinDriveMode.Output); csPin.SetDriveMode(GpioPinDriveMode.Output); WriteLEDValues(); }