Home→Forums→MonoBrick EV3 Firmware→Scary Fac3: Haunted House Building Challenge winner
- This topic has 1 reply, 2 voices, and was last updated 9 years, 11 months ago by Anders Søborg.
Viewing 2 posts - 1 through 2 (of 2 total)
-
AuthorPosts
-
December 18, 2014 at 19:05 #5060
Tcm0Participant
Today I found out that I won the haunted house building challenge by Lego (Link).
You might ask yourself why I write about that in this forum. That is because the robot was completely written in C#. This is not a very advanced project but it works and does it’s job 🙂Links:
– Project page
– Video presentationSourcecode:
using System; using MonoBrickFirmware; using MonoBrickFirmware.Display; using MonoBrickFirmware.UserInput; using System.Threading; using System.Net; using System.Threading.Tasks; using System.IO; using MonoBrickFirmware.Movement; using MonoBrickFirmware.Sensors; using MonoBrickFirmware.Sound; namespace MonoBrickHelloWorld { class MainClass { public static void Main (string[] args) { LcdConsole.WriteLine ("Happy Halloween!"); Parallel.Invoke ( () => Lights(), () => MainAction(), () => Flash() ); Thread.Sleep(50000); } /// <summary> /// This method flashes the spotlights when the gyrosensor moves. /// </summary> public static void Flash () { EV3GyroSensor GyroSensor = new EV3GyroSensor (SensorPort.In2, GyroMode.AngularVelocity); Motor LED = new Motor (MotorPort.OutA); while (true) { if (GyroSensor.Read () >= 2) { LED.SetPower (100); PlayDracula (); LED.SetPower (0); } } } public static void PlayDracula() { Speaker Speaker = new Speaker (75); Speaker.PlayTone (440, 250); //A Speaker.PlayTone ((ushort)391.995, 250); //G Speaker.PlayTone (440, 1500); //A Speaker.PlayTone ((ushort)391.995, 250); //G Speaker.PlayTone ((ushort)349.228, 250); //F Speaker.PlayTone ((ushort)329.628, 250); //E Speaker.PlayTone ((ushort)293.665, 250); //D Speaker.PlayTone ((ushort)277.183, 500); //C# Speaker.PlayTone ((ushort)293.665, 750); //D } /// <summary> /// This method moves the mouth of the head if you press the touchsensor. /// </summary> public static void MainAction() { EV3TouchSensor TouchS = new EV3TouchSensor(SensorPort.In1); Motor MouthMotor = new Motor (MotorPort.OutC); while (true) { if (TouchS.IsPressed () == true) { MouthMotor.SetPower (25); Thread.Sleep (500); MouthMotor.SetPower (0); } } } /// <summary> /// This method is used for the pulsing lights of the robot. /// </summary> public static void Lights () { Random rnd = new Random (); sbyte CurrentValue = 0; sbyte MaxValue = 0; Motor EyeLights = new Motor (MotorPort.OutB); //Light while (true) { MaxValue = (sbyte) rnd.Next (60, 90); for (sbyte i = CurrentValue; i <= MaxValue; i++) { EyeLights.SetPower (i); System.Threading.Thread.Sleep (100); } CurrentValue = MaxValue; MaxValue = (sbyte) rnd.Next (10, 40); for (sbyte i = CurrentValue; i >= MaxValue; i--) { EyeLights.SetPower (i); System.Threading.Thread.Sleep (100); } CurrentValue = MaxValue; } } } }
December 18, 2014 at 20:13 #5063
Anders SøborgKeymaster -
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic.
Follow