public RGBLCDShield(MCP23017 mcp23017, byte cols = 16, byte rows = 2, byte dotsize = 0)
        {
            this.mcp23017        = mcp23017;
            this.displayFunction = 0x0;

            // initialize the MCP23017 for this board
            mcp23017.PinMode(8, MCP23017.Direction.Output);
            mcp23017.PinMode(6, MCP23017.Direction.Output);
            mcp23017.PinMode(7, MCP23017.Direction.Output);

            //SetBacklight(BacklightColor.White);

            mcp23017.PinMode(rsPin, MCP23017.Direction.Output);
            mcp23017.PinMode(rwPin, MCP23017.Direction.Output);
            mcp23017.PinMode(enablePin, MCP23017.Direction.Output);

            for (int i = 0; i < dataPins.Length; i++)
            {
                mcp23017.PinMode(dataPins[i], MCP23017.Direction.Output);
            }

            for (int i = 0; i < buttonPins.Length; i++)
            {
                mcp23017.PinMode(buttonPins[i], MCP23017.Direction.Input);
                mcp23017.PullUp(buttonPins[i], 0x01);
            }

            Thread.Sleep(50);
            mcp23017.DigitalWrite(rsPin, 0x00);
            mcp23017.DigitalWrite(enablePin, 0x00);
            mcp23017.DigitalWrite(rwPin, 0x00);

            // put the LCD screen into 4 bit mode
            Write4Bits(0x03);
            Thread.Sleep(5);

            Write4Bits(0x03);
            Thread.Sleep(1);

            Write4Bits(0x03);
            Write4Bits(0x02);

            this.displayFunction = DisplayFunction.LCD_2LINE | DisplayFunction.LCD_4BITMODE | DisplayFunction.LCD_5x8DOTS;
            command((byte)((byte)Commands.LCD_FUNCTIONSET | (byte)this.displayFunction));

            this.displayControl = DisplayControl.LCD_DISPLAYON | DisplayControl.LCD_CURSOROFF | DisplayControl.LCD_BLINKOFF;
            Display();

            Clear();

            this.displayMode = DisplayMode.LCD_ENTRYLEFT | DisplayMode.LCD_ENTRYSHIFTDECREMENT;
            command((byte)((byte)Commands.LCD_ENTRYMODESET | (byte)this.displayMode));
        }
        public RGBLCDShield(MCP23017 mcp23017, byte cols = 16, byte rows = 2, byte dotsize = 0)
        {
            this.mcp23017 = mcp23017;
            this.displayFunction = 0x0;

            // initialize the MCP23017 for this board
            mcp23017.PinMode(8, MCP23017.Direction.Output);
            mcp23017.PinMode(6, MCP23017.Direction.Output);
            mcp23017.PinMode(7, MCP23017.Direction.Output);

            //SetBacklight(BacklightColor.White);

            mcp23017.PinMode(rsPin, MCP23017.Direction.Output);
            mcp23017.PinMode(rwPin, MCP23017.Direction.Output);
            mcp23017.PinMode(enablePin, MCP23017.Direction.Output);

            for (int i = 0; i < dataPins.Length; i++) mcp23017.PinMode(dataPins[i], MCP23017.Direction.Output);

            for (int i = 0; i < buttonPins.Length; i++)
            {
                mcp23017.PinMode(buttonPins[i], MCP23017.Direction.Input);
                mcp23017.PullUp(buttonPins[i], 0x01);
            }

            Thread.Sleep(50);
            mcp23017.DigitalWrite(rsPin, 0x00);
            mcp23017.DigitalWrite(enablePin, 0x00);
            mcp23017.DigitalWrite(rwPin, 0x00);

            // put the LCD screen into 4 bit mode
            Write4Bits(0x03);
            Thread.Sleep(5);

            Write4Bits(0x03);
            Thread.Sleep(1);

            Write4Bits(0x03);
            Write4Bits(0x02);

            this.displayFunction = DisplayFunction.LCD_2LINE | DisplayFunction.LCD_4BITMODE | DisplayFunction.LCD_5x8DOTS;
            command((byte)((byte)Commands.LCD_FUNCTIONSET | (byte)this.displayFunction));

            this.displayControl = DisplayControl.LCD_DISPLAYON | DisplayControl.LCD_CURSOROFF | DisplayControl.LCD_BLINKOFF;
            Display();

            Clear();

            this.displayMode = DisplayMode.LCD_ENTRYLEFT | DisplayMode.LCD_ENTRYSHIFTDECREMENT;
            command((byte)((byte)Commands.LCD_ENTRYMODESET | (byte)this.displayMode));
        }
예제 #3
0
 public Menu(MCP23017 mcp23017)
 {
     lcdBoard = new RGBLCDShield(mcp23017);
 }
예제 #4
0
        public static void Main()
        {
            // the MCP is what allows us to talk with the RGB LCD panel
            mcp23017 = new MCP23017();

            // and this is a class to help us chat with the LCD panel
            lcdBoard = new RGBLCDShield(mcp23017);

            // we'll follow the Adafruit example code
            lcdBoard.Write("Hello, world!");
            lcdBoard.SetBacklight(BacklightColor.White);

            // get the time so that we can track # of seconds since power up
            DateTime time = DateTime.Now;

            Button currentButtons = 0;

            while (true)
            {
                lcdBoard.SetPosition(1, 0);

                // calculate the number of seconds since power on
                var seconds = (DateTime.Now - time).Ticks / TimeSpan.TicksPerSecond;
                lcdBoard.Write(seconds.ToString());

                Button buttons = lcdBoard.ReadButtons();

                // only update the screen if a new button is pressed
                if (buttons != currentButtons && buttons != 0)
                {
                    lcdBoard.Clear();
                    lcdBoard.SetPosition(0, 0);

                    if ((buttons & Button.Up) != 0)
                    {
                        lcdBoard.Write("UP ");
                        if (buttons == Button.Up) lcdBoard.SetBacklight(BacklightColor.Red);
                    }
                    if ((buttons & Button.Down) != 0)
                    {
                        lcdBoard.Write("DOWN ");
                        if (buttons == Button.Down) lcdBoard.SetBacklight(BacklightColor.Yellow);
                    }
                    if ((buttons & Button.Right) != 0)
                    {
                        lcdBoard.Write("RIGHT ");
                        if (buttons == Button.Right) lcdBoard.SetBacklight(BacklightColor.Green);
                    }
                    if ((buttons & Button.Left) != 0)
                    {
                        lcdBoard.Write("LEFT ");
                        if (buttons == Button.Left) lcdBoard.SetBacklight(BacklightColor.Teal);
                    }
                    if ((buttons & Button.Select) != 0)
                    {
                        lcdBoard.Write("SELECT ");
                        if (buttons == Button.Select) lcdBoard.SetBacklight(BacklightColor.Violet);
                    }

                    currentButtons = buttons;
                }
            }
        }
        public static void Main()
        {
            try
            {
                mcp23017 = new MCP23017();//the MCP is what allows us to talk with the RGB LCD panel. I need it in this class so I can read the button presses from the User...
                mMenu = new Menu(mcp23017);//Configure this one first so that errors can be written to the LCD Shield
                mMenu.MenuSelection = MenuSelection.PrintLabel;

                //Setup the interrupt port for button presses from the LCD Shield.
                //Here I have the Interrupt pin from the LCD Shield (configured in the MCP23017 class) going to the Netduino Digital Pin 5
                btnShield = new InterruptPort(Pins.GPIO_PIN_D5, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeLow);
                // Bind the interrupt handler to the pin's interrupt event.
                btnShield.OnInterrupt += new NativeEventHandler(btnShield_OnInterrupt);

                //Configure the MUX which allows me to expand my serial ports. Here I am using digital pins 9 thru 10 to send the necessary signals to switch my MUX channels
                OutputPort DigitalPin9 = new OutputPort(Pins.GPIO_PIN_D9, false); //Goes to S0
                OutputPort DigitalPin10 = new OutputPort(Pins.GPIO_PIN_D10, false);//Goes to S1
                OutputPort DigitalPin11 = new OutputPort(Pins.GPIO_PIN_D11, false);//Goes to S2
                OutputPort DigitalPin12 = new OutputPort(Pins.GPIO_PIN_D12, false);//Goes to S3
                Mux = new CD74HC4067(DigitalPin9, DigitalPin10, DigitalPin11, DigitalPin12);
                Mux.SetPort(MuxChannel.C0); //default it to C0 which is data coming in from the Indicators Serial Port

                Settings = new Settings();
                Settings.Increments = new double[] { .001, .01, .1, 1, 10, 100 };
                Settings.IncrementSelection = 3;
                Settings.RetrieveSettingsFromSDCard(WORKINGDIRECTORY, "LabelFormat.txt", "Job.txt", "Operation.txt", "ShopTrakTransactionsURL.txt",
                    "PieceWeight.txt", "NetWeightAdjustment.txt", "BackgroundColor.txt");

                mMenu.SetBackLightColor(Settings.BacklightColor);

                // initialize the serial port for data being input via COM1
                mIndicatorScannerSerialPort = new MySerialPort(SerialPorts.COM1, BaudRate.Baudrate9600, Parity.None, DataBits.Eight, StopBits.One);
                // initialize the serial port for data being output via COM3
                mPrinterSerialPort = new MySerialPort(SerialPorts.COM3, BaudRate.Baudrate9600, Parity.None, DataBits.Eight, StopBits.One);
                // open the serial-ports, so we can send & receive data
                mIndicatorScannerSerialPort.Open();
                mPrinterSerialPort.Open();
                // add an event-handler for handling incoming data
                mIndicatorScannerSerialPort.DataReceived += new SerialDataReceivedEventHandler(IndicatorScannerSerialPort_DataReceived);

                //Setup the Onboard button; InterruptEdgeLevelLow only fires the event the first time that the button descends
                btnBoard = new InterruptPort(Pins.ONBOARD_SW1, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeHigh);
                // Create an event handler for the button
                btnBoard.OnInterrupt += new NativeEventHandler(btnBoard_OnInterrupt);

                // write your code here
                var webServer = new WebServer();
                webServer.AddRequestFilter(new RequestFilter());
                var fileAndDirectoryService = new FileAndDirectoryService();
                fileAndDirectoryService.SetSDCardManager(new SDCardManager(WORKINGDIRECTORY));
                webServer.SetFileAndDirectoryService(fileAndDirectoryService);
                /*Setting a default controller removes the ability to browse the files and folder of the root web directory*/
                //webServer.RouteTable.DefaultControllerName = "Scale";
                webServer.StartServer(80);//If port is not specified, then default is port 8500
                webServer.SetHostName("Cart Scale");

                //Display appropriate information to the user...
                mMenu.DisplayInformation(Settings);
            }
            catch (Exception objEx)
            {
                Debug.Print("Exception caught in Main()\r\n");
                Debug.Print(objEx.Message);
                mMenu.DisplayError(objEx);
            }

            //We are done. The thread must sleep or else the netduino turns off...
            Thread.Sleep(Timeout.Infinite);
        }