Hi guys
Heres my code for the display but it doesnt seem to be working correctly.
1. it doesnt write "Line 2" and it doesnt write it to the center of the display
2. the button events are slow and im not sure if this is the correct way to do this button logic, I mean is this an optimized way?
3. when I press a button, the text that im writing must stay displayed and not revert back to the original text, it basically needs to stay in that method, but it defaults back.
Heres the code, clearly its not correct but I cant seem to debug this and find the problem. Iv tried so many times and so many different approaches..
using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;
using MicroLiquidCrystal;
namespace DisplayExample
{
public class Program
{
public static void Main()
{
//Keypad connected to Analog pin 0
AnalogInput keys = new AnalogInput(AnalogChannels.ANALOG_PIN_A0, 3.3, 0.0, -1);
//backlight connected to D10
// create the transfer provider
// Initialize the library with the numbers of the interface pins
//PWM backlight = new PWM(Pins.GPIO_PIN_D10);
var lcdProvider = new GpioLcdTransferProvider(Pins.GPIO_PIN_D8, Pins.GPIO_PIN_D9,
Pins.GPIO_PIN_D4, Pins.GPIO_PIN_D5, Pins.GPIO_PIN_D6, Pins.GPIO_PIN_D7);
// create the LCD interface
var lcd = new Lcd(lcdProvider);
// set up the number of columns and rows:
lcd.Begin(16, 2);
lcd.Write("Line 1");
lcd.SetCursorPosition(8, 1);
lcd.Write("Line 2");
while (true)
{
var lcd_key = keys.Read() * 100;
if (lcd_key.ToString("F0") == "155")
{
lcd.Clear();
lcd.Write("Down Button");
//it must stay in the below mode until another button is pressed.
DoOperation1();
}
else if (lcd_key.ToString("F0") == "68")
{
lcd.Clear();
lcd.Write("Up Button");
//it must stay in the below mode until another button is pressed.
DoOperation2();
}
else if (lcd_key.ToString("F0") == "0")
{
lcd.Clear();
lcd.Write("Right Button");
}
else if (lcd_key.ToString("F0") == "238")
{
lcd.Clear();
lcd.Write("Left Button");
}
else
{
lcd.Clear();
lcd.Write("Line 1");
lcd.SetCursorPosition(8, 1);
lcd.Write("Line 2");
}
Thread.Sleep(1000);
}
public static void DoOperation1()
{
//when the down button is pressed, it must remain in this mode until another button
// is pressed and it must go into that method and stay there
}
public static void DoOperation2()
{
//when the up button is pressed, it must remain in this mode until another button
// is pressed and it must go into that method and stay there
}
}
}
}
Thanks guys.