private void read_key() { brick.Mailbox.Send("M", Box.Box0); Thread.Sleep(50); while (true) { if (light1.ReadLightLevel() == 0) { break; } Thread.Sleep(50); if (light2.ReadLightLevel() == 0) { break; } Thread.Sleep(50); if (light4.ReadLightLevel() == 0) { break; } if (state == QUITTING) { break; } Thread.Sleep(50); } if (light1.ReadLightLevel() == 0) { Console.WriteLine("Left"); } else if (light2.ReadLightLevel() == 0) { Console.WriteLine("Right"); } else if (light4.ReadLightLevel() == 0) { Console.WriteLine("Enter"); } brick.Mailbox.Send("O", Box.Box0); Thread.Sleep(200); }
private void timer1_Tick(object sender, EventArgs e) { switch (sensorType) { case "DIST": int iDistance; iDistance = sensorDistance.ReadDistance(); Thread.Sleep(50); lblSensorResult2.Text = "Closet object is " + iDistance + " cm"; break; case "ATTACK": int iDistance1; iDistance1 = sensorDistance.ReadDistance(); Thread.Sleep(50); lblSensorResult2.Text = "Closest object is " + iDistance1 + " cm"; do { circle(); if (iDistance1 < 35) { forward(); Thread.Sleep(2000); backward(); Thread.Sleep(2000); circle(); } } while (iDistance1 > 255); break; case "LIGHT": int value; value = sensorLight.ReadLightLevel(); Thread.Sleep(50); lblSensorResult.Text = "Colour light is " + value; break; } }
private bool check_movement_completed() { try { if (monitored_sensor.ReadLightLevel() != 0) { return(false); } Thread.Sleep(100); brick.Mailbox.Send("O", Box.Box0); Thread.Sleep(200); Console.WriteLine("Done"); return(true); } catch (Exception) { //Console.Error.WriteLine("NXTOperator: Exception on check_movement..."); //Console.Error.WriteLine(ex.ToString()); // unfortunately this happens sometimes, but recovers soon (too fast message stream?) return(false); } }