Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using Microsoft.SPOT;
- using Microsoft.SPOT.Hardware;
- using Microsoft.SPOT.Presentation;
- using Microsoft.SPOT.Presentation.Controls;
- using GHIElectronics.NETMF.Hardware;
- using Microsoft.SPOT.Presentation.Media;
- using System.Threading;
- namespace Playground
- {
- public class Program
- {
- private static readonly int LCDHeight = SystemMetrics.ScreenHeight;
- private static readonly int LCDWidth = SystemMetrics.ScreenWidth;
- private static Bitmap LCD = new Bitmap(LCDWidth, LCDHeight);
- private static OutputPort led1 = new OutputPort((Cpu.Pin)ChipworkX.Pin.PC5, false);
- private static OutputPort led2 = new OutputPort((Cpu.Pin)ChipworkX.Pin.PC6, false);
- public static void Main()
- {
- Bitmap habr = Resources.GetBitmap(Resources.BitmapResources.Habr);
- LCD.Clear();
- LCD.DrawRectangle(Colors.White, 0, 0, 0, LCDWidth, LCDHeight, 0, 0, Colors.White, 0, 0, Colors.White, 0, 0, ushort.MaxValue);
- LCD.DrawImage((LCDWidth - habr.Width) / 2, (LCDHeight - habr.Height) / 2, habr, 0, 0, habr.Width, habr.Height);
- LCD.Flush();
- Cpu.GlitchFilterTime = new TimeSpan(0, 0, 0, 0, 50);
- InterruptPort btnUp = new InterruptPort((Cpu.Pin)23, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);
- InterruptPort btnSelect = new InterruptPort((Cpu.Pin)20, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);
- InterruptPort btnDown = new InterruptPort((Cpu.Pin)18, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);
- InterruptPort btnRight = new InterruptPort((Cpu.Pin)16, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);
- InterruptPort btnLeft = new InterruptPort((Cpu.Pin)25, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);
- NativeEventHandler btnPress = new NativeEventHandler(btnPress_OnInterrupt);
- btnUp.OnInterrupt += btnPress;
- btnDown.OnInterrupt += btnPress;
- btnLeft.OnInterrupt += btnPress;
- btnRight.OnInterrupt += btnPress;
- btnSelect.OnInterrupt += btnPress;
- Thread.Sleep(Timeout.Infinite);
- }
- static bool penDown = false;
- static int penX = LCDWidth / 2;
- static int penY = LCDHeight / 2;
- static void btnPress_OnInterrupt(uint data1, uint data2, DateTime time)
- {
- switch (data1)
- {
- case 20:
- penDown = !penDown;
- led1.Write(penDown);
- break;
- case 25:
- MovePen(-1, 0);
- break;
- case 16:
- MovePen(1, 0);
- break;
- case 23:
- MovePen(0, -1);
- break;
- case 18:
- MovePen(0, 1);
- break;
- }
- }
- private static void MovePen(int incX, int incY)
- {
- int newX = penX + incX;
- int newY = penY + incY;
- if (newX <= 0 || newX >= LCDWidth)
- return;
- if (newY <= 0 || newY >= LCDHeight)
- return;
- if (penDown)
- {
- LCD.SetPixel(penX + incX, penY + incY, Colors.Red);
- LCD.Flush(penX, penY, 3, 3);
- }
- penX = newX;
- penY = newY;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement