Hello everyone,
I searched and couldn’t find anything relating to reading a Hall sensor (except for a very old post which won’t help me). This is the sensor I’m referring to: Hall High Sensitivity Sensor Switch - emartee.com
My current setup (using a Hydra, Cerberus, and a couple other main boards around the house) have a very basic premise-read the voltage from a Hall sensor, and send a signal to an RFPipe if it drops below a certain number. My code worked in Visual Studio 2010; but the same code doesn’t work for VS 2013. The underlying SDK seems to have changed and I can’t find the documentation to help me.
Here’s my VS2010 code - any thoughts? This seems like an easy objective; but not easy enough for me. The guts of the program is when the ticker.tick event fires, that’s where it is supposed to read the input voltage.
As it stands, when massaged into VS 2013 it doesn’t know what the Socket declaration is, and also the “GTI.AnalogInput” doesn’t exist. (because the GTI.Gadteteer.Interface doesn’t exist)
Any help?
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 Microsoft.SPOT.Hardware;
using Gadgeteer;
using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using GTI = Gadgeteer.Interfaces;
using Gadgeteer.Modules.GHIElectronics;
using Gadgeteer.Modules;
namespace FrontDoorModule
{
public partial class Program
{
private GT.Timer _pollingTimer;
private GTI.AnalogInput analogInput;
private bool disarmButton;
// This method is run when the mainboard is powered up or reset.
void ProgramStarted()
{
disarmButton = false;
Socket socket = Gadgeteer.Socket.GetSocket(3, true, null, null);
analogInput = new GTI.AnalogInput(socket, Socket.Pin.Three, null);
_pollingTimer = new GT.Timer(1000);
_pollingTimer.Tick += new GT.Timer.TickEventHandler(_pollingTimer_Tick);
Mainboard.SetDebugLED(false);
_pollingTimer.Start();
button.ButtonPressed += new GTM.GHIElectronics.Button.ButtonEventHandler(button_ButtonPressed);
rfPipe.DataReceived +=new GTM.IngenuityMicro.RfPipe.RfPipeReceivedHandler(rfPipe_DataReceived);
}
void button_ButtonPressed(GTM.GHIElectronics.Button sender, GTM.GHIElectronics.Button.ButtonState state)
{
// activate disarm variable
disarmButton = true;
// play disarm tone sequence
Tunes.MusicNote note = new Tunes.MusicNote(Tunes.Tone.C5, 200);
tunes.AddNote(note);
note = new Tunes.MusicNote(Tunes.Tone.C5, 200);
tunes.AddNote(note);
tunes.Play();
// if button is pressed begin egress sequence
_pollingTimer.Stop();
// sleep for 2 minutes giving the person time to leave
Thread.Sleep(120000);
disarmButton = false;
_pollingTimer.Start();
}
void _pollingTimer_Tick(GT.Timer timer)
{
if (disarmButton == false)
{
// check for voltage that is higher than 3.0
if (analogInput.ReadVoltage() < 3)
{
// sleep for 250 milliseconds
Thread.Sleep(250);
// check voltage again - this was added as a failsafe to prevent false positives
if (analogInput.ReadVoltage() < 3)
{
rfPipe.SendData("fd opened");
Mainboard.SetDebugLED(true);
Tunes.MusicNote note = new Tunes.MusicNote(Tunes.Tone.C5, 300);
tunes.AddNote(note);
tunes.Play();
Thread.Sleep(700);
Mainboard.SetDebugLED(false);
} // end if second voltage read
} // end if first voltage read
} // end if disarm is false
}
}
}