My problem is that the robot, which should just remain in the program until the Escape Button is pressed, just stays in the while-loop. The current code looks like this:
using System;
using MonoBrickFirmware;
using MonoBrickFirmware.Movement;
using MonoBrickFirmware.Display;
using MonoBrickFirmware.Sensors;
using MonoBrickFirmware.UserInput;
using System.Threading;
namespace ColorSensorExample
{
class R_Main
{
public static void Main (string[] args)
{
R_Main main = new R_Main ();
}
public R_Main()
{
var sensor = new EV3ColorSensor (SensorPort.In2);
ButtonEvents buts = new ButtonEvents ();
buts.EscapePressed += new Action(onEscape);
while (true)
{
}
}
private void onEscape()
{
EventWaitHandle stopped = new ManualResetEvent (false);
stopped.Set ();
}
}
}
But it does work with the example from the Monobrick homepage:
using System;
using MonoBrickFirmware;
using MonoBrickFirmware.Movement;
using MonoBrickFirmware.Display;
using MonoBrickFirmware.Sensors;
using MonoBrickFirmware.UserInput;
using System.Threading;
namespace ColorSensorExample
{
class MainClass
{
public static void Main (string[] args)
{
EventWaitHandle stopped = new ManualResetEvent(false);
ColorMode[] modes = {ColorMode.Color, ColorMode.Reflection,
ColorMode.Ambient, ColorMode.Blue};
int modeIdx = 0;
var sensor = new ColorSensor(SensorPort.In1);
ButtonEvents buts = new ButtonEvents ();
buts.EscapePressed += () => {
stopped.Set();
};
buts.UpPressed += () => {
LcdConsole.WriteLine("Sensor value: " + sensor.ReadAsString());
};
buts.DownPressed += () => {
LcdConsole.WriteLine("Raw sensor value: " + sensor.ReadRaw());
};
buts.EnterPressed += () => {
modeIdx = (modeIdx+1)%modes.Length;
sensor.Mode = modes[modeIdx];
LcdConsole.WriteLine("Sensor mode is: " + modes[modeIdx]);
};
stopped.WaitOne();
}
}
}