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);
}
///
/// This method flashes the spotlights when the gyrosensor moves.
///
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);
//Thread.Sleep (100);
PlayDracula ();
LED.SetPower (0);
}
}
}
public static void PlayDracula()
{
Speaker Lautsprecher = new Speaker (75);
Lautsprecher.PlayTone (440, 250); //A
Lautsprecher.PlayTone ((ushort)391.995, 250); //G
Lautsprecher.PlayTone (440, 1500); //A
Lautsprecher.PlayTone ((ushort)391.995, 250); //G
Lautsprecher.PlayTone ((ushort)349.228, 250); //F
Lautsprecher.PlayTone ((ushort)329.628, 250); //E
Lautsprecher.PlayTone ((ushort)293.665, 250); //D
Lautsprecher.PlayTone ((ushort)277.183, 500); //Cis
Lautsprecher.PlayTone ((ushort)293.665, 750); //D
}
///
/// This method moves the mouth of the head if you press the touchsensor.
///
public static void MainAction()
{
EV3TouchSensor Beruhrungssensor = new EV3TouchSensor(SensorPort.In1);
Motor MundMotor = new Motor (MotorPort.OutC);
while (true)
{
if (Beruhrungssensor.IsPressed () == true) {
MundMotor.SetPower (25);
Thread.Sleep (500);
MundMotor.SetPower (0);
}
}
}
///
/// This method is used for the pulsing lights of the robot.
///
public static void Lights ()
{
Random rnd = new Random ();
sbyte CurrentValue = 0;
sbyte MaxValue = 0;
Motor LichtAugen = new Motor (MotorPort.OutB);
//Licht
while (true) {
MaxValue = (sbyte) rnd.Next (60, 90);
for (sbyte i = CurrentValue; i <= MaxValue; i++) {
LichtAugen.SetPower (i);
System.Threading.Thread.Sleep (100);
}
CurrentValue = MaxValue;
MaxValue = (sbyte) rnd.Next (10, 40);
for (sbyte i = CurrentValue; i >= MaxValue; i--) {
LichtAugen.SetPower (i);
System.Threading.Thread.Sleep (100);
}
CurrentValue = MaxValue;
}
}
}
}