public HalloweenFrankGhost( IReceivesColor light, DigitalOutput2 air, AudioPlayer audioPlayer, [System.Runtime.CompilerServices.CallerMemberName] string name = "") : base(name) { pulsatingLow.ConnectTo(light); levelsPlayback.Output.Controls(b => light.SetBrightness(b, this.controlToken)); OutputPower.Subscribe(x => { if (x) { LockDevices(air, light); air.SetValue(true, this.controlToken); light.SetColor(Color.Red, this.controlToken); pulsatingLow.Start(token: this.controlToken); } else { pulsatingLow.Stop(); UnlockDevices(); } }); PowerOn .SetLoop(true) .SetMaxRuntime(S(60)) .SetUp(ins => { pulsatingLow.Stop(); }) .RunAction(ins => { audioPlayer.PlayEffect("Thriller2.wav", levelsPlayback); // The control token is optional since it's passed in via the Subroutine light.SetColor(Color.Purple); var cts = levelsPlayback.Start(this.controlToken); ins.WaitFor(S(45)); cts.Cancel(); }) .TearDown(ins => { light.SetColor(Color.Red); pulsatingLow.Start(token: this.controlToken); }); PowerOff.RunAction(ins => { audioPlayer.PlayEffect("Happy Halloween.wav", 0.15); ins.WaitFor(S(5)); }); }
public HalloweenGrumpyCat( Dimmer3 light, DigitalOutput2 air, AudioPlayer audioPlayer, [System.Runtime.CompilerServices.CallerMemberName] string name = "") : base(name) { pulsatingLow.ConnectTo(light); pulsatingHigh.ConnectTo(light); OutputPower.Subscribe(x => { if (x) { LockDevices(air, light); air.SetValue(true, this.controlToken); pulsatingLow.Start(token: this.controlToken); } else { pulsatingLow.Stop(); UnlockDevices(); } }); PowerOn .SetLoop(true) .SetMaxRuntime(S(20)) .SetUp(ins => { pulsatingLow.Stop(); pulsatingHigh.Start(token: this.controlToken); }) .RunAction(ins => { switch (random.Next(5)) { case 0: audioPlayer.PlayEffect("266 Monster Growl 7.wav", 1.0, 1.0); ins.WaitFor(S(2.0)); break; case 1: audioPlayer.PlayEffect("285 Monster Snarl 2.wav", 1.0, 1.0); ins.WaitFor(S(3.0)); break; case 2: audioPlayer.PlayEffect("286 Monster Snarl 3.wav", 1.0, 1.0); ins.WaitFor(S(2.5)); break; case 3: audioPlayer.PlayEffect("287 Monster Snarl 4.wav", 1.0, 1.0); ins.WaitFor(S(1.5)); break; default: ins.WaitFor(S(3.0)); break; } }) .TearDown(ins => { //TODO: Fade out pulsatingHigh.Stop(); pulsatingLow.Start(token: this.controlToken); }); PowerOff .RunAction(ins => { audioPlayer.PlayEffect("How you doing.wav", 0.15); ins.WaitFor(S(5)); }); }