first commit
This commit is contained in:
commit
a5a0434432
1126 changed files with 439481 additions and 0 deletions
38
Software/CSharp/GrovePi/Sensors/Sensor.cs
Normal file
38
Software/CSharp/GrovePi/Sensors/Sensor.cs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
using System;
|
||||
|
||||
namespace GrovePi.Sensors
|
||||
{
|
||||
public abstract class Sensor<TSensorType> where TSensorType : class
|
||||
{
|
||||
protected readonly IGrovePi Device;
|
||||
protected readonly Pin Pin;
|
||||
|
||||
internal Sensor(IGrovePi device, Pin pin, PinMode pinMode)
|
||||
{
|
||||
if (device == null) throw new ArgumentNullException(nameof(device));
|
||||
Device = device;
|
||||
Pin = pin;
|
||||
device.PinMode(Pin, pinMode);
|
||||
}
|
||||
|
||||
internal Sensor(IGrovePi device, Pin pin)
|
||||
{
|
||||
if (device == null) throw new ArgumentNullException(nameof(device));
|
||||
Device = device;
|
||||
Pin = pin;
|
||||
}
|
||||
|
||||
public SensorStatus CurrentState => (SensorStatus) Device.DigitalRead(Pin);
|
||||
|
||||
public TSensorType ChangeState(SensorStatus newState)
|
||||
{
|
||||
Device.DigitalWrite(Pin, (byte) newState);
|
||||
return this as TSensorType;
|
||||
}
|
||||
|
||||
public void AnalogWrite(byte value)
|
||||
{
|
||||
Device.AnalogWrite(Pin,value);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue