wait for input from touch sensor

HomeForumsMonoBrick EV3 Firmwarewait for input from touch sensor

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #4851
    Author Image
    Glenn arens
    Participant

    hello guys i’m trying to get a robot working which one touch runs away and when escaped is pressed the programs quit
    only problem is he ignores the on escape press. any though on this problem?

    here is my code:

    using System;
    using System.Threading;
    using MonoBrickFirmware.Movement;
    using MonoBrickFirmware.Display;
    using MonoBrickFirmware.Sensors;
    using MonoBrickFirmware.UserInput;

    namespace AutoRijdenMono
    {
    class Program
    {

    static void Main(string[] args)
    {
    Motor A = new Motor(MotorPort.OutA);
    Motor B = new Motor(MotorPort.OutD);
    Motor C = new Motor(MotorPort.OutC);
    ManualResetEvent terminateProgram = new ManualResetEvent(false);
    ButtonEvents buts = new ButtonEvents();
    EV3TouchSensor Sensor = new EV3TouchSensor(SensorPort.In1);
    buts.EscapePressed += () =>
    {
    terminateProgram.Set();
    };
    while (true)
    {

    LcdConsole.WriteLine(“Sensor:” + Sensor.ReadRaw());
    if (Sensor.ReadRaw() > 1000)
    {
    LcdConsole.WriteLine(“Ahh geraakt, wegwezen!”);
    A.SetPower(100);
    B.SetPower(100);
    C.SetPower(50);
    Thread.Sleep(200);
    C.SetPower(-50);
    Thread.Sleep(200);
    C.SetPower(50);
    Thread.Sleep(200);
    C.SetPower(-50);
    Thread.Sleep(200);
    C.SetPower(50);
    Thread.Sleep(200);
    C.SetPower(-50);
    Thread.Sleep(200);
    C.SetPower(50);
    Thread.Sleep(200);
    C.SetPower(-50);
    Thread.Sleep(200);
    C.SetPower(50);
    Thread.Sleep(200);
    C.SetPower(-50);
    Thread.Sleep(200);
    A.Off();
    B.Off();
    C.Off();
    }
    terminateProgram.WaitOne();
    }
    }
    }
    }

    #4852
    Author Image
    Tcm0
    Participant

    You use the button event and a loop. But that doesn’t work: You either have to use the button event or the loop.
    Here is a quick example on how to use buttons without event:
    `Buttons.ButtonStates TastenStatus = new Buttons.ButtonStates ();
    Buttons.Instance.LedPattern (1);
    do {
    TastenStatus = Buttons.Instance.GetKeypress();
    if (TastenStatus == Buttons.ButtonStates.Enter) { LcdConsole.WriteLine(“Enter is pressed.”); }
    else LcdConsole.WriteLine(Convert.ToString(TastenStatus) + ” is pressed.”);
    } while (TastenStatus != Buttons.ButtonStates.Escape);

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

Posted in

Make a donation