Exemple #1
0
 /// <summary>Initialises a new parallel output port</summary>
 /// <param name="Module">The object of the main chain</param>
 /// <param name="StartBit">The first bit to write</param>
 /// <param name="BitCount">The amount of bits to write</param>
 /// <param name="Inverted">When true, bits will be inverted</param>
 public Mcp23017ParallelOut(Mcp23017 Module, uint StartBit, uint BitCount, bool Inverted)
 {
     this._Module   = Module;
     this._StartBit = StartBit;
     this._BitCount = BitCount;
     this._Inverted = Inverted;
 }
        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);
        }
 /// <summary>Initialises a new parallel output port</summary>
 /// <param name="Module">The object of the main chain</param>
 /// <param name="StartBit">The first bit to write</param>
 /// <param name="BitCount">The amount of bits to write</param>
 /// <param name="Inverted">When true, bits will be inverted</param>
 public Mcp23017ParallelOut(Mcp23017 Module, uint StartBit, uint BitCount, bool Inverted)
 {
     this._Module = Module;
     this._StartBit = StartBit;
     this._BitCount = BitCount;
     this._Inverted = Inverted;
 }
 /// <summary>
 /// Defines a Tristate Port
 /// </summary>
 /// <param name="Module">The object of the main chip</param>
 /// <param name="PinNo">The number of the pin</param>
 public Mcp23017Port(Mcp23017 Module, int PinNo)
 {
     this._Module = Module;
     this._PinNo = PinNo;
 }
        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;
            }
        }
Exemple #6
0
 /// <summary>
 /// Defines a Tristate Port
 /// </summary>
 /// <param name="Module">The object of the main chip</param>
 /// <param name="PinNo">The number of the pin</param>
 public Mcp23017Port(Mcp23017 Module, int PinNo)
 {
     this._Module = Module;
     this._PinNo  = PinNo;
 }