static void Flash() { const int lightCount = 12; var settings = new SpiConnectionSettings(0, 0) { ClockFrequency = 2_400_000, Mode = SpiMode.Mode0, DataBitLength = 8 }; // Create a Neo Pixel x8 stick on spi 0.0 var spi = SpiDevice.Create(settings); var neo = new Ws2812b(spi, lightCount); // Display basic colors for 5 sec var img = neo.Image; img.Clear(); for (var x = 0; x < lightCount; x++) { System.Console.WriteLine("White: " + x.ToString()); img.SetPixel(x, 0, Color.White); } neo.Update(); System.Threading.Thread.Sleep(10000); img.Clear(); neo.Update(); }
public DisplayService() { Lines = 8; Columns = 8; _spiDevice = SpiDevice.Create(spiSettings); _ledDisplay = new Ws2812b(_spiDevice, Columns, Lines); }
static void Main() { // Create a Neo Pixel x8 stick on spi 0.0 var spi = new UnixSpiDevice(new SpiConnectionSettings(0, 0)); var neo = new Ws2812b(spi, 8); // Display basic colors for 5 sec BitmapImageNeo3 img = neo.Image; img.SetPixel(0, 0, Color.White); img.SetPixel(1, 0, Color.Red); img.SetPixel(2, 0, Color.Green); img.SetPixel(3, 0, Color.Blue); img.SetPixel(4, 0, Color.Yellow); img.SetPixel(5, 0, Color.Cyan); img.SetPixel(6, 0, Color.Magenta); img.SetPixel(7, 0, Color.FromArgb(unchecked ((int)0xffff8000))); neo.Update(); System.Threading.Thread.Sleep(5000); // Fade in first pixel byte b = 0; img.Clear(); while (true) { img.SetPixel(0, 0, Color.FromArgb(0xff, b, b, b)); neo.Update(); System.Threading.Thread.Sleep(10); b++; } }
public static void LedTest(List <string> argsList, Ws2812b led) { Console.WriteLine($"Led Test"); //double delay; //if (argsList.Count > 1) delay = Convert.ToDouble(argsList[1]); //else delay = 10; //BitmapImage img = led.Image; //img.Clear(); //img.SetPixel(0, 0, Color.White); //img.SetPixel(1, 0, Color.Red); //img.SetPixel(2, 0, Color.Green); //img.SetPixel(3, 0, Color.Blue); //img.Clear(); //while (true) //{ // for (byte b = 0; b < 255; b++) // { // img.SetPixel(0, 0, Color.FromArgb(0xff, b, 0, 0)); // img.SetPixel(1, 0, Color.FromArgb(0xff, 0, b, 0)); // img.SetPixel(2, 0, Color.FromArgb(0xff, 0, 0, b)); // img.SetPixel(3, 0, Color.FromArgb(0xff, b, 0, b)); // led.Update(); // Console.WriteLine($"{b}"); // DelayHelper.DelayMilliseconds((int)delay, true); // } //} }
public void Stop() { try { if (!_started) { return; } //if were updating lights already spin waiting for it to finish before we try to clear the lights do { System.Threading.Thread.Sleep(5); } while (_updating); _updating = true; if (_config.Model.ffmpegCaptureSettings.useFFMpeg && _config.Model.ffmpegCaptureSettings.lightsLocal) { foreach (var light in _lights) { light.Color = Color.FromRgb(_resetColor.R, _resetColor.G, _resetColor.B); light.LastColor = light.Color; } _lightStrip?.Image?.Clear(); _lightStrip?.Update(); _device?.Dispose(); _device = null; _lightStrip = null; } else { SerializeLightMetadata(-1); foreach (var light in _lights) { light.Color = Color.FromRgb(_resetColor.R, _resetColor.G, _resetColor.B); light.LastColor = light.Color; SerializeLightColor(light.Color); } SerializePad(); //Send packets and then reset streams to start foreach (var stream in _serializeStreams) { _lightClientSocket.SendTo(stream.Value.ToArray(), _lightClientEndpoint); stream.Value.Seek(0, SeekOrigin.Begin); } _currentStream = 0; } _started = false; } catch (Exception ex) { _ = Task.Run(() => _logger?.WriteLog(ex?.ToString())); } _updating = false; }
public Ws2812bAdapter(IOptions <LedOptions> options) { _count = options.Value.LedCount; var settings = new SpiConnectionSettings(0, 0) { ClockFrequency = 2_800_000, Mode = SpiMode.Mode0, DataBitLength = 8 }; var spi = SpiDevice.Create(settings); _ledTape = new Ws2812b(spi, _count); _image = _ledTape.Image; }
public LightStrip(int count, ILogger <LightStrip> logger) { _logger = logger; LedCount = count; var settings = new SpiConnectionSettings(0, 0) { ClockFrequency = 2_400_000, Mode = SpiMode.Mode0, DataBitLength = 8 }; // Create a Neo Pixel x8 stick on spi 0.0 var spi = new UnixSpiDevice(settings); Device = new Ws2812b(spi, count); }
public TestController(ILogger <TestController> logger) { _logger = logger ?? throw new NotImplementedException(logger.GetType().Name); var settings = new SpiConnectionSettings(0, 0) { ClockFrequency = 2_400_000, Mode = SpiMode.Mode0, DataBitLength = 8 }; var spi = SpiDevice.Create(settings); matrixDevice = new Ws2812b(spi, 32, 8); matrixImage = matrixDevice.Image; matrixImage.Clear(); _logger.LogInformation("Image: {width}x{height}", matrixImage.Width, matrixImage.Height); }
static void Main() { var settings = new SpiConnectionSettings(0, 0) { ClockFrequency = 2_400_000, Mode = SpiMode.Mode0, DataBitLength = 8 }; // Create a Neo Pixel x8 stick on spi 0.0 var spi = new UnixSpiDevice(settings); #if WS2808 var neo = new Ws2808(spi, count); #else var neo = new Ws2812b(spi, count); #endif // Display basic colors for 5 sec BitmapImage img = neo.Image; img.Clear(); img.SetPixel(0, 0, Color.White); img.SetPixel(1, 0, Color.Red); img.SetPixel(2, 0, Color.Green); img.SetPixel(3, 0, Color.Blue); img.SetPixel(4, 0, Color.Yellow); img.SetPixel(5, 0, Color.Cyan); img.SetPixel(6, 0, Color.Magenta); img.SetPixel(7, 0, Color.FromArgb(unchecked ((int)0xffff8000))); neo.Update(); System.Threading.Thread.Sleep(5000); // Fade in first pixel byte b = 0; img.Clear(); while (true) { img.SetPixel(0, 0, Color.FromArgb(0xff, b, b, b)); neo.Update(); System.Threading.Thread.Sleep(10); b++; } } }
private void DrawTest(Ws2812b device) { var image = device.Image; image.Clear(); var heart = new HeartIcon(Color.Crimson); var fadeOut = false; while (true) { if (_stateHandler.GetCurrentState().StateCode != StateCode.TestConnection) { break; } var b = 1; while (b > 0) { foreach (var pixel in heart.Pixels) { image.SetPixel(pixel.x, pixel.y, Color.FromArgb(0xff, b, 0, 0)); } device.Update(); Thread.Sleep(10); if (fadeOut) { b--; } else { b++; if (b == 120) { fadeOut = true; } } } Thread.Sleep(200); fadeOut = false; } }
public LedStripTranslation(int height = Constants.LedHeight, int width = Constants.LedWidth) { Height = height; Width = width; SpiConnectionSettings settings = new SpiConnectionSettings(0, 0) { ClockFrequency = 2_400_000, Mode = SpiMode.Mode0, DataBitLength = 8 }; SpiDevice spi = SpiDevice.Create(settings); Device = new Ws2812b(spi, width, height); Image = Device.Image; Device.Update(); }
public ControllerManager(List <Matrix> matrices) { this.matrices = matrices; matrices.ForEach(x => totalLedCount += x.TotalLedCount); //Create Settings settings = new SpiConnectionSettings(0, 0) { ClockFrequency = 2_400_000, Mode = SpiMode.Mode0, DataBitLength = 8 }; //Create SPI interfacing Device spi = SpiDevice.Create(settings); device = new Ws2812b(spi, totalLedCount); image = device.Image; ClearLEDs(); }
static async Task Main(string[] args) { System.Console.WriteLine("Starting"); const int lightCount = 12; var settings = new SpiConnectionSettings(0, 0) { ClockFrequency = 2_400_000, Mode = SpiMode.Mode0, DataBitLength = 8 }; // Create a Neo Pixel x8 stick on spi 0.0 var spi = SpiDevice.Create(settings); var neo = new Ws2812b(spi, lightCount); var img = neo.Image; img.Clear(); for (var x = 0; x < lightCount; x++) { img.SetPixel(x, 0, Color.White); } neo.Update(); MMALCamera cam = MMALCamera.Instance; for (var y = 0; y < 50; y++) { using (var imgCaptureHandler = new ImageStreamCaptureHandler($"_testing{y}.jpg")){ await cam.TakePicture(imgCaptureHandler, MMALEncoding.JPEG, MMALEncoding.I420); } Step(); } img.Clear(); neo.Update(); cam.Cleanup(); }
public void Dispose() { _lights?.Clear(); _lights = null; _lightClientSocket?.Dispose(); _lightClientSocket = null; _lightClientEndpoint = null; if (_serializeStreams != null) { foreach (var stream in _serializeStreams) { stream.Value.Dispose(); } _serializeStreams.Clear(); _serializeStreams = null; } _device?.Dispose(); _device = null; _lightStrip?.Image?.Clear(); _lightStrip = null; GC.SuppressFinalize(this); }
private static Ws2812b CreateInstance() { try { var count = 256; // number of LEDs var settings = new SpiConnectionSettings(0, 0) { ClockFrequency = 2_400_000, Mode = SpiMode.Mode0, DataBitLength = 8 }; var spi = SpiDevice.Create(settings); var device = new Ws2812b(spi, count); device.Image.Clear(); device.Update(); return(device); } catch (Exception ex) { // Log error //throw new Exception("Error connecting to the LED matrix"); throw ex; } }
public void Enable(Accessories accessory) { try { switch (accessory) { case Accessories.Camera: if (camera is null) { this.camera = new Camera(); } else { Disable(Accessories.Camera); this.camera = new Camera(); } break; case Accessories.IMU: if (imu is null) { this.imu = new Mpu6050(I2cDevice.Create( new I2cConnectionSettings(1, Mpu6050.DefaultI2cAddress))); } else { Disable(Accessories.IMU); this.imu = new Mpu6050(I2cDevice.Create( new I2cConnectionSettings(1, Mpu6050.DefaultI2cAddress))); } break; case Accessories.MotorL: if (motorL is null) { this.motorL = DCMotor.Create(6, 12, 13); } else { Disable(Accessories.MotorL); this.motorL = DCMotor.Create(6, 12, 13); } break; case Accessories.MotorR: if (motorR is null) { this.motorR = DCMotor.Create(26, 20, 21); } else { Disable(Accessories.MotorR); this.motorR = DCMotor.Create(26, 20, 21); } break; case Accessories.Motors: Enable(Accessories.MotorL); Enable(Accessories.MotorR); break; case Accessories.ADC: if (adc is null) { this.adc = new Tlc1543(24, 5, 23, 25); } else { Disable(Accessories.ADC); this.adc = new Tlc1543(24, 5, 23, 25); } break; case Accessories.IR: if (ir is null) { this.ir = new IrReceiver(17); } else { Disable(Accessories.IR); this.ir = new IrReceiver(17); } break; case Accessories.Sonar: if (sonar is null) { this.sonar = new Hcsr04(22, 27); } else { Disable(Accessories.Sonar); this.sonar = new Hcsr04(22, 27); } break; case Accessories.LED: if (led is null) { this.led = new Ws2812b(18, 4); } else { Disable(Accessories.LED); this.led = new Ws2812b(18, 4); } break; case Accessories.CPUTemp: if (cpuTemperature is null) { this.cpuTemperature = new CpuTemperature(); } //else { Disable(led); this.led = new Ws2812b(18, 4); } break; case Accessories.All: foreach (var item in Enum.GetValues(typeof(Accessories))) { Enable((Accessories)item); } break; default: Console.WriteLine("Something went wrong (Enabling accessories)"); break; } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine($"Enabling accessory: {Enum.GetName(typeof(Accessories), accessory)} failed."); System.Diagnostics.Debug.WriteLine($"Exception message: {ex.Message}"); Console.WriteLine($"Enabling accessory: {Enum.GetName(typeof(Accessories), accessory)} failed."); Console.WriteLine($"Exception message: {ex.Message}"); } }
public void Start() { try { if (_started) { return; } if (_lights != null) { _lights.Clear(); } else { _lights = new List <StripLighterLight>(); } if (_config.Model.lightStripSettings.lights?.Any() ?? false) { foreach (var light in _config.Model.lightStripSettings.lights) { _lights.Add(new StripLighterLight() { Location = new PointF(light.X, light.Y), Color = Color.FromRgb(0, 0, 0), LastColor = null }); } } if (_config.Model.ffmpegCaptureSettings.useFFMpeg && _config.Model.ffmpegCaptureSettings.lightsLocal) { try { var settings = new SpiConnectionSettings(0, 0) { ClockFrequency = 2400000, Mode = SpiMode.Mode0, DataBitLength = 8 }; _device = SpiDevice.Create(settings); _lightStrip = new Ws2812b(_device, _lights.Count); } catch (Exception ex) { _device = null; _lightStrip = null; Console.WriteLine(ex.ToString()); _ = Task.Run(() => _logger?.WriteLog(ex.ToString())); } } else { if (_lightClientSocket != null) { _lightClientSocket.Dispose(); } _lightClientSocket = new Socket(_config.Model.lightStripSettings.remoteAddressIp.AddressFamily, SocketType.Dgram, ProtocolType.Udp); _lightClientEndpoint = new IPEndPoint(_config.Model.lightStripSettings.remoteAddressIp, _config.Model.lightStripSettings.remotePort); if (_serializeStreams != null) { foreach (var stream in _serializeStreams) { stream.Value.Dispose(); } _serializeStreams.Clear(); } _serializeStreams = new Dictionary <byte, MemoryStream>(); //each light takes 3 bytes for its color _packetColorSize = _packetMaxSize - _packetHeaderSize; _packetCount = (byte)Math.Ceiling((_lights.Count * _colorByteCount) / (double)(_packetColorSize)); for (byte i = 0; i < _packetCount; ++i) { _serializeStreams.Add(i, new MemoryStream(_packetMaxSize)); } } _started = true; _frameTimeSpan = TimeSpan.FromMilliseconds(1000 / _config.Model.lightStripSettings.updateFrameRate); } catch (Exception ex) { _ = Task.Run(() => _logger?.WriteLog(ex?.ToString())); } }
public LedStripOutput(int numberofleds) { strip = Initialise(numberofleds); stripImage = strip.Image; }