Home→Forums→MonoBrick EV3 Firmware→wait for input from touch sensor
Tagged: button press, input, touch sensor
- This topic has 1 reply, 2 voices, and was last updated 10 years, 3 months ago by Tcm0.
-
AuthorPosts
-
September 18, 2014 at 12:22 #4851
Glenn arensParticipanthello 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();
}
}
}
}September 18, 2014 at 14:44 #4852
Tcm0ParticipantYou 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); -
AuthorPosts
You must be logged in to reply to this topic.
Follow