Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Threading;
- using Microsoft.SPOT;
- using Microsoft.SPOT.Presentation;
- using Microsoft.SPOT.Presentation.Controls;
- using Microsoft.SPOT.Presentation.Media;
- using Microsoft.SPOT.Touch;
- using Gadgeteer.Networking;
- using GT = Gadgeteer;
- using GTM = Gadgeteer.Modules;
- using Gadgeteer.Modules.GHIElectronics;
- using Gadgeteer.Modules.Seeed;
- namespace Gadgeteer_DD02_Oled_RFID_01
- {
- public partial class Program
- {
- // create a font that we can use on the oled display screen
- Font displayFont = Resources.GetFont(Resources.FontResources.NinaB);
- // This method is run when the mainboard is powered up or reset.
- void ProgramStarted()
- {
- /*******************************************************************************************
- Modules added in the Program.gadgeteer designer view are used by typing
- their name followed by a period, e.g. button. or camera.
- Many modules generate useful events. Type +=<tab><tab> to add a handler to an event, e.g.:
- button.ButtonPressed +=<tab><tab>
- If you want to do something periodically, use a GT.Timer and handle its Tick event, e.g.:
- GT.Timer timer = new GT.Timer(1000); // every second (1000ms)
- timer.Tick +=<tab><tab>
- timer.Start();
- *******************************************************************************************/
- // create a card read event handling robot
- rfid.CardIDReceived += new RFID.CardIDReceivedEventHandler(rfid_CardIDReceived);
- // stop the oled display redrawing every time we add a graphic element to the screen memory
- oledDisplay.SimpleGraphics.AutoRedraw = false;
- // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
- Debug.Print("Program Started");
- }
- void rfid_CardIDReceived(RFID sender, string ID)
- {
- // a card has been read!
- Debug.Print("This card ID is: " + ID);
- // jump out of the event handler to free it up
- processCard(ID);
- }
- void processCard(string cardID)
- {
- // clear the oled display screen memory of graphics
- oledDisplay.SimpleGraphics.Clear();
- if (cardID == "4D00559CF1")
- {
- Debug.Print("This is card number 1");
- printOledDisplay(1, "Card number");
- printOledDisplay(2, "1");
- printOledDisplay(3, "has been found");
- }
- else if (cardID == "4D0055CDB4")
- {
- Debug.Print("This is card number 2");
- printOledDisplay(1, "Card number");
- printOledDisplay(2, "2");
- printOledDisplay(3, "has been found");
- }
- else if (cardID == "4D00558A13")
- {
- Debug.Print("This is card number 3");
- printOledDisplay(1, "Card number");
- printOledDisplay(2, "3");
- printOledDisplay(3, "has been found");
- }
- else if (cardID == "4D0055A5F7")
- {
- Debug.Print("This is card number 4");
- printOledDisplay(1, "Card number");
- printOledDisplay(2, "4");
- printOledDisplay(3, "has been found");
- }
- else
- {
- Debug.Print("This card is unknown");
- printOledDisplay(1, "Card number");
- printOledDisplay(2, cardID);
- }
- // switch is another method for determining a condition
- //switch (cardID)
- //{
- // case "4D00559CF1":
- // Debug.Print("This is card number 1");
- // printOledDisplay(1, "Card number");
- // printOledDisplay(2, "1");
- // printOledDisplay(3, "has been found");
- // break;
- // case "4D0055CDB4":
- // Debug.Print("This is card number 2");
- // printOledDisplay(1, "Card number");
- // printOledDisplay(2, "2");
- // printOledDisplay(3, "has been found");
- // break;
- // case "4D00558A13":
- // Debug.Print("This is card number 3");
- // printOledDisplay(1, "Card number");
- // printOledDisplay(2, "3");
- // printOledDisplay(3, "has been found");
- // break;
- // case "4D0055A5F7":
- // Debug.Print("This is card number 4");
- // printOledDisplay(1, "Card number");
- // printOledDisplay(2, "4");
- // printOledDisplay(3, "has been found");
- // break;
- // default:
- // Debug.Print("This card is unknown");
- // printOledDisplay(1, "Card number");
- // printOledDisplay(2, cardID);
- // break;
- //}
- // redraw the screen with all new graphics
- oledDisplay.SimpleGraphics.Redraw();
- }
- // a custom method for printing text to the OLED screen
- // input a line number and the text to be printed as a text string
- void printOledDisplay(uint lineNumber, string displayMessage)
- {
- uint xPos = 0;
- oledDisplay.SimpleGraphics.DisplayText(displayMessage, displayFont, GT.Color.White, xPos, lineNumber * 12);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment