private void FlashButtons(byte port)
 {
     i2cButtonPanel.Write(new byte[] { Mcp23017.GPIOB, 0x00 });
     for (int i = 0; i < 3; i++)
     {
         i2cButtonPanel.Write(new byte[] { Mcp23017.GPIOB, port });
         LcdScreen.Delay(400);
         i2cButtonPanel.Write(new byte[] { Mcp23017.GPIOB, 0x00 });
         LcdScreen.Delay(400);
     }
 }
예제 #2
0
        private async void InitializeSystem()
        {
            // initialize I2C communications
            try
            {
                string deviceSelector = I2cDevice.GetDeviceSelector(I2C_CONTROLLER_NAME);
                var i2cDeviceControllers = await DeviceInformation.FindAllAsync(deviceSelector);

                //Port expander controlling the Button Panel
                var buttonPanelSettings = new I2cConnectionSettings(BUTTON_PANEL_I2C_ADDRESS);
                buttonPanelSettings.BusSpeed = I2cBusSpeed.FastMode;
                i2cButtonPanel = await I2cDevice.FromIdAsync(i2cDeviceControllers[0].Id, buttonPanelSettings);

                //Port expander controlling the LCD Screen
                var lcdSettings = new I2cConnectionSettings(LCD_SCREEN_I2C_ADDRESS);
                lcdSettings.BusSpeed = I2cBusSpeed.FastMode;
                i2cLcdScreen = await I2cDevice.FromIdAsync(i2cDeviceControllers[0].Id, lcdSettings);

                Screen = new LcdScreen(i2cLcdScreen);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Exception: {0}", e.Message);
                return;
            }

            // initialize I2C Port Expander registers
            try
            {
                InitializeButtonPanel();
                InitializeLcd();

            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Exception: {0}", e.Message);
                return;
            }

            try
            {
                buttonStatusCheckTimer = new DispatcherTimer();
                buttonStatusCheckTimer.Interval = TimeSpan.FromMilliseconds(BUTTON_STATUS_CHECK_TIMER_INTERVAL);
                buttonStatusCheckTimer.Tick += ButtonStatusCheckTimer_Tick;
                buttonStatusCheckTimer.Start();
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Exception: {0}", e.Message);
                return;
            }
        }
        private async void InitializeSystem()
        {
            // initialize I2C communications
            try
            {
                string deviceSelector       = I2cDevice.GetDeviceSelector(I2C_CONTROLLER_NAME);
                var    i2cDeviceControllers = await DeviceInformation.FindAllAsync(deviceSelector);

                //Port expander controlling the Button Panel
                var buttonPanelSettings = new I2cConnectionSettings(BUTTON_PANEL_I2C_ADDRESS);
                buttonPanelSettings.BusSpeed = I2cBusSpeed.FastMode;
                i2cButtonPanel = await I2cDevice.FromIdAsync(i2cDeviceControllers[0].Id, buttonPanelSettings);

                //Port expander controlling the LCD Screen
                var lcdSettings = new I2cConnectionSettings(LCD_SCREEN_I2C_ADDRESS);
                lcdSettings.BusSpeed = I2cBusSpeed.FastMode;
                i2cLcdScreen         = await I2cDevice.FromIdAsync(i2cDeviceControllers[0].Id, lcdSettings);

                Screen = new LcdScreen(i2cLcdScreen);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Exception: {0}", e.Message);
                return;
            }

            // initialize I2C Port Expander registers
            try
            {
                InitializeButtonPanel();
                InitializeLcd();
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Exception: {0}", e.Message);
                return;
            }

            try
            {
                buttonStatusCheckTimer          = new DispatcherTimer();
                buttonStatusCheckTimer.Interval = TimeSpan.FromMilliseconds(BUTTON_STATUS_CHECK_TIMER_INTERVAL);
                buttonStatusCheckTimer.Tick    += ButtonStatusCheckTimer_Tick;
                buttonStatusCheckTimer.Start();
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Exception: {0}", e.Message);
                return;
            }
        }
 public void PrintGameOver()
 {
     Screen.LcdReset();
     Screen.MoveToLine(0x00);
     Screen.PrintLine("     GAME OVER!     ");
     if (p1Count == 0 || p2Count == 0)
     {
         Screen.MoveToLine(0x01);
         Screen.PrintLine("--------------------");
         Screen.MoveToLine(0x02);
         string temp = "Points = " + Convert.ToString(p1Count + p2Count);
         Screen.PrintLine(temp);
         Screen.MoveToLine(0x03);
         Screen.PrintLine("  Congratulations!  ");
     }
     else
     {
         Screen.MoveToLine(0x01);
         if (p1Count > p2Count)
         {
             Screen.PrintLine("   Player 1 wins!   ");
         }
         else if (p2Count > p1Count)
         {
             Screen.PrintLine("   Player 2 wins!   ");
         }
         else
         {
             Screen.PrintLine("    It is a tie!    ");
         }
         Screen.MoveToLine(0x02);
         string temp = "Player 1 = " + Convert.ToString(p1Count);
         Screen.PrintLine(temp);
         Screen.MoveToLine(0x03);
         temp = "Player 2 = " + Convert.ToString(p2Count);
         Screen.PrintLine(temp);
     }
     LcdScreen.Delay(3000);
 }