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 EV3ColorSensor(SensorPort.In1); ButtonEvents buts = new ButtonEvents (); LcdConsole.WriteLine("Use color on port1"); LcdConsole.WriteLine("Up read value"); LcdConsole.WriteLine("Down raw value"); LcdConsole.WriteLine("Enter change mode"); LcdConsole.WriteLine("Esc. terminate"); 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 set to: " + modes[modeIdx]); }; stopped.WaitOne(); }
public static void Main (string[] args) { ManualResetEvent terminateProgram = new ManualResetEvent (false); ButtonEvents buts = new ButtonEvents (); HiTecCompassSensor compass = new HiTecCompassSensor(SensorPort.In1); HiTecColorSensor colorSensor = new HiTecColorSensor(SensorPort.In2); HiTecTiltSensor tilt = new HiTecTiltSensor(SensorPort.In3); LcdConsole.WriteLine("Use compass on port1"); LcdConsole.WriteLine("Use color on port2"); LcdConsole.WriteLine("Use tilt on port3"); LcdConsole.WriteLine("Up read compass"); LcdConsole.WriteLine("Down read tilt"); LcdConsole.WriteLine("Enter read color"); LcdConsole.WriteLine("Esc. terminate"); buts.EscapePressed += () => { terminateProgram.Set (); }; buts.UpPressed += () => { LcdConsole.WriteLine ("Compass sensor: " + compass.ReadAsString()); }; buts.EnterPressed += () => { LcdConsole.WriteLine ("Color sensor: " + colorSensor.ReadAsString()); LcdConsole.WriteLine ("Color index: " + colorSensor.ReadColorIndex()); }; buts.DownPressed += () => { LcdConsole.WriteLine ("Tilt : " + tilt.ReadAsString()); }; terminateProgram.WaitOne (); }
public static void Main (string[] args) { ManualResetEvent terminateProgram = new ManualResetEvent(false); var soundSensor = new NXTSoundSensor(SensorPort.In1); ButtonEvents buts = new ButtonEvents (); LcdConsole.WriteLine("Use sound on port1"); LcdConsole.WriteLine("Up sensor value"); LcdConsole.WriteLine("Enter read raw"); LcdConsole.WriteLine("Down change mode"); LcdConsole.WriteLine("Esc. terminate"); buts.EscapePressed += () => { terminateProgram.Set(); }; buts.UpPressed += () => { LcdConsole.WriteLine("Sensor value:" + soundSensor.ReadAsString()); }; buts.EnterPressed += () => { LcdConsole.WriteLine("Sensor raw value:" + soundSensor.ReadRaw()); }; buts.DownPressed += () => { if(soundSensor.Mode == SoundMode.SoundDB){ soundSensor.Mode = SoundMode.SoundDBA; } else{ soundSensor.Mode = SoundMode.SoundDB; } LcdConsole.WriteLine("Sensor mode is now: " + soundSensor.Mode); }; terminateProgram.WaitOne(); }
public static void Main (string[] args) { ManualResetEvent terminateProgram = new ManualResetEvent(false); var lightSensor = new NXTLightSensor(SensorPort.In1); ButtonEvents buts = new ButtonEvents (); LcdConsole.WriteLine("Use light on port1"); LcdConsole.WriteLine("Up value "); LcdConsole.WriteLine("Down change mode"); LcdConsole.WriteLine("Esc. terminate"); buts.EscapePressed += () => { terminateProgram.Set(); }; buts.UpPressed += () => { LcdConsole.WriteLine("Sensor value:" + lightSensor.ReadAsString()); }; buts.DownPressed += () => { if(lightSensor.Mode == LightMode.Ambient){ lightSensor.Mode = LightMode.Relection; } else{ lightSensor.Mode = LightMode.Ambient; } LcdConsole.WriteLine("Sensor mode is now: " + lightSensor.Mode); }; terminateProgram.WaitOne(); }
public static void Main (string[] args) { ButtonEvents buts = new ButtonEvents (); var tokenSource = new CancellationTokenSource(); var token = tokenSource.Token; var dialog = new InfoDialog("Attach distance sensor", false); dialog.Show(); var sensor = SensorAttachment.Wait<MSAngleSensor>(token);//wait for sensor to attached on any port LcdConsole.WriteLine("Up reset angle"); LcdConsole.WriteLine("Down read RMP"); LcdConsole.WriteLine("Enter read angle"); LcdConsole.WriteLine("Left read raw"); LcdConsole.WriteLine("Esc. terminate"); buts.EscapePressed += () => { tokenSource.Cancel(); }; buts.EnterPressed += () => { LcdConsole.WriteLine ("Angle: " + sensor.ReadAngle().ToString()); }; buts.UpPressed += () => { LcdConsole.WriteLine ("Reset angle"); sensor.ResetAngle(); }; buts.DownPressed += () => { LcdConsole.WriteLine ("Read RPM: " + sensor.ReadRPM().ToString()); }; buts.LeftPressed += () => { LcdConsole.WriteLine ("Read raw: " + sensor.ReadRAW().ToString()); }; token.WaitHandle.WaitOne(); }
public static void Main (string[] args) { ManualResetEvent terminateProgram = new ManualResetEvent (false); GyroMode[] modes = {GyroMode.Angle, GyroMode.AngularVelocity}; int modeIdx = 0; ButtonEvents buts = new ButtonEvents (); var gyro = new EV3GyroSensor(SensorPort.In2, GyroMode.Angle); LcdConsole.WriteLine("Use gyro on port 1"); LcdConsole.WriteLine("Up read value"); LcdConsole.WriteLine("Down rotation count"); LcdConsole.WriteLine("Left reset"); LcdConsole.WriteLine("Enter change mode"); LcdConsole.WriteLine("Esc. terminate"); buts.EscapePressed += () => { terminateProgram.Set (); }; buts.UpPressed += () => { LcdConsole.WriteLine ("Gyro sensor: " + gyro.ReadAsString()); }; buts.EnterPressed += () => { modeIdx = (modeIdx+1)%modes.Length; gyro.Mode = modes[modeIdx]; LcdConsole.WriteLine("Mode: " + modes[modeIdx]); }; buts.DownPressed += () => { LcdConsole.WriteLine ("Rotation count: " + gyro.RotationCount()); }; buts.LeftPressed += () => { LcdConsole.WriteLine ("Reset"); gyro.Reset(); }; terminateProgram.WaitOne (); }
public static void Main(string[] args) { object sensorLock = new object(); bool run = true; ISensor[] sensor = new ISensor[4]; for (int i = 0; i < 4; i++) { sensor[i] = null; } using (SensorListner listner = new SensorListner()) { listner.SensorAttached += delegate(ISensor obj) { lock (sensorLock) { if (obj != null) { sensor[(int) obj.Port] = obj; Console.WriteLine(obj.GetSensorName() + " attached on " + obj.Port); } } }; listner.SensorDetached += delegate(SensorPort obj) { lock (sensorLock) { Console.WriteLine(sensor[(int) obj] + " detached from " + obj); sensor[(int) obj] = null; } }; ButtonEvents buts = new ButtonEvents(); buts.EscapePressed += delegate { run = false; }; while (run) { lock (sensorLock) { /*for (int i = 0; i < sensor.Length; i++) { if (sensor[i] != null) { typeLabel [i].Text = sensor[i].GetSensorName (); modeLabel [i].Text = sensor[i].SelectedMode (); valueLabel[i].Text = sensor[i].ReadAsString (); } else { typeLabel [i].Text = "Not connected"; modeLabel [i].Text = "-"; valueLabel [i].Text = "-"; } }*/ } System.Threading.Thread.Sleep(1000); } } }
private void CreateButtonEvents () { buttonEvents = new ButtonEvents (); buttonEvents.DownPressed += () => ExecuteButtonAction (activeMenuItem.OnDownPressed); buttonEvents.UpPressed += () => ExecuteButtonAction (activeMenuItem.OnUpPressed); buttonEvents.LeftPressed += () => ExecuteButtonAction (activeMenuItem.OnLeftPressed); buttonEvents.RightPressed += () => ExecuteButtonAction (activeMenuItem.OnRightPressed); buttonEvents.EnterPressed += () => ExecuteButtonAction (activeMenuItem.OnEnterPressed); buttonEvents.EscapePressed += () => ExecuteButtonAction (activeMenuItem.OnEscPressed); }
static void Main(string[] args) { var terminateProgram = new ManualResetEvent(false); var cubeSolver = new CubeSolver(); var buts = new ButtonEvents(); buts.EscapePressed += () => terminateProgram.Set(); Task.Factory.StartNew(cubeSolver.Run); terminateProgram.WaitOne(); cubeSolver.Stop(); //var solution = Search.solution(Tools.randomCube(), 26, false); }
public static void Main (string[] args) { ManualResetEvent terminateProgram = new ManualResetEvent (false); ButtonEvents buts = new ButtonEvents (); var gyro = new HiTecGyroSensor(SensorPort.In1, 600); LcdConsole.WriteLine("Use gyro on port1"); LcdConsole.WriteLine("Enter read value"); LcdConsole.WriteLine("Esc. terminate"); buts.EscapePressed += () => { terminateProgram.Set (); }; buts.EnterPressed += () => { LcdConsole.WriteLine ("Gyro sensor: " + gyro.ReadAsString()); }; terminateProgram.WaitOne (); }
public static void Main (string[] args) { using (ButtonEvents buts = new ButtonEvents ()) { var tokenSource = new CancellationTokenSource (); var token = tokenSource.Token; buts.EscapePressed += tokenSource.Cancel; var dialog = new InfoDialog ("Attach distance sensor"); dialog.Show (); var sensor = SensorAttachment.Wait<MSDistanceSensor> (token);//wait for sensor to attached on any port if (!token.IsCancellationRequested) { LcdConsole.WriteLine ("Up power on"); LcdConsole.WriteLine ("Down power off"); LcdConsole.WriteLine ("Enter read sensor"); LcdConsole.WriteLine ("Left read voltage"); LcdConsole.WriteLine ("Right read range type"); LcdConsole.WriteLine ("Esc. terminate"); buts.EnterPressed += () => { LcdConsole.WriteLine ("Sensor reading: " + sensor.ReadAsString ()); }; buts.UpPressed += () => { LcdConsole.WriteLine ("Power on"); sensor.PowerOn (); }; buts.DownPressed += () => { LcdConsole.WriteLine ("Power off"); sensor.PowerOff (); }; buts.LeftPressed += () => { LcdConsole.WriteLine ("Voltage: " + sensor.GetVolgage ()); }; buts.RightPressed += () => { LcdConsole.WriteLine ("Sensor range is : " + sensor.GetRange ()); }; } token.WaitHandle.WaitOne (); } }
public static void Main (string[] args) { const string to = "*****@*****.**"; const string from = "*****@*****.**"; const string password = "******"; ManualResetEvent terminateProgram = new ManualResetEvent(false); var colorSensor = new EV3ColorSensor(SensorPort.In1); ButtonEvents buts = new ButtonEvents (); SmtpClient smptpClient = new SmtpClient("smtp.gmail.com", 587); smptpClient.EnableSsl = true; smptpClient.UseDefaultCredentials = false; smptpClient.Credentials = new NetworkCredential(from, password); smptpClient.DeliveryMethod = SmtpDeliveryMethod.Network; ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; }; MailMessage message = new MailMessage(); message.To.Add(to); message.From = new MailAddress(from); message.Subject = "Color mail from my EV3"; LcdConsole.Clear(); LcdConsole.WriteLine("Use color on port1"); LcdConsole.WriteLine("Enter send mail"); LcdConsole.WriteLine("Esc. terminate"); buts.EscapePressed += () => { terminateProgram.Set(); }; buts.EnterPressed += () => { LcdConsole.WriteLine("Sending email"); try{ message.Body = "EV3 read color: " + colorSensor.ReadColor(); smptpClient.Send(message); LcdConsole.WriteLine("Done sending email"); } catch(Exception e) { LcdConsole.WriteLine("Failed to send email"); Console.WriteLine(e.StackTrace); } }; terminateProgram.WaitOne(); message = null; }
public static void Main(string[] args) { ManualResetEvent terminateProgram = new ManualResetEvent(false); Motor motor = new Motor (MotorPort.OutA); // pull the arm back slightly to the starting position ResetArmLocation (motor); // a loop needs to run to watch the arm and reset the switch if someone is rude enough to push it Task.Factory.StartNew(() => MainLoop(motor)); // Setup the down button to terminate the app ButtonEvents buts = new ButtonEvents (); buts.DownPressed += () => { motor.Off(); terminateProgram.Set(); }; terminateProgram.WaitOne(); }
public static void Main (string[] args) { ManualResetEvent terminateProgram = new ManualResetEvent(false); var touchSensor = new EV3TouchSensor(SensorPort.In1); //svar touchSensor = new NXTTouchSensor(SensorPort.In1); ButtonEvents buts = new ButtonEvents (); LcdConsole.WriteLine("Use touch on port1"); LcdConsole.WriteLine("Up read"); LcdConsole.WriteLine("Down read raw"); LcdConsole.WriteLine("Esc. terminate"); buts.EscapePressed += () => { terminateProgram.Set(); }; buts.UpPressed += () => { LcdConsole.WriteLine("Sensor value:" + touchSensor.ReadAsString()); }; buts.DownPressed += () => { LcdConsole.WriteLine("Raw sensor value: " + touchSensor.ReadRaw()); }; terminateProgram.WaitOne(); }
public static void Main(string[] args) { new Motor(MotorPort.OutA).Off(); Lcd.Instance.ShowPicture(MonoPicture.Picture); Font f = Font.MediumFont; Point offset = new Point(0,25); Point p = new Point(10, Lcd.Height-75); Point boxSize = new Point(100, 24); Rectangle box = new Rectangle(p, p+boxSize); ButtonEvents buts = new ButtonEvents(); int val = 7; buts.EnterPressed += () => { Lcd.Instance.Clear(); Lcd.Instance.WriteTextBox(f, box + offset*0, "Value = " + val.ToString(), true); Lcd.Instance.WriteTextBox(f, box + offset*1, "Hello World!!", false); Lcd.Instance.WriteTextBox(f, box + offset*2, "Hello World!!", true); Lcd.Instance.Update (); val++; }; buts.UpPressed += () => { Lcd.Instance.Clear(); Lcd.Instance.DrawBitmap(monoLogo, new Point((int)(Lcd.Width-monoLogo.Width)/2,10)); Lcd.Instance.Update(); }; buts.DownPressed += () => { Lcd.Instance.TakeScreenShot(); Lcd.Instance.Clear(); Lcd.Instance.WriteTextBox(f, box + offset*1, "Screen Shot", true); Lcd.Instance.Update(); }; buts.EscapePressed += () => stopped.Set(); stopped.WaitOne(); Lcd.Instance.WriteTextBox(f, box + offset*0, "Done!", true); Lcd.Instance.Update(); }
public static void Main (string[] args) { IRChannel[] channels = {IRChannel.One, IRChannel.Two, IRChannel.Three, IRChannel.Four}; int channelIdx = 0; ManualResetEvent terminateProgram = new ManualResetEvent(false); var sensor = new EV3IRSensor(SensorPort.In1); ButtonEvents buts = new ButtonEvents (); LcdConsole.WriteLine("Use IR on port1"); LcdConsole.WriteLine("Up distance"); LcdConsole.WriteLine("Down beacon location"); LcdConsole.WriteLine("Enter read command"); LcdConsole.WriteLine("Left change channel"); LcdConsole.WriteLine("Right read as string"); LcdConsole.WriteLine("Esc. terminate"); buts.EscapePressed += () => { terminateProgram.Set(); }; buts.UpPressed += () => { LcdConsole.WriteLine("Distance " + sensor.ReadDistance() + " cm"); }; buts.EnterPressed += () => { LcdConsole.WriteLine("Remote command " + sensor.ReadRemoteCommand() + " on channel " + sensor.Channel); }; buts.DownPressed += () => { BeaconLocation location = sensor.ReadBeaconLocation(); LcdConsole.WriteLine("Beacon location: " + location.Location + " Beacon distance: " + location.Distance + " cm"); }; buts.LeftPressed += () => { channelIdx = (channelIdx+1)%channels.Length; sensor.Channel = channels[channelIdx]; LcdConsole.WriteLine("Channel is set to: " + channels[channelIdx]); }; buts.RightPressed += () => { LcdConsole.WriteLine(sensor.ReadAsString()); }; terminateProgram.WaitOne(); }
public static void Main (string[] args) { EventWaitHandle stopped = new ManualResetEvent (false); int centerX = Lcd.Width / 2; int centerY = Lcd.Height / 2; Point center = new Point(centerX,centerY); int refreshRate = 100; bool run = true; ButtonEvents buts = new ButtonEvents (); buts.EscapePressed += () => { stopped.Set (); run = false; }; while (run) { for (int k = 0; k < 4; k++) { for (int i = 1; i < centerY; i++) { Lcd.Clear (); Lcd.DrawCircle(center, (ushort)i, true, true); Lcd.Update (); stopped.WaitOne (refreshRate); } for (int i = centerY - 1; i > 0; i--) { Lcd.Clear (); Lcd.DrawCircle(center, (ushort)i, true, true); Lcd.Update (); stopped.WaitOne (refreshRate); } } for (int k = 0; k < 20; k++) { Lcd.Clear(); Lcd.DrawHLine(center, centerX/2, true); stopped.WaitOne (refreshRate); Lcd.Clear(); Lcd.DrawVLine(center, centerY/2, true); } } }
public static void Main(string[] args) { Console.WriteLine ("Resetting the motors"); TouchSensor ts = new TouchSensor(SensorPort.In2); Motor motorFwd = new Motor(MotorPort.OutB); Motor motorTurn = new Motor(MotorPort.OutC); Motor motorSwitch = new Motor(MotorPort.OutA); Motor motorArm = new Motor(MotorPort.OutD); motorArm.On (-60); ButtonEvents buts = new ButtonEvents(); bool keepGoing = true; while (keepGoing) { buts.EscapePressed += () => { keepGoing = false; }; if (ts.IsPressed ()) { keepGoing = false; } } motorArm.Off (); switchMode (); keepGoing = true; TouchSensor ts2 = new TouchSensor(SensorPort.In4); motorArm.On (-60); while (keepGoing) { buts.EscapePressed += () => { keepGoing = false; }; if (ts2.IsPressed ()) { keepGoing = false; } } motorArm.Off (); switchMode (); motorArm.ResetTacho (); motorFwd.ResetTacho (); motorSwitch.ResetTacho (); motorTurn.ResetTacho (); }
public static void Main (string[] args) { Bitmap monoLogo = Bitmap.FromResouce(Assembly.GetExecutingAssembly(), "monologo.bitmap"); EventWaitHandle stopped = new ManualResetEvent(false); Lcd.ShowPicture(MonoPicture.Picture); Font f = Font.MediumFont; Point offset = new Point(0,25); Point p = new Point(10, Lcd.Height-75); Point boxSize = new Point(100, 24); Rectangle box = new Rectangle(p, p+boxSize); using (ButtonEvents buts = new ButtonEvents ()) { int val = 7; buts.EnterPressed += () => { Lcd.Clear (); Lcd.WriteTextBox (f, box + offset * 0, "Value = " + val.ToString (), true); Lcd.WriteTextBox (f, box + offset * 1, "Hello EV3!!", false); Lcd.WriteTextBox (f, box + offset * 2, "Hello World!!", true); Lcd.Update (); val++; }; buts.UpPressed += () => { Lcd.Clear (); Lcd.DrawBitmap (monoLogo, new Point ((int)(Lcd.Width - monoLogo.Width) / 2, 10)); Lcd.Update (); }; buts.DownPressed += () => { Lcd.TakeScreenShot (); Lcd.Clear (); Lcd.WriteTextBox (f, box + offset * 1, "Screen Shot", true); Lcd.Update (); }; buts.EscapePressed += () => stopped.Set (); stopped.WaitOne (); } Lcd.WriteTextBox(f, box + offset*0, "Done!", true); Lcd.Update(); }
public static void Main (string[] args) { string soundFileName = "/home/root/apps/SoundTest.wav"; ManualResetEvent terminateProgram = new ManualResetEvent(false); var speaker = new Speaker (50); ButtonEvents buts = new ButtonEvents (); LcdConsole.WriteLine("Up beep"); LcdConsole.WriteLine("Down buzz"); LcdConsole.WriteLine("Enter play soundfile"); LcdConsole.WriteLine("Esc. terminate"); buts.EscapePressed += () => { terminateProgram.Set(); }; buts.UpPressed += () => { LcdConsole.WriteLine("Beep"); speaker.Beep(); }; buts.DownPressed += () => { LcdConsole.WriteLine("Buzz"); speaker.Buzz(); }; buts.EnterPressed += () => { LcdConsole.WriteLine("Play sound file"); try{ speaker.PlaySoundFile(soundFileName); } catch(Exception e) { LcdConsole.WriteLine("Failed to play " + soundFileName); LcdConsole.WriteLine("Exception" + e.Message); LcdConsole.WriteLine("Stack trace " + e.StackTrace); } }; terminateProgram.WaitOne(); }
public static void Main (string[] args) { ManualResetEvent terminateProgram = new ManualResetEvent (false); string fbToken = "CAACpSl1Qm3cBAHAMyZAY...";//This is not valied var fb = new FacebookClient(fbToken); Font f = Font.MediumFont; Point offset = new Point(0,25); Point p = new Point(10, Lcd.Height-75); Point boxSize = new Point(100, 24); Rectangle box = new Rectangle(p, p+boxSize); var colorSensor = new EV3ColorSensor (SensorPort.In1); ButtonEvents buts = new ButtonEvents (); LcdConsole.WriteLine("Use color on port1"); LcdConsole.WriteLine("Enter post value"); LcdConsole.WriteLine("Esc. terminate"); buts.EscapePressed += () => { terminateProgram.Set(); }; buts.EnterPressed += () => { Color color = colorSensor.ReadColor(); Lcd.Clear(); Lcd.WriteTextBox(f, box + offset*0, "Color: " + color, true); Lcd.WriteTextBox(f, box + offset*1, "Send to Facebook" + color, true); Lcd.Update(); colorSensor.ReadColor(); var me = fb.Get("monobrick.dk") as JsonObject; var uid = me["id"]; string url = string.Format("{0}/{1}", uid, "feed"); var argList = new Dictionary<string, object>(); argList["message"] = "A program running MonoBrick Firmware was aked to read the color sensor. Color read: " + colorSensor.ReadColor().ToString(); fb.Post(url, argList); }; terminateProgram.WaitOne (); }
public static void Main (string[] args) { ManualResetEvent terminateProgram = new ManualResetEvent (false); UltraSonicMode[] modes = {UltraSonicMode.Centimeter, UltraSonicMode.Inch, UltraSonicMode.Listen}; int modeIdx = 0; ButtonEvents buts = new ButtonEvents (); var sensor = new EV3UltrasonicSensor(SensorPort.In1, modes[modeIdx]); LcdConsole.WriteLine("Use sonic on port1"); LcdConsole.WriteLine("Up change mode"); LcdConsole.WriteLine("Enter read"); LcdConsole.WriteLine("Esc. terminate"); buts.EscapePressed += () => { terminateProgram.Set (); }; buts.UpPressed += () => { modeIdx = (modeIdx+1)%modes.Length; sensor.Mode = modes[modeIdx]; LcdConsole.WriteLine("Mode: " + modes[modeIdx]); }; buts.EnterPressed += () => { LcdConsole.WriteLine (sensor.ReadAsString()); }; terminateProgram.WaitOne (); }
public void SuspendButtonEvents () { if (buttonEvents != null) { buttonEvents.Kill (); buttonEvents = null; } }