internal static void LatencyTest() { var ac = Mono.Audio.AudioDevice.CreateDevice("default"); ac.SetFormat(Mono.Audio.AudioFormat.S16_LE, 1, 48000); short[] sample = new short[48000]; for (int n = 0; n < sample.Length; n++) { sample[n] = (short)(0.5 * short.MaxValue * Math.Sin((2 * Math.PI * n * 440) / 48000)); } Console.WriteLine("Ready. Press key to play note"); Console.ReadKey(); // ac.PlaySample(sample, 48000); Console.WriteLine("done"); _dev = ac; _sample = sample; Console.WriteLine("now try a pi button"); var bc = new PiAndBash.ButtonCatcher(); bc.ButtonEvent += bc_ButtonEvent3; bc.Start(); }
public static void WaitForAllButtonsAsync() { // http://stackoverflow.com/questions/3390286/making-a-console-application-like-a-windows-application PiAndBash.Display disp = new PiAndBash.Display(); disp.TopLine = "Simon"; disp.BottomLine = "< EXIT"; notePlayer = new NotePlayer(); notePlayer.CreateSamples(new double[] { 440, 523 }); PiAndBash.ButtonCatcher bc = new PiAndBash.ButtonCatcher(); bc.ButtonEvent += bc_ButtonEvent2; bc.Start(); }
void buttonCatcher_ButtonEvent(object sender, PiAndBash.ButtonCatcher.ButtonArgs e) { if (isPlaying && e.ButtonEvent == PiAndBash.ButtonCatcher.ButtonEventType.Down) { if (e.Button == beeps[currentPress].Button) // correct button { leds.SetLight(beeps[currentPress].Color, true); notePlayer.PlayNote(beeps[currentPress].Frequency, 300); leds.SetLight(beeps[currentPress].Color, false); currentPress++; if (currentPress == beeps.Count) // all notes pressed { pnbDisplay.BottomLine = "Score = " + beeps.Count.ToString(); Sleep(250); nextRound(); } } else { isPlaying = false; pnbDisplay.TopLine = "YOU LOSE!"; notePlayer.Volume = 100; for (int i = 0; i < 5; i++) { foreach (var n in notes.OrderByDescending(n => n.Key)) { leds.SetLight(n.Value.Color, true); notePlayer.PlayNote(n.Value.Frequency * 0.7, 70); leds.SetLight(n.Value.Color, false); } } notePlayer.Volume = 50; // wait for one second then reset Sleep(1000); pnbDisplay.TopLine = "< Press to exit"; pnbDisplay.BottomLine = "< Press to start"; buttonCatcher.Start(); } } else { if (e.ButtonEvent == PiAndBash.ButtonCatcher.ButtonEventType.Up) { if (e.Button == PiAndBash.ButtonCatcher.ButtonType.BotSel) { buttonCatcher.Stop(); isPlaying = true; newGame(); } if (e.Button == PiAndBash.ButtonCatcher.ButtonType.TopSel) { pnbDisplay.SetBacklight(false); pnbDisplay.TopLine = ""; pnbDisplay.BottomLine = ""; buttonCatcher.Stop(); Console.WriteLine("Exiting"); } } } }