Scary Fac3: Haunted House Building Challenge winner

HomeForumsMonoBrick EV3 FirmwareScary Fac3: Haunted House Building Challenge winner

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #5060
    Author Image
    Tcm0
    Participant

    Image
    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 presentation

    Sourcecode:

    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;
    			}
    		}
    	}
    }
    #5063
    Author Image
    Anders Søborg
    Keymaster

    Hi there

    Sooo nice – shared on twitter and facebook and on

    monobrick.dk

    /Anders

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

You must be logged in to reply to this topic.

Posted in

Make a donation