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_Compass_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();
- *******************************************************************************************/
- // set the time interval between each compass reading event
- compass.ContinuousMeasurementInterval = new TimeSpan(0, 0, 0, 0, 500);
- // setup a compass reading robot event watcher
- compass.MeasurementComplete += new Compass.MeasurementCompleteEventHandler(compass_MeasurementComplete);
- // start the compass reading
- compass.StartContinuousMeasurements();
- // 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 compass_MeasurementComplete(Compass sender, Compass.SensorData sensorData)
- {
- // there is a new compass reading!
- Debug.Print("Compass reading: " + sensorData.Angle);
- // jump out of the event handler to free it up
- // print the message to the oled display
- // convert the angle number from its original form of a double to an integer and then to a string
- processMessage(((int)sensorData.Angle).ToString());
- }
- void processMessage(string recievedMessage)
- {
- // clear the oled display screen memory of graphics
- oledDisplay.SimpleGraphics.Clear();
- // write the message to the display screen
- printOledDisplay(1, recievedMessage);
- // 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