Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- 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_Accelerometer_01
- {
- public partial class Program
- {
- GT.Timer timer = new GT.Timer(1000, GT.Timer.BehaviorType.RunOnce);
- void ProgramStarted()
- {
- //
- accelerometer.ThresholdExceeded += new GTM.Seeed.Accelerometer.ThresholdExceededEventHandler(accelerometer_ThresholdExceeded);
- accelerometer.MeasurementRange = GTM.Seeed.Accelerometer.Range.TwoG;
- // steup a timer to wait for the reset action
- timer.Tick += new GT.Timer.TickEventHandler(timer_Tick);
- // set the calibration point (the device shouldn't be moving!)
- accelerometer.Calibrate();
- //accelerometer.SaveCalibration();
- //accelerometer.LoadCalibration();
- accelerometer.EnableThresholdDetection(-3.0, false, false, true, true, false, false);
- // continuous accelerometer measuring
- //accelerometer.MeasurementComplete += new Accelerometer.MeasurementCompleteEventHandler(accelerometer_MeasurementComplete);
- //accelerometer.ContinuousMeasurementInterval = new TimeSpan(0, 0, 0, 0, 300); // 300 ms
- //accelerometer.StartContinuousMeasurements();
- // let everyone know
- Debug.Print("Program Started");
- }
- void accelerometer_ThresholdExceeded(GTM.Seeed.Accelerometer sender)
- {
- Debug.Print("Threshold exceeded!");
- // start the timer to reset the accelerometer when it has settled again
- timer.Start();
- }
- void timer_Tick(GT.Timer timer)
- {
- accelerometer.ResetThresholdDetection();
- Debug.Print("Threshold reset and waiting....");
- // stop the timer just in case
- timer.Stop();
- }
- // use this event handeler for continuous readings
- void accelerometer_MeasurementComplete(GTM.Seeed.Accelerometer sender, GTM.Seeed.Accelerometer.Acceleration acceleration)
- {
- double mag = acceleration.X * acceleration.X + acceleration.Y * acceleration.Y + acceleration.Z * acceleration.Z;
- Debug.Print(acceleration.ToString() + " " + mag.ToString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment