Snippet - HD4478 Module controled by Joystick

HD4478 Module controled by Joystick

using Gadgeteer.Modules.GHIElectronics;
using Microsoft.SPOT;
using GT = Gadgeteer;
 
namespace LCD
{
 
    public partial class Program
    {
        const byte Ball = 0x6F;
        const uint DispRows = 4;
        const uint DispColoumns = 20;
        const int Speed = 250; //breaks in ms
 
        private int CursorPosX = 0;
        private int CursorPosY = 0;
 
        static Joystick.Position JoyPosition;
 
        void ProgramStarted()
        {
            Debug.Print("Program Started");
            Lcd.Clear();
            Lcd.SetCursor((byte) CursorPosY, (byte) CursorPosX);
            Lcd.Putc(Ball);
 
            GT.Timer timer = new GT.Timer(Speed);
            timer.Tick += new GT.Timer.TickEventHandler(timer_Tick);
            timer.Start();
 
        }
 
        void timer_Tick(GT.Timer timer)
        {
            // Change direction @ <0.1 | >0.8
            JoyPosition = joystick.GetJoystickPosition();
 
            Debug.Print("JoyPositionX: " + JoyPosition.X.ToString());
            Debug.Print("JoyPositionY: " + JoyPosition.Y.ToString());
            Debug.Print("CursorPos: " + CursorPosX + " / " + CursorPosY);
            Debug.Print("--------");
 
            // X-Left
            if (JoyPosition.X < 0.1 && CursorPosX > 0)
            {
                CursorPosX -= 1;
                LcdRedraw();
            }
            // X-Right
            if (JoyPosition.X > 0.8 && CursorPosX < DispColoumns-1)
            {
                CursorPosX += 1;
                LcdRedraw();
            }
 
            // Y-Up
            if (JoyPosition.Y > 0.8 && CursorPosY > 0)
            {
                CursorPosY -= 1;
                LcdRedraw();
            }
 
            // Y-Down
            if (JoyPosition.Y < 0.1 && CursorPosY < DispRows - 1)
            {
                CursorPosY += 1;
                LcdRedraw();
            }
 
        }
 
        private void LcdRedraw()
        {
            Lcd.Clear();
            Lcd.SetCursor((byte) CursorPosY, (byte) CursorPosX);
            Lcd.Putc(Ball);
        }
 
    }
}

Using code tags will make your post more readable. This can be done in two ways:[ol]
Click the “101010” icon and paste your code between the

 tags or...
Select the code within your post and click the "101010" icon.[/ol]
(Generated by QuickReply)