示例#1
0
        /// <summary>
        /// Initializes a HD44780 compatible LCD with a parallel output port
        /// </summary>
        /// <param name="Data">Data port</param>
        /// <param name="ClockEnablePin">Clock enable pin</param>
        /// <param name="RegisterSelectPin">Register select pin</param>
        /// <param name="ReadWritePin">Read/write pin (optional; this driver is always in 'write' mode)</param>
        /// <param name="Columns">The amount of columns (default: 16)</param>
        /// <param name="Rows">The amount of rows (default: 2)</param>
        public Hd44780Lcd(IParallelOut Data, IGPOPort ClockEnablePin, IGPOPort RegisterSelectPin, IGPOPort ReadWritePin = null, int Columns = 16, int Rows = 2)
        {
            // Validates parameters
            if (Data.Size != 4)
            {
                throw new ArgumentOutOfRangeException("Can only use 4-bit data blocks right now");
            }

            // Copies all references locally
            this._Data   = Data;
            this._CePin  = ClockEnablePin;
            this._RsPin  = RegisterSelectPin;
            this._RwPin  = ReadWritePin;
            this.Rows    = Rows;
            this.Columns = Columns;

            // Since we are referring to a data block, we're not in pin mode
            this._PinMode = false;

            // Since we use virtual pins, disposal isn't required
            this._PinDisposalRequired = false;

            // Starts the LCD initialization
            this._Initialization();
        }
示例#2
0
        /// <summary>
        /// Initializes a HD44780 compatible LCD with a parallel output port
        /// </summary>
        /// <param name="Data">Data port</param>
        /// <param name="ClockEnablePin">Clock enable pin</param>
        /// <param name="RegisterSelectPin">Register select pin</param>
        /// <param name="ReadWritePin">Read/write pin (optional; this driver is always in 'write' mode)</param>
        /// <param name="Columns">The amount of columns (default: 16)</param>
        /// <param name="Rows">The amount of rows (default: 2)</param>
        public Hd44780Lcd(IParallelOut Data, Cpu.Pin ClockEnablePin, Cpu.Pin RegisterSelectPin, Cpu.Pin ReadWritePin = Cpu.Pin.GPIO_NONE, int Columns = 16, int Rows = 2)
        {
            // Validates parameters
            if (Data.Size != 4)
            {
                throw new ArgumentOutOfRangeException("Can only use 4-bit data blocks right now");
            }

            // Copies all references locally
            this._Data   = Data;
            this._CePin  = new IntegratedGPO(ClockEnablePin);
            this._RsPin  = new IntegratedGPO(RegisterSelectPin);
            this._RwPin  = ReadWritePin == Cpu.Pin.GPIO_NONE ? null : new IntegratedGPO(ReadWritePin);
            this.Rows    = Rows;
            this.Columns = Columns;

            // Since we are referring to a data block, we're not in pin mode
            this._PinMode = false;

            // Since we use real pins, disposal is required
            this._PinDisposalRequired = true;

            // Starts the LCD initialization
            this._Initialization();
        }
示例#3
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);
        }
示例#4
0
        /// <summary>
        /// Initialises a chain of one or multiple parallel to serial ICs over bitbanged SPI [WHEN POSSIBLE, USE MANAGED MODE!]
        /// </summary>
        /// <remarks>
        /// Use only when the managed SPI-pins can't be used. This method is way slower and locks the pins for any other purpose until disposed.
        /// </remarks>
        /// <param name="ClockPin">The clock pin connected to the IC(s)</param>
        /// <param name="DataPin">The data pin connected to the IC(s)</param>
        /// <param name="LatchPin">The slave select pin connected to the IC(s)</param>
        /// <param name="Bytes">The amount of 8-bit IC(s) connected</param>
        public Ic74hc165(Cpu.Pin ClockPin, Cpu.Pin DataPin, Cpu.Pin LatchPin, uint Bytes = 1)
        {
            // Enables bitbang mode and marks the pins as need-to-be-disposed
            this._BitBangMode         = true;
            this._PinDisposalRequired = true;
            // Makes references to the SPI pins
            this._BBM_CS   = new IntegratedGPO(LatchPin, false);
            this._BBM_MISO = new IntegratedGPI(DataPin);
            this._BBM_SPCK = new IntegratedGPO(ClockPin, true);

            // The amount of ICs
            this._Init(Bytes);
        }
示例#5
0
        /// <summary>
        /// Initialises a chain of one or multiple parallel to serial ICs over bitbanged SPI [WHEN POSSIBLE, USE MANAGED MODE!]
        /// </summary>
        /// <remarks>
        /// Use only when the managed SPI-pins can't be used. This method is way slower and locks the pins for any other purpose until disposed.
        /// </remarks>
        /// <param name="ClockPin">The clock pin connected to the IC(s)</param>
        /// <param name="DataPin">The data pin connected to the IC(s)</param>
        /// <param name="LatchPin">The slave select pin connected to the IC(s)</param>
        /// <param name="Bytes">The amount of 8-bit IC(s) connected</param>
        public Ic74hc165(Cpu.Pin ClockPin, Cpu.Pin DataPin, Cpu.Pin LatchPin, uint Bytes = 1)
        {
            // Enables bitbang mode and marks the pins as need-to-be-disposed
            this._BitBangMode = true;
            this._PinDisposalRequired = true;
            // Makes references to the SPI pins
            this._BBM_CS = new IntegratedGPO(LatchPin, false);
            this._BBM_MISO = new IntegratedGPI(DataPin);
            this._BBM_SPCK = new IntegratedGPO(ClockPin, true);

            // The amount of ICs
            this._Init(Bytes);
        }
示例#6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ClockPin">SPI Clock pin</param>
        /// <param name="EnablePin">SPI Enable pin</param>
        /// <param name="DataPin">SPI Data pin</param>
        /// <param name="LatchPin">SPI Latch pin</param>
        /// <param name="Motor1Pwm">Motor 1 PWM pin</param>
        /// <param name="Motor2Pwm">Motor 2 PWM pin</param>
        /// <param name="Motor3Pwm">Motor 3 PWM pin</param>
        /// <param name="Motor4Pwm">Motor 4 PWM pin</param>
        public AdafruitMotorshield(
            Cpu.Pin ClockPin, Cpu.Pin EnablePin, Cpu.Pin DataPin, Cpu.Pin LatchPin,
            IPWMPort Motor1Pwm, IPWMPort Motor2Pwm, IPWMPort Motor3Pwm, IPWMPort Motor4Pwm
            )
        {
            // This one should always be false
            this._EnablePin = new OutputPort(EnablePin, false);

            // Defines the 74HC595 chip by bitbanging
            this._IcOut = new Ic74hc595(ClockPin, DataPin, LatchPin);

            // Defines all 8 pins on the 74HC595
            this._Motor1aPin = this._IcOut.Pins[2]; // M1A
            this._Motor1bPin = this._IcOut.Pins[3]; // M1B
            this._Motor2aPin = this._IcOut.Pins[1]; // M2A
            this._Motor2bPin = this._IcOut.Pins[4]; // M3B
            this._Motor4aPin = this._IcOut.Pins[0]; // M4A
            this._Motor4bPin = this._IcOut.Pins[6]; // M4B
            this._Motor3aPin = this._IcOut.Pins[5]; // M3A
            this._Motor3bPin = this._IcOut.Pins[7]; // M3B

            // Motor PWM pins
            this._Motor1Pwm = Motor1Pwm;              // PWM2A
            this._Motor2Pwm = Motor2Pwm;              // PWM2B
            this._Motor3Pwm = Motor3Pwm;              // PWM0A
            this._Motor4Pwm = Motor4Pwm;              // PWM0B

            if (this._Motor1Pwm != null)
            {
                this._Motor1Pwm.SetDutyCycle(0); this._Motor1Pwm.StartPulse();
            }
            if (this._Motor2Pwm != null)
            {
                this._Motor2Pwm.SetDutyCycle(0); this._Motor2Pwm.StartPulse();
            }
            if (this._Motor3Pwm != null)
            {
                this._Motor3Pwm.SetDutyCycle(0); this._Motor3Pwm.StartPulse();
            }
            if (this._Motor4Pwm != null)
            {
                this._Motor4Pwm.SetDutyCycle(0); this._Motor4Pwm.StartPulse();
            }
        }
示例#7
0
        /// <summary>
        /// Initializes a HD44780 compatible LCD by bitbanging
        /// </summary>
        /// <param name="Data4">Data pin 4</param>
        /// <param name="Data5">Data pin 5</param>
        /// <param name="Data6">Data pin 6</param>
        /// <param name="Data7">Data pin 7</param>
        /// <param name="ClockEnablePin">Clock enable pin</param>
        /// <param name="RegisterSelectPin">Register select pin</param>
        /// <param name="ReadWritePin">Read/write pin (optional; this driver is always in 'write' mode)</param>
        /// <param name="Columns">The amount of columns (default: 16)</param>
        /// <param name="Rows">The amount of rows (default: 2)</param>
        public Hd44780Lcd(IGPOPort Data4, IGPOPort Data5, IGPOPort Data6, IGPOPort Data7, IGPOPort ClockEnablePin, IGPOPort RegisterSelectPin, IGPOPort ReadWritePin = null, int Columns = 16, int Rows = 2)
        {
            // Copies all references locally
            this._Db4Pin = Data4;
            this._Db5Pin = Data5;
            this._Db6Pin = Data6;
            this._Db7Pin = Data7;
            this._CePin  = ClockEnablePin;
            this._RsPin  = RegisterSelectPin;
            this._RwPin  = ReadWritePin;
            this.Rows    = Rows;
            this.Columns = Columns;

            // Since we are referring to data pins, we're in pin mode
            this._PinMode = true;

            // Since we use virtual pins, disposal isn't required
            this._PinDisposalRequired = false;

            // Starts the LCD initialization
            this._Initialization();
        }
示例#8
0
        /// <summary>
        /// Initializes a HD44780 compatible LCD by bitbanging
        /// </summary>
        /// <param name="Data4">Data pin 4</param>
        /// <param name="Data5">Data pin 5</param>
        /// <param name="Data6">Data pin 6</param>
        /// <param name="Data7">Data pin 7</param>
        /// <param name="ClockEnablePin">Clock enable pin</param>
        /// <param name="RegisterSelectPin">Register select pin</param>
        /// <param name="ReadWritePin">Read/write pin (optional; this driver is always in 'write' mode)</param>
        /// <param name="Columns">The amount of columns (default: 16)</param>
        /// <param name="Rows">The amount of rows (default: 2)</param>
        public Hd44780Lcd(Cpu.Pin Data4, Cpu.Pin Data5, Cpu.Pin Data6, Cpu.Pin Data7, Cpu.Pin ClockEnablePin, Cpu.Pin RegisterSelectPin, Cpu.Pin ReadWritePin = Cpu.Pin.GPIO_NONE, int Columns = 16, int Rows = 2)
        {
            // Copies all references locally
            this._Db4Pin = new IntegratedGPO(Data4);
            this._Db5Pin = new IntegratedGPO(Data5);
            this._Db6Pin = new IntegratedGPO(Data6);
            this._Db7Pin = new IntegratedGPO(Data7);
            this._CePin  = new IntegratedGPO(ClockEnablePin);
            this._RsPin  = new IntegratedGPO(RegisterSelectPin);
            this._RwPin  = ReadWritePin == Cpu.Pin.GPIO_NONE ? null : new IntegratedGPO(ReadWritePin);
            this.Rows    = Rows;
            this.Columns = Columns;

            // Since we are referring to data pins, we're in pin mode
            this._PinMode = true;

            // Since we use real pins, disposal is required
            this._PinDisposalRequired = true;

            // Starts the LCD initialization
            this._Initialization();
        }
示例#9
0
        /// <summary>
        /// Initializes a HD44780 compatible LCD with a parallel output port
        /// </summary>
        /// <param name="Data">Data port</param>
        /// <param name="ClockEnablePin">Clock enable pin</param>
        /// <param name="RegisterSelectPin">Register select pin</param>
        /// <param name="ReadWritePin">Read/write pin (optional; this driver is always in 'write' mode)</param>
        /// <param name="Columns">The amount of columns (default: 16)</param>
        /// <param name="Rows">The amount of rows (default: 2)</param>
        public Hd44780Lcd(IParallelOut Data, Cpu.Pin ClockEnablePin, Cpu.Pin RegisterSelectPin, Cpu.Pin ReadWritePin = Cpu.Pin.GPIO_NONE, int Columns = 16, int Rows = 2)
        {
            // Validates parameters
            if (Data.Size != 4) throw new ArgumentOutOfRangeException("Can only use 4-bit data blocks right now");

            // Copies all references locally
            this._Data = Data;
            this._CePin = new IntegratedGPO(ClockEnablePin);
            this._RsPin = new IntegratedGPO(RegisterSelectPin);
            this._RwPin = ReadWritePin == Cpu.Pin.GPIO_NONE ? null : new IntegratedGPO(ReadWritePin);
            this.Rows = Rows;
            this.Columns = Columns;

            // Since we are referring to a data block, we're not in pin mode
            this._PinMode = false;

            // Since we use real pins, disposal is required
            this._PinDisposalRequired = true;

            // Starts the LCD initialization
            this._Initialization();
        }
示例#10
0
        /// <summary>
        /// Initializes a HD44780 compatible LCD by bitbanging
        /// </summary>
        /// <param name="Data4">Data pin 4</param>
        /// <param name="Data5">Data pin 5</param>
        /// <param name="Data6">Data pin 6</param>
        /// <param name="Data7">Data pin 7</param>
        /// <param name="ClockEnablePin">Clock enable pin</param>
        /// <param name="RegisterSelectPin">Register select pin</param>
        /// <param name="ReadWritePin">Read/write pin (optional; this driver is always in 'write' mode)</param>
        /// <param name="Columns">The amount of columns (default: 16)</param>
        /// <param name="Rows">The amount of rows (default: 2)</param>
        public Hd44780Lcd(IGPOPort Data4, IGPOPort Data5, IGPOPort Data6, IGPOPort Data7, IGPOPort ClockEnablePin, IGPOPort RegisterSelectPin, IGPOPort ReadWritePin = null, int Columns = 16, int Rows = 2)
        {
            // Copies all references locally
            this._Db4Pin = Data4;
            this._Db5Pin = Data5;
            this._Db6Pin = Data6;
            this._Db7Pin = Data7;
            this._CePin = ClockEnablePin;
            this._RsPin = RegisterSelectPin;
            this._RwPin = ReadWritePin;
            this.Rows = Rows;
            this.Columns = Columns;

            // Since we are referring to data pins, we're in pin mode
            this._PinMode = true;

            // Since we use virtual pins, disposal isn't required
            this._PinDisposalRequired = false;

            // Starts the LCD initialization
            this._Initialization();
        }
示例#11
0
        /// <summary>
        /// Initializes a HD44780 compatible LCD by bitbanging
        /// </summary>
        /// <param name="Data4">Data pin 4</param>
        /// <param name="Data5">Data pin 5</param>
        /// <param name="Data6">Data pin 6</param>
        /// <param name="Data7">Data pin 7</param>
        /// <param name="ClockEnablePin">Clock enable pin</param>
        /// <param name="RegisterSelectPin">Register select pin</param>
        /// <param name="ReadWritePin">Read/write pin (optional; this driver is always in 'write' mode)</param>
        /// <param name="Columns">The amount of columns (default: 16)</param>
        /// <param name="Rows">The amount of rows (default: 2)</param>
        public Hd44780Lcd(Cpu.Pin Data4, Cpu.Pin Data5, Cpu.Pin Data6, Cpu.Pin Data7, Cpu.Pin ClockEnablePin, Cpu.Pin RegisterSelectPin, Cpu.Pin ReadWritePin = Cpu.Pin.GPIO_NONE, int Columns = 16, int Rows = 2)
        {
            // Copies all references locally
            this._Db4Pin = new IntegratedGPO(Data4);
            this._Db5Pin = new IntegratedGPO(Data5);
            this._Db6Pin = new IntegratedGPO(Data6);
            this._Db7Pin = new IntegratedGPO(Data7);
            this._CePin = new IntegratedGPO(ClockEnablePin);
            this._RsPin = new IntegratedGPO(RegisterSelectPin);
            this._RwPin = ReadWritePin == Cpu.Pin.GPIO_NONE ? null : new IntegratedGPO(ReadWritePin);
            this.Rows = Rows;
            this.Columns = Columns;

            // Since we are referring to data pins, we're in pin mode
            this._PinMode = true;

            // Since we use real pins, disposal is required
            this._PinDisposalRequired = true;

            // Starts the LCD initialization
            this._Initialization();
        }
示例#12
0
        /// <summary>
        /// Initializes a HD44780 compatible LCD with a parallel output port
        /// </summary>
        /// <param name="Data">Data port</param>
        /// <param name="ClockEnablePin">Clock enable pin</param>
        /// <param name="RegisterSelectPin">Register select pin</param>
        /// <param name="ReadWritePin">Read/write pin (optional; this driver is always in 'write' mode)</param>
        /// <param name="Columns">The amount of columns (default: 16)</param>
        /// <param name="Rows">The amount of rows (default: 2)</param>
        public Hd44780Lcd(IParallelOut Data, IGPOPort ClockEnablePin, IGPOPort RegisterSelectPin, IGPOPort ReadWritePin = null, int Columns = 16, int Rows = 2)
        {
            // Validates parameters
            if (Data.Size != 4) throw new ArgumentOutOfRangeException("Can only use 4-bit data blocks right now");

            // Copies all references locally
            this._Data = Data;
            this._CePin = ClockEnablePin;
            this._RsPin = RegisterSelectPin;
            this._RwPin = ReadWritePin;
            this.Rows = Rows;
            this.Columns = Columns;

            // Since we are referring to a data block, we're not in pin mode
            this._PinMode = false;

            // Since we use virtual pins, disposal isn't required
            this._PinDisposalRequired = false;

            // Starts the LCD initialization
            this._Initialization();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="ClockPin">SPI Clock pin</param>
        /// <param name="EnablePin">SPI Enable pin</param>
        /// <param name="DataPin">SPI Data pin</param>
        /// <param name="LatchPin">SPI Latch pin</param>
        /// <param name="Motor1Pwm">Motor 1 PWM pin</param>
        /// <param name="Motor2Pwm">Motor 2 PWM pin</param>
        /// <param name="Motor3Pwm">Motor 3 PWM pin</param>
        /// <param name="Motor4Pwm">Motor 4 PWM pin</param>
        public AdafruitMotorshield(
            Cpu.Pin ClockPin, Cpu.Pin EnablePin, Cpu.Pin DataPin, Cpu.Pin LatchPin,
            IPWMPort Motor1Pwm, IPWMPort Motor2Pwm, IPWMPort Motor3Pwm, IPWMPort Motor4Pwm
        )
        {
            // This one should always be false
            this._EnablePin = new OutputPort(EnablePin, false);

            // Defines the 74HC595 chip by bitbanging
            this._IcOut = new Ic74hc595(ClockPin, DataPin, LatchPin);

            // Defines all 8 pins on the 74HC595
            this._Motor1aPin = this._IcOut.Pins[2]; // M1A
            this._Motor1bPin = this._IcOut.Pins[3]; // M1B
            this._Motor2aPin = this._IcOut.Pins[1]; // M2A
            this._Motor2bPin = this._IcOut.Pins[4]; // M3B
            this._Motor4aPin = this._IcOut.Pins[0]; // M4A
            this._Motor4bPin = this._IcOut.Pins[6]; // M4B
            this._Motor3aPin = this._IcOut.Pins[5]; // M3A
            this._Motor3bPin = this._IcOut.Pins[7]; // M3B

            // Motor PWM pins
            this._Motor1Pwm = Motor1Pwm;              // PWM2A
            this._Motor2Pwm = Motor2Pwm;              // PWM2B
            this._Motor3Pwm = Motor3Pwm;              // PWM0A
            this._Motor4Pwm = Motor4Pwm;              // PWM0B

            if (this._Motor1Pwm != null) { this._Motor1Pwm.SetDutyCycle(0); this._Motor1Pwm.StartPulse(); }
            if (this._Motor2Pwm != null) { this._Motor2Pwm.SetDutyCycle(0); this._Motor2Pwm.StartPulse(); }
            if (this._Motor3Pwm != null) { this._Motor3Pwm.SetDutyCycle(0); this._Motor3Pwm.StartPulse(); }
            if (this._Motor4Pwm != null) { this._Motor4Pwm.SetDutyCycle(0); this._Motor4Pwm.StartPulse(); }
        }