Advertisement
Guest User

.Net Micro Framework Sample

a guest
Aug 13th, 2010
489
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using Microsoft.SPOT;
  3. using Microsoft.SPOT.Hardware;
  4. using Microsoft.SPOT.Presentation;
  5. using Microsoft.SPOT.Presentation.Controls;
  6.  
  7. using GHIElectronics.NETMF.Hardware;
  8. using Microsoft.SPOT.Presentation.Media;
  9. using System.Threading;
  10.  
  11. namespace Playground
  12. {
  13.     public class Program
  14.     {
  15.         private static readonly int LCDHeight = SystemMetrics.ScreenHeight;
  16.         private static readonly int LCDWidth = SystemMetrics.ScreenWidth;
  17.  
  18.         private static Bitmap LCD = new Bitmap(LCDWidth, LCDHeight);
  19.  
  20.         private static OutputPort led1 = new OutputPort((Cpu.Pin)ChipworkX.Pin.PC5, false);
  21.         private static OutputPort led2 = new OutputPort((Cpu.Pin)ChipworkX.Pin.PC6, false);
  22.  
  23.  
  24.         public static void Main()
  25.         {
  26.             Bitmap habr = Resources.GetBitmap(Resources.BitmapResources.Habr);
  27.  
  28.             LCD.Clear();
  29.             LCD.DrawRectangle(Colors.White, 0, 0, 0, LCDWidth, LCDHeight, 0, 0, Colors.White, 0, 0, Colors.White, 0, 0, ushort.MaxValue);
  30.             LCD.DrawImage((LCDWidth - habr.Width) / 2, (LCDHeight - habr.Height) / 2, habr, 0, 0, habr.Width, habr.Height);
  31.             LCD.Flush();
  32.  
  33.             Cpu.GlitchFilterTime = new TimeSpan(0, 0, 0, 0, 50);
  34.             InterruptPort btnUp = new InterruptPort((Cpu.Pin)23, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);
  35.             InterruptPort btnSelect = new InterruptPort((Cpu.Pin)20, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);
  36.             InterruptPort btnDown = new InterruptPort((Cpu.Pin)18, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);
  37.             InterruptPort btnRight = new InterruptPort((Cpu.Pin)16, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);
  38.             InterruptPort btnLeft = new InterruptPort((Cpu.Pin)25, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);
  39.  
  40.             NativeEventHandler btnPress = new NativeEventHandler(btnPress_OnInterrupt);
  41.             btnUp.OnInterrupt += btnPress;
  42.             btnDown.OnInterrupt += btnPress;
  43.             btnLeft.OnInterrupt += btnPress;
  44.             btnRight.OnInterrupt += btnPress;
  45.             btnSelect.OnInterrupt += btnPress;
  46.  
  47.  
  48.             Thread.Sleep(Timeout.Infinite);
  49.         }
  50.  
  51.         static bool penDown = false;
  52.  
  53.         static int penX = LCDWidth / 2;
  54.         static int penY = LCDHeight / 2;
  55.  
  56.         static void btnPress_OnInterrupt(uint data1, uint data2, DateTime time)
  57.         {
  58.             switch (data1)
  59.             {
  60.                 case 20:
  61.                     penDown = !penDown;
  62.                     led1.Write(penDown);
  63.                     break;
  64.                 case 25:
  65.                     MovePen(-1, 0);
  66.                     break;
  67.                 case 16:
  68.                     MovePen(1, 0);
  69.                     break;
  70.                 case 23:
  71.                     MovePen(0, -1);
  72.                     break;
  73.                 case 18:
  74.                     MovePen(0, 1);
  75.                     break;
  76.             }
  77.         }
  78.  
  79.         private static void MovePen(int incX, int incY)
  80.         {
  81.             int newX = penX + incX;
  82.             int newY = penY + incY;
  83.             if (newX <= 0 || newX >= LCDWidth)
  84.                 return;
  85.             if (newY <= 0 || newY >= LCDHeight)
  86.                 return;
  87.             if (penDown)
  88.             {
  89.                 LCD.SetPixel(penX + incX, penY + incY, Colors.Red);
  90.                 LCD.Flush(penX, penY, 3, 3);
  91.             }
  92.             penX = newX;
  93.             penY = newY;
  94.         }
  95.     }
  96. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement