Ejemplo n.º 1
0
        public static void Main()
        {
            // The Adafruit LCD Shield uses a MCP23017 IC as multiplex chip
            Mcp23017 Mux = new Mcp23017();

            // Pins 0 to 4 on the Mux-chip are connected to the buttons
            IGPIPort ButtonSelect = Mux.Pins[0];
            IGPIPort ButtonRight  = Mux.Pins[1];
            IGPIPort ButtonDown   = Mux.Pins[2];
            IGPIPort ButtonUp     = Mux.Pins[3];
            IGPIPort ButtonLeft   = Mux.Pins[4];

            // Enables pull-ups for all the buttons
            for (int i = 0; i < 5; ++i)
            {
                Mux.EnablePullup(i, true);
                Mux.Pins[i].InvertReadings = true;
            }

            // Pins 6 to 8 on the Mux-chip are for the backlight
            IGPOPort Red   = Mux.Pins[6];  // Red backlight
            IGPOPort Green = Mux.Pins[7];  // Green backlight
            IGPOPort Blue  = Mux.Pins[8];  // Blue backlight

            // Pins 9 to 15 are connected to the HD44780 LCD
            Hd44780Lcd Display = new Hd44780Lcd(
                Data: Mux.CreateParallelOut(9, 4),
                ClockEnablePin: Mux.Pins[13],
                ReadWritePin: Mux.Pins[14],
                RegisterSelectPin: Mux.Pins[15]
                );

            // Initializes the game
            Games.HD44780_Snake.Init(Display, ButtonSelect, ButtonLeft, ButtonRight, ButtonUp, ButtonDown);

            // Turn on blue backlight
            Blue.Write(false); Red.Write(true); Green.Write(true);

            // Display splash
            Games.HD44780_Snake.Splash();

            // Wait 5 sec.
            Thread.Sleep(5000);

            // Turn on green backlight
            Blue.Write(true); Red.Write(true); Green.Write(false);

            // Starts the game
            try
            {
                Games.HD44780_Snake.Start();
            } catch (Exception e) {
                Display.ClearDisplay();
                Display.Write(e.Message);
            }

            // Turn on red backlight
            Blue.Write(true); Red.Write(false); Green.Write(true);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes the hardware
 /// </summary>
 /// <param name="Display">Reference to the LCD</param>
 /// <param name="ButtonStart">Start button</param>
 /// <param name="ButtonLeft">Left button</param>
 /// <param name="ButtonRight">Right button</param>
 /// <param name="ButtonUp">Up button</param>
 /// <param name="ButtonDown">Down button</param>
 public static void Init(Hd44780Lcd Display, IGPIPort ButtonStart, IGPIPort ButtonLeft, IGPIPort ButtonRight, IGPIPort ButtonUp, IGPIPort ButtonDown)
 {
     // Copies the parameters to local values
     _disp     = Display;
     _btnStart = ButtonStart;
     _btnLeft  = ButtonLeft;
     _btnRight = ButtonRight;
     _btnUp    = ButtonUp;
     _btnDown  = ButtonDown;
     _rand     = new Random();
 }
Ejemplo n.º 3
0
        public static void Main()
        {
            Hd44780Lcd Display = new Hd44780Lcd(
                Data4: Pins.GPIO_PIN_D4,
                Data5: Pins.GPIO_PIN_D5,
                Data6: Pins.GPIO_PIN_D6,
                Data7: Pins.GPIO_PIN_D7,
                ClockEnablePin: Pins.GPIO_PIN_D8,
                RegisterSelectPin: Pins.GPIO_PIN_D9
                );

            Display.ClearDisplay();
            Display.Write("Hello World!");
        }
Ejemplo n.º 4
0
        public static void Main()
        {
            // The Adafruit LCD Shield uses a MCP23017 IC as multiplex chip
            Mcp23017 Mux = new Mcp23017();

            // Pins 0 to 4 on the Mux-chip are connected to the buttons
            IGPIPort ButtonSelect = Mux.Pins[0];
            IGPIPort ButtonRight  = Mux.Pins[1];
            IGPIPort ButtonDown   = Mux.Pins[2];
            IGPIPort ButtonUp     = Mux.Pins[3];
            IGPIPort ButtonLeft   = Mux.Pins[4];

            // Enables pull-ups for all the buttons
            for (int i = 0; i < 5; ++i)
            {
                Mux.EnablePullup(i, true);
                Mux.Pins[i].InvertReadings = true;
            }

            // Pins 6 to 8 on the Mux-chip are for the backlight
            Mux.Pins[6].Write(false); // Red backlight
            Mux.Pins[7].Write(true);  // Green backlight
            Mux.Pins[8].Write(true);  // Blue backlight

            // Pins 9 to 15 are connected to the HD44780 LCD
            Hd44780Lcd Display = new Hd44780Lcd(
                Data: Mux.CreateParallelOut(9, 4),
                ClockEnablePin: Mux.Pins[13],
                ReadWritePin: Mux.Pins[14],
                RegisterSelectPin: Mux.Pins[15]
                );

            // Pressing the Select-button will shift through these colors
            bool[][] Colors = new bool[][] {
                new bool[3] {
                    false, true, true
                },
                new bool[3] {
                    true, false, true
                },
                new bool[3] {
                    true, true, false
                },
                new bool[3] {
                    false, false, true
                },
                new bool[3] {
                    false, true, false
                },
                new bool[3] {
                    true, false, false
                },
            };
            int ColorIndex = 0;

            // Fills up the display
            Display.ClearDisplay();
            Display.Write("Left:  ? Down: ?");
            Display.ChangePosition(1, 0);
            Display.Write("Right: ? Up:   ?");

            // Loops infinitely
            bool SelectPressed = false;

            while (true)
            {
                Display.ChangePosition(0, 7); Display.Write(ButtonLeft.Read() ? "1" : "0");
                Display.ChangePosition(1, 7); Display.Write(ButtonRight.Read() ? "1" : "0");
                Display.ChangePosition(0, 15); Display.Write(ButtonDown.Read() ? "1" : "0");
                Display.ChangePosition(1, 15); Display.Write(ButtonUp.Read() ? "1" : "0");

                // Handles the Select button
                if (ButtonSelect.Read())
                {
                    if (!SelectPressed)
                    {
                        SelectPressed = true;
                        ++ColorIndex;
                        if (ColorIndex == Colors.Length)
                        {
                            ColorIndex = 0;
                        }
                        Mux.Pins[6].Write(Colors[ColorIndex][0]);
                        Mux.Pins[7].Write(Colors[ColorIndex][1]);
                        Mux.Pins[8].Write(Colors[ColorIndex][2]);
                    }
                }
                else
                {
                    SelectPressed = false;
                }
            }
        }