first commit
This commit is contained in:
commit
a5a0434432
1126 changed files with 439481 additions and 0 deletions
46
Software/CSharp/GrovePi/Sensors/RotaryAngleSensor.cs
Normal file
46
Software/CSharp/GrovePi/Sensors/RotaryAngleSensor.cs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
using System;
|
||||
|
||||
namespace GrovePi.Sensors
|
||||
{
|
||||
public interface IRotaryAngleSensor
|
||||
{
|
||||
int SensorValue();
|
||||
double Voltage();
|
||||
double Degrees();
|
||||
}
|
||||
|
||||
public class RotaryAngleSensor : IRotaryAngleSensor
|
||||
{
|
||||
private const int FullAngle = 300;
|
||||
private readonly GrovePi _device;
|
||||
private readonly Pin _pin;
|
||||
|
||||
internal RotaryAngleSensor(GrovePi device, Pin pin)
|
||||
{
|
||||
if (device == null) throw new ArgumentNullException(nameof(device));
|
||||
device.PinMode(_pin, PinMode.Input);
|
||||
_device = device;
|
||||
_pin = pin;
|
||||
}
|
||||
|
||||
public int SensorValue()
|
||||
{
|
||||
return _device.AnalogRead(_pin);
|
||||
}
|
||||
|
||||
public double Voltage()
|
||||
{
|
||||
return Math.Round(((float) SensorValue()*Constants.AdcVoltage/1023), 2);
|
||||
}
|
||||
|
||||
public double Degrees()
|
||||
{
|
||||
return Math.Round((Voltage()*FullAngle)/Constants.GroveVcc, 2);
|
||||
}
|
||||
|
||||
public int Brightness()
|
||||
{
|
||||
return (int) (Degrees()/FullAngle*255);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue