private static void Ads1115(I2cBus i2c) { var ads1115 = new ADS1115(i2c, 0x4A); char keyChar = ' '; do { if (Console.KeyAvailable) { keyChar = Console.ReadKey().KeyChar; } var ch0 = ads1115.ReadAdcSingleEnded(0); Thread.Sleep(10); var ch1 = ads1115.ReadAdcSingleEnded(1); Thread.Sleep(10); var v0 = ads1115.ConvertToVoltage(ch0); var v1 = ads1115.ConvertToVoltage(ch1); Console.WriteLine($"v0 {v0:F3} {ch0} v1 {v1:F3} {ch1}"); Thread.Sleep(300); } while (keyChar != 'x'); }
private static void Mcp4725(I2cBus i2c) { var mcp = new Mcp4725.Mcp4725(i2c); var ads1115 = new ADS1115(i2c, 0x4A); char keyChar = ' '; UInt16 outVar = 0; do { if (Console.KeyAvailable) { keyChar = Console.ReadKey().KeyChar; if (keyChar == '+') { outVar += 10; } if (keyChar == '-') { outVar -= 10; } } mcp.SetVoltage(outVar, false); var ch0 = ads1115.ReadAdcSingleEnded(0); Thread.Sleep(10); var v0 = ads1115.ConvertToVoltage(ch0); Console.WriteLine($"OutVar {outVar} In {v0}"); Thread.Sleep(300); } while (keyChar != 'x'); }
/// <summary> /// Test the ADS1115 ADC (or the KY-053 sensor module) together with a two-axis analog joystick (KY-023 module) /// Connect the joystick with the ADC as described in http://sensorkit.joy-it.net/index.php?title=KY-023_Joystick_Modul_(XY-Achsen). /// Note that I2C-Bus support must be enabled in config. /// </summary> public static void TestJoystick() { Console.Clear(); // Add device var device = Pi.I2C.AddDevice(ADS1015.ADS1x15ADDRESS); // The joystick module we're testing has also an extra digital signal when it is pressed down var inputPin = Pi.Gpio[Abstractions.BcmPin.Gpio24]; inputPin.PinMode = GpioPinDriveMode.Input; // For some reason, this command doesn't do anything right now. To set the pull-up mode, run the python KY-023 sample first. inputPin.InputPullMode = GpioPinResistorPullMode.PullUp; Console.WriteLine(ExitMessage); var adc = new ADS1115(device); while (true) { var a0 = adc.ReadChannel(0); var a1 = adc.ReadChannel(1); var a2 = adc.ReadChannel(2); // This 3rd channel can be connected to 3.3V or 0V to see that the reference values are converted correctly. bool pressed = inputPin.Read(); Console.WriteLine($"Button {(pressed ? "pressed" : "not pressed")}\nX:{a0}\nY:{a1}\nReference:{a2}"); if (Console.KeyAvailable) { var input = Console.ReadKey(true).Key; if (input == ConsoleKey.Escape) { break; } } } }
private static void Roboter(I2cBus i2c) { var pca9685 = new Pca9685.Pca9685(i2c, 0x40, 50); var axis1 = new ServoAxis(0, pca9685, 158, 529); // Savöx var axis2 = new ServoAxis(1, pca9685, 172, 519); // Spektrum var axis3 = new ServoAxis(2, pca9685, 126, 528); // Tower // var axis4 = new ServoAxis(3, pca9685, 150, 650); // var axis5 = new ServoAxis(4, pca9685, 150, 650); // var axis6 = new ServoAxis(5, pca9685, 150, 650); var ads1115 = new ADS1115(i2c, 0x4A); var ctrl = new XInputController(UserIndex.One); if (!ctrl.IsConnected) { Console.WriteLine("No Controller Conected"); Console.ReadKey(); return; } ctrl.StartAutoUpdate(); ctrl.ButtonPressed += axis3.OnButtonPressed; ctrl.Updated += axis1.OnUpdate; char keyChar = ' '; do { if (Console.KeyAvailable) { keyChar = Console.ReadKey().KeyChar; } Console.Clear(); if (ctrl.A) { axis1.MoveAbsolute(ctrl.LeftThumbX); axis2.MoveAbsolute(ctrl.LeftThumbY); } else { var ch0 = ads1115.ReadAdcSingleEnded(0); var ch1 = ads1115.ReadAdcSingleEnded(1); var pot0 = ads1115.Normalize(ch0); var pot1 = ads1115.Normalize(ch1); axis1.MoveAbsolute(pot0); axis2.MoveAbsolute(pot1); } //axis2.MoveAbsolute(ctrl.LeftThumbY); axis3.MoveAbsolute(ctrl.RightThumbY); // axis4.MoveAbsolute(ctrl.RightThumbX); // axis5.MoveAbsolute(ctrl.LeftTrigger); // axis6.MoveAbsolute(ctrl.RightTrigger); } while (!ctrl.Start && keyChar != 'x'); }