peony3000

Gadgeteer_DD02_Oled_RFID_01

Feb 23rd, 2013
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.77 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Threading;
  4. using Microsoft.SPOT;
  5. using Microsoft.SPOT.Presentation;
  6. using Microsoft.SPOT.Presentation.Controls;
  7. using Microsoft.SPOT.Presentation.Media;
  8. using Microsoft.SPOT.Touch;
  9.  
  10. using Gadgeteer.Networking;
  11. using GT = Gadgeteer;
  12. using GTM = Gadgeteer.Modules;
  13. using Gadgeteer.Modules.GHIElectronics;
  14. using Gadgeteer.Modules.Seeed;
  15.  
  16. namespace Gadgeteer_DD02_Oled_RFID_01
  17. {
  18.     public partial class Program
  19.     {
  20.          
  21.         // create a font that we can use on the oled display screen
  22.         Font displayFont = Resources.GetFont(Resources.FontResources.NinaB);
  23.    
  24.     // This method is run when the mainboard is powered up or reset.  
  25.         void ProgramStarted()
  26.         {
  27.             /*******************************************************************************************
  28.             Modules added in the Program.gadgeteer designer view are used by typing
  29.             their name followed by a period, e.g.  button.  or  camera.
  30.            
  31.             Many modules generate useful events. Type +=<tab><tab> to add a handler to an event, e.g.:
  32.                 button.ButtonPressed +=<tab><tab>
  33.            
  34.             If you want to do something periodically, use a GT.Timer and handle its Tick event, e.g.:
  35.                 GT.Timer timer = new GT.Timer(1000); // every second (1000ms)
  36.                 timer.Tick +=<tab><tab>
  37.                 timer.Start();
  38.             *******************************************************************************************/
  39.            
  40.             // create a card read event handling robot
  41.             rfid.CardIDReceived += new RFID.CardIDReceivedEventHandler(rfid_CardIDReceived);
  42.  
  43.             // stop the oled display redrawing every time we add a graphic element to the screen memory
  44.             oledDisplay.SimpleGraphics.AutoRedraw = false;
  45.  
  46.             // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
  47.             Debug.Print("Program Started");
  48.         }
  49.  
  50.         void rfid_CardIDReceived(RFID sender, string ID)
  51.         {
  52.             // a card has been read!
  53.             Debug.Print("This card ID is: " + ID);
  54.  
  55.             // jump out of the event handler to free it up
  56.             processCard(ID);
  57.         }
  58.  
  59.         void processCard(string cardID)
  60.         {
  61.             // clear the oled display screen memory of graphics
  62.             oledDisplay.SimpleGraphics.Clear();
  63.  
  64.             if (cardID == "4D00559CF1")
  65.             {
  66.                 Debug.Print("This is card number 1");
  67.                 printOledDisplay(1, "Card number");
  68.                 printOledDisplay(2, "1");
  69.                 printOledDisplay(3, "has been found");
  70.             }
  71.             else if (cardID == "4D0055CDB4")
  72.             {
  73.                 Debug.Print("This is card number 2");
  74.                 printOledDisplay(1, "Card number");
  75.                 printOledDisplay(2, "2");
  76.                 printOledDisplay(3, "has been found");
  77.             }
  78.             else if (cardID == "4D00558A13")
  79.             {
  80.                 Debug.Print("This is card number 3");
  81.                 printOledDisplay(1, "Card number");
  82.                 printOledDisplay(2, "3");
  83.                 printOledDisplay(3, "has been found");
  84.             }
  85.             else if (cardID == "4D0055A5F7")
  86.             {
  87.                 Debug.Print("This is card number 4");
  88.                 printOledDisplay(1, "Card number");
  89.                 printOledDisplay(2, "4");
  90.                 printOledDisplay(3, "has been found");
  91.             }
  92.             else
  93.             {
  94.                 Debug.Print("This card is unknown");
  95.                 printOledDisplay(1, "Card number");
  96.                 printOledDisplay(2, cardID);
  97.             }
  98.  
  99.             // switch is another method for determining a condition
  100.  
  101.             //switch (cardID)
  102.             //{
  103.             //    case "4D00559CF1":
  104.             //        Debug.Print("This is card number 1");
  105.             //        printOledDisplay(1, "Card number");
  106.             //        printOledDisplay(2, "1");
  107.             //        printOledDisplay(3, "has been found");
  108.             //        break;
  109.             //    case "4D0055CDB4":
  110.             //        Debug.Print("This is card number 2");
  111.             //        printOledDisplay(1, "Card number");
  112.             //        printOledDisplay(2, "2");
  113.             //        printOledDisplay(3, "has been found");
  114.             //        break;
  115.             //    case "4D00558A13":
  116.             //        Debug.Print("This is card number 3");
  117.             //        printOledDisplay(1, "Card number");
  118.             //        printOledDisplay(2, "3");
  119.             //        printOledDisplay(3, "has been found");
  120.             //        break;
  121.             //    case "4D0055A5F7":
  122.             //        Debug.Print("This is card number 4");
  123.             //        printOledDisplay(1, "Card number");
  124.             //        printOledDisplay(2, "4");
  125.             //        printOledDisplay(3, "has been found");
  126.             //        break;
  127.             //    default:
  128.             //        Debug.Print("This card is unknown");
  129.             //        printOledDisplay(1, "Card number");
  130.             //        printOledDisplay(2, cardID);
  131.             //        break;
  132.             //}
  133.  
  134.             // redraw the screen with all new graphics
  135.             oledDisplay.SimpleGraphics.Redraw();
  136.  
  137.             }
  138.  
  139.         // a custom method for printing text to the OLED screen
  140.         // input a line number and the text to be printed as a text string
  141.         void printOledDisplay(uint lineNumber, string displayMessage)
  142.         {
  143.             uint xPos = 0;
  144.             oledDisplay.SimpleGraphics.DisplayText(displayMessage, displayFont, GT.Color.White, xPos, lineNumber * 12);
  145.         }
  146.  
  147.     }
  148. }
Advertisement
Add Comment
Please, Sign In to add comment