using System;
using System.Collections.Generic;
using System.Text;
using Bram.NxtSharp;
namespace LegoNxtConsoleSample
{
class Program
{
const string c_BluetoothComPort = "COM4";
static void pressureSensorValueChangedEventHandler(NxtSensor sensor)
{
if (sensor is NxtPressureSensor)
{
NxtPressureSensor pressureSensor = (NxtPressureSensor)sensor;
Console.Write("Pressure rawvalue:" + pressureSensor.RawValue + " means that sensor is ");
if (pressureSensor.IsPressed)
Console.WriteLine("pressed");
else
Console.WriteLine("not pressed");
}
else
{
Console.WriteLine("Problem: NxtPressureSensure expected but not received");
}
}
static void SensorEventingDemo()
{
Console.WriteLine("pressure sensor eventing demo, running for 30 seconds");
NxtBrick brick = new NxtBrick();
brick.COMPortName = c_BluetoothComPort;
brick.AutoPoll = true;
NxtPressureSensor pressureSensor = new NxtPressureSensor();
pressureSensor.AutoPoll = true;
pressureSensor.AutoPollDelay = 50;
pressureSensor.Brick = brick;
brick.Sensor1 = pressureSensor;
pressureSensor.ValueChanged += new SensorEvent(pressureSensorValueChangedEventHandler);
//best practice: connect all sensors and motors first
brick.Connect();
System.Threading.Thread.Sleep(30000);
brick.Disconnect();
}
static void Main(string[] args)
{
SensorEventingDemo();
}
}
}