public static void AdcTest1(List <string> argsList, Tlc1543 adc) { Console.WriteLine($"ADC Test1"); List <Tlc1543.Channel> channelList = new List <Tlc1543.Channel> { Tlc1543.Channel.A0, Tlc1543.Channel.A1, Tlc1543.Channel.A2, Tlc1543.Channel.A3, Tlc1543.Channel.A4, Tlc1543.Channel.A10 }; double delay; if (argsList.Count > 1) { delay = Convert.ToDouble(argsList[1]); } else { delay = 10; } while (true) { List <int> values = adc.ReadChannels(channelList); //read data for (int i = 0; i < values.Count; i++) { Console.Write($"{i}: {values[i],4} "); } Thread.Sleep((int)delay); Console.WriteLine(); } }
public static void AdcTest(List <string> argsList, Tlc1543 adc) { Console.WriteLine($"ADC Test"); double delay; byte sensorNumber; if (argsList.Count > 1) { delay = Convert.ToDouble(argsList[1]); } else { delay = 10; } if (argsList.Count > 2) { sensorNumber = Convert.ToByte(argsList[2]); } else { sensorNumber = 11; } while (true) { for (int i = 0; i < sensorNumber; i++) { Console.Write($"{i}: {adc.ReadChannel((Tlc1543.Channel)i),4} "); DelayHelper.DelayMilliseconds((int)delay, true); } Console.WriteLine(); } }
/// <summary> /// Main entry point /// </summary> public static void Main() { SoftwareSpi spi = new SoftwareSpi( clk: 25, sdi: 23, sdo: 24, cs: 5, settings: new SpiConnectionSettings(-1) { DataBitLength = Tlc1543.SpiDataBitLength }); Tlc1543 adc = new Tlc1543(spi); Channel[] channels = new Channel[] { Channel.A0, Channel.A1, Channel.A2, Channel.A3, Channel.A4 }; foreach (Channel channel in channels) { Console.WriteLine($"Channel {channel}: {adc.ReadChannel(channel)}"); } // or a bit faster // we ignore the first reading adc.ReadPreviousAndChargeChannel(channels[0]); for (int i = 0; i < channels.Length; i++) { // For last reading we need to pass something so let's pass test channel Channel nextChannel = i < channels.Length - 1 ? channels[i + 1] : Channel.SelfTestHalf; int previous = adc.ReadPreviousAndChargeChannel(nextChannel); Console.WriteLine($"Channel {channels[i]}: {previous}"); } // now continuously read from one channel Channel ch = Channel.A0; int numberOfReadings = 10; adc.ReadPreviousAndChargeChannel(ch); for (int i = 0; i < numberOfReadings; i++) { Console.WriteLine($"Channel {ch}: {adc.ReadPreviousAndChargeChannel(ch)}"); } }
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}"); } }