/// <summary> /// This is where all sensor and motor properties are initialized /// </summary> /// <param name="bluetoothPortName"></param> public Scorpio(string bluetoothPortName) { Brick = new AForgeNxtBrickFacade(); BluetoothPortName = bluetoothPortName; // Sensors: // 1 TouchSensor = new TouchSensor(Brick, NxtBrick.Sensor.First); // 2 LightIntensitySensor = new LightSensor(Brick, NxtBrick.Sensor.Second); // 3 (shared) SoundLevelSensor = new SoundSensor(Brick, NxtBrick.Sensor.Third); SoundRatioSensor = new SoundDbaRatioSensor(Brick, NxtBrick.Sensor.Third); // 4 UltrasonicSensor = new UltrasonicSensor(Brick, NxtBrick.Sensor.Fourth); // Motor sensors: // 1 // Motors: // A,B,C MotorTail = new Motor(Brick, NxtBrick.Motor.A); MotorRight = new Motor(Brick, NxtBrick.Motor.B); MotorLeft = new Motor(Brick, NxtBrick.Motor.C); // Walk: WalkBehavior = new TwoMotorWalkBehavior(MotorLeft, MotorRight); }
public Form1() { InitializeComponent(); this.FormClosing += Form1_FormClosing; _updateUIDelegate = new updateUIDelegate(updateUI); label1.Text = "X"; label2.Text = "Y"; label3.Text = "Z"; label4.Text = ""; label5.Text = ""; label6.Text = ""; progressBar1.Maximum = maxRange; progressBar2.Maximum = maxRange; progressBar3.Maximum = maxRange; this.Text = "Freipost Hardware Demo"; try { us = new UltrasonicSensor(); } catch (Exception e) { MessageBox.Show("Device could not be found " + e.Message); this.Close(); } timer = new Timer(); timer.Interval = 1000; timer.Tick += Timer_Tick; timer.Start(); }
public ButtonTimerHostedService(IPIManager Pimanager) { _piManager = Pimanager; button = new Button(_piManager.grovePi, GrovePort.DigitalPin7); buzzer = new Buzzer(_piManager.grovePi, GrovePort.DigitalPin6); buzzer.Value = 10; lightSensor = new LightSensor(_piManager.grovePi, GrovePort.AnalogPin0); soundSesnor = new SoundSensor(_piManager.grovePi, GrovePort.AnalogPin1); ultrasonicSensor = new UltrasonicSensor(_piManager.grovePi, GrovePort.DigitalPin8); }
public static IProducer <Length> CreateComponent(this UltrasonicSensor ultrasonicSensor, Pipeline pipeline, TimeSpan samplingInterval) { if (ultrasonicSensor == null) { throw new ArgumentNullException(nameof(ultrasonicSensor)); } if (pipeline == null) { throw new ArgumentNullException(nameof(pipeline)); } return(Generators.Sequence(pipeline, new Length(0, LengthUnit.Centimeter), _ => ultrasonicSensor.Distance, samplingInterval)); }
static void Main(string[] args) { I2cConnectionSettings i2CConnectionSettings = new I2cConnectionSettings(1, GrovePi.DefaultI2cAddress); GrovePi grovePi = new GrovePi(I2cDevice.Create(i2CConnectionSettings)); UltrasonicSensor sensor = new UltrasonicSensor(grovePi, Iot.Device.GrovePiDevice.Models.GrovePort.DigitalPin7); while (true) { Console.WriteLine(sensor.Value); Thread.Sleep(200); } }
/// <summary> /// This is where all sensors and motors are stopped /// </summary> public void DisconnectAll() { // Stop sensing if (LightIntensitySensor.IsSensing()) { LightIntensitySensor.StopSensing(); } if (SoundLevelSensor.IsSensing()) { SoundLevelSensor.StopSensing(); } if (SoundRatioSensor.IsSensing()) { SoundRatioSensor.StopSensing(); } if (UltrasonicSensor.IsSensing()) { UltrasonicSensor.StopSensing(); } if (TouchSensor.IsSensing()) { TouchSensor.StopSensing(); } //TODO clear sensors? // Stop behaviors if (WalkBehavior.IsWalking) { WalkBehavior.Stop(); } // Stop motors if (MotorTail.IsRunning) { MotorTail.Stop(); } if (MotorRight.IsRunning) { MotorRight.Stop(); } if (MotorLeft.IsRunning) { MotorLeft.Stop(); } System.Threading.Thread.Sleep(1000); Brick.Disconnect(); IsConnectionStarted = false; }
static void Main(string[] args) { var us = new UltrasonicSensor(); double x_mm, y_mm, z_mm; while (true) { us.Measure(out x_mm, out y_mm, out z_mm); Console.WriteLine("X: " + x_mm.ToString() + " - Y: " + y_mm.ToString() + " - Z: " + z_mm.ToString()); System.Threading.Thread.Sleep(500); } }
private void btnStartMeasure_Click( object sender, RoutedEventArgs e ) { this.sensor = new UltrasonicSensor( this.viewModel.TriggerPinNumber, this.viewModel.EchoPinNumber ); // Measure and display distance every second. this.measureTimer.Tick += ( s, args ) => { this.viewModel.Distance = sensor.GetDistance(); }; this.measureTimer.Interval = TimeSpan.FromSeconds( 0.5 ); this.measureTimer.Start(); this.tblDistancePrompt.Visibility = Visibility.Visible; this.tblDistance.Visibility = Visibility.Visible; this.pbDistance.Visibility = Visibility.Visible; }
public Robot(Drivers drivers, IMoveFree moveFree, CallbackActions callbackActions) { _moveFree = moveFree; _noActionNotification = callbackActions.NoActionNotification; _actionNotification = callbackActions.ActionNotification; UltrasonicSensor = new UltrasonicSensor(drivers.UltraSonicSensorDriver); FrontSensor = new InfraRedSensor(drivers.InfraRedSensorDriverFront); BackSensor = new InfraRedSensor(drivers.InfraRedSensorDriverBack); States = RobotStateFactory.Create(Attack, MoveFree, ActionTwo, ActionThree, ActionFour, NoAction); }
internal static PocketView GetSvg(this UltrasonicSensor ultrasonicSensor) { var value = ultrasonicSensor.Distance.ToString("0.##"); return(g( g[transform: "matrix(0.159967,0,0,0.0762288,-22.0502,-7.71042)"]( CreatePath("M623.239,203.06C623.239,154.054 604.279,114.267 580.926,114.267L186.406,114.267C163.053,114.267 144.093,154.054 144.093,203.06L144.093,550.209C144.093,599.216 163.053,639.003 186.406,639.003L580.926,639.003C604.279,639.003 623.239,599.216 623.239,550.209L623.239,203.06Z", "fill:white;stroke:black;stroke-width:15.96px;") ), g[transform: "matrix(1,0,0,1,-756.787,-111.913)"]( _.text[x: "768.748px", y: "149.76px", style: TextStyle]("ULTRASOUND") ), g[@class: "UltrasoundLevel", transform: "matrix(1,0,0,1,-756.787,-120.913)"]( _.text[x: "785px", y: "149.76px", style: TextStyle](value) ), g[transform: "matrix(1.26023,0,0,1.26023,-975.766,-158.437)"]( _.circle[cx: "788.557", cy: "138.653", r: "8.673", style: "fill:rgb(235,235,235);fill-opacity:0;stroke:black;stroke-width:1.59px;"]() ), g[transform: "matrix(1.26023,0,0,1.26023,-933.441,-158.437)"]( _.circle[cx: "788.557", cy: "138.653", r: "8.673", style: "fill:rgb(235,235,235);fill-opacity:0;stroke:black;stroke-width:1.59px;"]() ) )); }
/// <summary> /// Main entry point /// </summary> /// <param name="args">unused</param> public static void Main(string[] args) { Console.WriteLine("Hello GrovePi!"); PinValue relay = PinValue.Low; I2cConnectionSettings i2CConnectionSettings = new I2cConnectionSettings(1, GrovePi.DefaultI2cAddress); _grovePi = new GrovePi(I2cDevice.Create(i2CConnectionSettings)); Console.WriteLine($"Manufacturer :{_grovePi.GrovePiInfo.Manufacturer}"); Console.WriteLine($"Board: {_grovePi.GrovePiInfo.Board}"); Console.WriteLine($"Firmware version: {_grovePi.GrovePiInfo.SoftwareVersion}"); // Specific example to show how to read directly a pin without a high level class _grovePi.PinMode(GrovePort.AnalogPin0, PinMode.Input); _grovePi.PinMode(GrovePort.DigitalPin2, PinMode.Output); _grovePi.PinMode(GrovePort.DigitalPin3, PinMode.Output); _grovePi.PinMode(GrovePort.DigitalPin4, PinMode.Input); // 2 high level classes UltrasonicSensor ultrasonic = new UltrasonicSensor(_grovePi, GrovePort.DigitalPin6); DhtSensor dhtSensor = new DhtSensor(_grovePi, GrovePort.DigitalPin7, DhtType.Dht11); int poten = 0; while (!Console.KeyAvailable) { Console.Clear(); poten = _grovePi.AnalogRead(GrovePort.AnalogPin0); Console.WriteLine($"Potentiometer: {poten}"); relay = (relay == PinValue.Low) ? PinValue.High : PinValue.Low; _grovePi.DigitalWrite(GrovePort.DigitalPin2, relay); Console.WriteLine($"Relay: {relay}"); _grovePi.AnalogWrite(GrovePort.DigitalPin3, (byte)(poten * 100 / 1023)); Console.WriteLine($"Button: {_grovePi.DigitalRead(GrovePort.DigitalPin4)}"); Console.WriteLine($"Ultrasonic: {ultrasonic}"); dhtSensor.Read(); Console.WriteLine($"{dhtSensor.DhtType}: {dhtSensor}"); Thread.Sleep(2000); } }
internal GrovePiAnalogUltrasonic(UltrasonicSensor ultrasonicSensor, string name, int sensorId, GrovePort port, bool rgbDisplay) : base(name, "cm", sensorId, SensorType.UltrasonicSensor, port, rgbDisplay) { _ultrasonicSensor = ultrasonicSensor; }
public MainPage() { this.InitializeComponent(); sensor = new UltrasonicSensor(); timer = new Timer(new TimerCallback(TimerTickAsync), null, 750, 750); }