示例#1
0
        static void bc_ButtonEvent(object sender, PiAndBash.ButtonCatcher.ButtonArgs e)
        {
            if (e.ButtonEvent == PiAndBash.ButtonCatcher.ButtonEventType.Up)
            {
                Console.WriteLine(e.Button.ToString() + " pressed and released");

                if (e.Button == PiAndBash.ButtonCatcher.ButtonType.Down)
                {
                    notePlayer.PlayNote(440, 1);
                }
                if (e.Button == PiAndBash.ButtonCatcher.ButtonType.Enter)
                {
                    notePlayer.PlayNote(523, 1);
                }
                if (e.Button == PiAndBash.ButtonCatcher.ButtonType.BotSel)
                {
                    Console.WriteLine("Exiting");
                    (sender as PiAndBash.ButtonCatcher).Stop();
                }
            }
        }
示例#2
0
        internal static void WindowsInterruptTest()
        {
            Console.WriteLine("press any key to play sound");
            bool isPlaying = false;
            var  ad        = Mono.Audio.AudioDevice.CreateDevice("sss");

            var np = new NotePlayer();



            short[] buffer = new short[480];
            while (true)
            {
                if (!isPlaying)
                {
                    Console.ReadKey(false);
                    isPlaying = true;
                }

                if (isPlaying && !Console.KeyAvailable)
                {
                    // ad.PlaySample(buffer, 480);
                    //Thread.Sleep(100);
                    //Task.Factory.StartNew(() => np.PlayNote(440, 1));
                    //Thread t = new Thread(() => np.PlayNote(440,1));
                    //t.Start();
                    //while (!t.IsAlive) ;
                    np.PlayNote(440, 1);
                    Console.Write(".");
                }
                else
                {
                    Console.Write("£");
                    np.Silence();
                    isPlaying = false;
                    Console.ReadKey(true);
                }
            }
        }
示例#3
0
        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");
                    }
                }
            }
        }