public void OnLoop() { if (Saturation > 1) { Saturation = 1; } if (Saturation < 0) { Saturation = 0; } if (Value > 1) { Value = 1; } if (Value < 0) { Value = 0; } /* convert to rgb */ HsvToRgb.Convert(Hue, Saturation, Value, out _r, out _g, out _b); _r = _averageR.Process(_r); _g = _averageG.Process(_g); _b = _averageB.Process(_b); /* update CANifier's LED strip */ Platform.Hardware.canifier.SetLEDOutput(_r, CTRE.CANifier.LEDChannel.LEDChannelA); Platform.Hardware.canifier.SetLEDOutput(_g, CTRE.CANifier.LEDChannel.LEDChannelB); Platform.Hardware.canifier.SetLEDOutput(_b, CTRE.CANifier.LEDChannel.LEDChannelC); }
/** * Updates the LED strip (Talon/HERO) when given angle. To be used with Pigeon * * @param Hue Angle in degrees */ static void UpdateLedStrip_Pigeon(float Hue) { /* 75% brigtness */ float Brightness = 0.75f; /* Hue provided angle from pigeon */ float HueDeg = Hue; /* Constant saturation */ float Saturation = 1; /* Constant value */ float Value = 1; /* Output after HSV to RGB conversion */ uint R, G, B; /* Convert HSV to RGB */ HsvToRgb.Convert(HueDeg, Saturation, Value, out R, out G, out B); /* Modify RGB values based on brightness */ float Red = R * 1f / 255f * Brightness; float Green = G * 1f / 255f * Brightness; float Blue = B * 1f / 255f * Brightness; /* Update RGB values with current RGB */ _LEDStripController.Red = Red; _LEDStripController.Green = Green; _LEDStripController.Blue = Blue; /* Update the LED strip through HERO */ _LEDStripController.Process(); /* Update the LED strip through Talon SRX */ CommandLedStrip_Talon(Red, Green, Blue, 10, _TalonID); }
public void OnLoop() { /* just ramp through the outer rim of the HSV color wheel */ _saturation = 1; _theta += 1; if (_theta >= 360) { _theta = 0; } /* push saturation to the outter rim of the HSV color wheel */ _saturation *= 3.0f; if (_saturation > 1) { _saturation = 1; } /* convert to rgb */ float r, g, b; HsvToRgb.Convert(_theta, _saturation, _value, out r, out g, out b); /* update CANifier's LED strip */ Platform.Hardware.canifier_LedStrip_RCRADIO.SetLEDOutput(r, CTRE.Phoenix.CANifier.LEDChannel.LEDChannelA); Platform.Hardware.canifier_LedStrip_RCRADIO.SetLEDOutput(g, CTRE.Phoenix.CANifier.LEDChannel.LEDChannelB); Platform.Hardware.canifier_LedStrip_RCRADIO.SetLEDOutput(b, CTRE.Phoenix.CANifier.LEDChannel.LEDChannelC); }
/** * Updates the LED strip (Talon/HERO) when given Brightness, X, and Y * * @param Brightness Brightness value from 0 to 1, modifies RGB values * @param X X value used when finding the angle for hue * @param Y Y value used when finding the angle for hue */ static void UpdateLedStrip(float Brightness, float X, float Y) { /* The values of the HSV are explained here, * https://en.wikipedia.org/wiki/HSL_and_HSV */ /* Square it to get bright quickly */ Brightness = Brightness * Brightness; /* Angle */ float HueDeg = 0; /* Finds the angle of the left Stick for hue */ if (Y != 0 || X != 0) { /* Find the inverse tangent of X-axis and Y-axis of left joystick for angle */ HueDeg = (float)System.Math.Atan2(Y, X) * 180f / (float)System.Math.PI; /* Keep the angle positive */ if (HueDeg < 0) { HueDeg += 360.0f; } } /* Find the saturation of HSV based on the X and Y value */ float Saturation = (float)System.Math.Sqrt(X * X + Y * Y); /* Constant the value of HSV */ float Value = 1.0f; /* Output after HSV to RGB conversion */ uint R, G, B; /* Convert HSV to RGB */ HsvToRgb.Convert(HueDeg, Saturation, Value, out R, out G, out B); /* Modify RGB values based on brightness */ float Red = R * 1f / 255f * Brightness; float Green = G * 1f / 255f * Brightness; float Blue = B * 1f / 255f * Brightness; /* Update RGB values with current RGB */ _LEDStripController.Red = Red; _LEDStripController.Green = Green; _LEDStripController.Blue = Blue; /* Update the LED strip through HERO */ _LEDStripController.Process(); /* Update the LED strip through Talon SRX */ CommandLedStrip_Talon(Red, Green, Blue, 10, _TalonID); }
public void OnLoop() { /* select how to control LED strip */ if (false) { /* get the drive train and produce a unique color per drivetrain state */ float f = Platform.Hardware.drivetrain.Forward; float t = Platform.Hardware.drivetrain.Turn; _theta = (float)System.Math.Atan2(f, t) * 180f / (float)System.Math.PI; _saturation = (float)System.Math.Sqrt(f * f + t * t); } else { /* just ramp through the outer rim of the HSV color wheel */ _saturation = 1; _theta += 1; if (_theta >= 360) { _theta = 0; } } /* push saturation to the outter rim of the HSV color wheel */ _saturation *= 3.0f; if (_saturation > 1) { _saturation = 1; } /* convert to rgb */ float r, g, b; HsvToRgb.Convert(_theta, _saturation, _value, out r, out g, out b); /* update CANifier's LED strip */ Platform.Hardware.canifier_LedStrip_RCRADIO.SetLEDOutput(r, CTRE.CANifier.LEDChannel.LEDChannelA); Platform.Hardware.canifier_LedStrip_RCRADIO.SetLEDOutput(g, CTRE.CANifier.LEDChannel.LEDChannelB); Platform.Hardware.canifier_LedStrip_RCRADIO.SetLEDOutput(b, CTRE.CANifier.LEDChannel.LEDChannelC); }
public void RunForever() { /* get an X,Y, and btn value. These could come from potentiometers for example, or USB gamepad */ Microsoft.SPOT.Hardware.AnalogInput aiBtn = new Microsoft.SPOT.Hardware.AnalogInput(CTRE.HERO.IO.Port1.Analog_Pin3); Microsoft.SPOT.Hardware.AnalogInput aiX = new Microsoft.SPOT.Hardware.AnalogInput(CTRE.HERO.IO.Port1.Analog_Pin4); Microsoft.SPOT.Hardware.AnalogInput aiY = new Microsoft.SPOT.Hardware.AnalogInput(CTRE.HERO.IO.Port1.Analog_Pin5); /* loop forever */ while (true) { /* loop sleep */ Thread.Sleep(5); /* get x,y, and button */ bool btn = aiBtn.Read() < 0.5f; float x = (float)aiX.Read() * 2f - 1f; // [-1,1] float y = (float)aiY.Read() * 2f - 1f; // [-1,1] x = Deadband(x); y = Deadband(y); /* figure out next color based on current mode */ if (_colorWheelMode) { /* spin around the top circular slice of an HSV surface, * https://en.wikipedia.org/wiki/HSL_and_HSV */ /* calc sat and hue, use 100% for value */ float hueDeg = 0; if (y != 0 || x != 0) { hueDeg = (float)System.Math.Atan2(y, x) * 180f / (float)System.Math.PI; /* keep the angle positive */ if (hueDeg < 0) { hueDeg += 360f; } } float sat = (float)System.Math.Sqrt(x * x + y * y); float value = 1f; /* convert to rgb */ uint color; uint r, g, b; HsvToRgb.Convert(hueDeg, sat, value, out r, out g, out b); color = r; color <<= 8; color |= g; color <<= 8; color |= b; /* set all LEDs to one color, controlled by analog signals */ _heroPixels.setColor(color, 0, _heroPixels.NumberPixels); } else { /* just ramp through the predetermined color sequence */ uint color = _colorSequence[_colIdx]; _heroPixels.setColor(color, _pixelIdx, 1); } /* update LEDs using SPI*/ _heroPixels.writeOutput(); /* iterate to next pixel */ if (++_pixelIdx >= _heroPixels.NumberPixels) { /* back to first pixel */ _pixelIdx = 0; /* step to next color when using the predetermined sequence */ if (++_colIdx >= _colorSequence.Length) { _colIdx = 0; } } /* detect on-press event on button to change mode. */ if (btn && !_lastBtn) { _colorWheelMode = !_colorWheelMode; } _lastBtn = btn; } }