I have Fez Mini and Fez Spider and i want to move reflective sensors from mini to spider.
I tried to mimic FEZ_Components_ReflectiveSensor.cs and I wrote mine on class.
But when i call it, i get error that adc is null.
using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.Hardware;
using GHIElectronics.NETMF.FEZ;
using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;
using GTI = Gadgeteer.Interfaces;
using Gadgeteer.Interfaces;
using Gadgeteer;
namespace GHIElectronics.NETMF.FEZ
{
public static partial class FEZ_Components
{
public class ReflectiveSensor : IDisposable
{
AnalogIn adc;
public string SensorValue;
int trigger_level;
public void Dispose()
{
adc.Dispose();
}
public ReflectiveSensor(GT.Socket.Pin pin, int socket, int reflection_detection_trigger_percentage)
{
GT.Socket mySocket = GT.Socket.GetSocket(socket, true, null, null);
adc = new AnalogIn((AnalogIn.Pin)mySocket.ReservePin(pin, null));
adc.SetLinearScale(0, 100);
if (reflection_detection_trigger_percentage < 100 && reflection_detection_trigger_percentage >= 0)
trigger_level = reflection_detection_trigger_percentage;
else
throw new Exception("You must enter a percentage value betweeon 0 and 100");
}
public enum DetectingState : byte
{
ReflectionNotDetected = 0,
ReflectionDeteced = 1,
}
public DetectingState GetState()
{
SensorValue = adc.Read().ToString();
Debug.Print(adc.Read().ToString());
return (adc.Read() >= trigger_level) ? DetectingState.ReflectionDeteced : DetectingState.ReflectionNotDetected;
}
}
}
}