/// <summary> /// /// </summary> /// <param name="goPiGo">The GoPiGo3 class</param> /// <param name="port">The Grove Port, need to be in the list of SupportedPorts</param> public UltraSonicSensor(GoPiGo goPiGo, GrovePort port) { if (!SupportedPorts.Contains(port)) { throw new ArgumentException($"Error: Grove Port not supported"); } _goPiGo = goPiGo; Port = port; _goPiGo.SetGroveType(port, GroveSensorType.Ultrasonic); }
/// <summary> /// Create a motor /// </summary> /// <param name="brick">GoPiGo3 brick</param> /// <param name="port">Motor port</param> /// <param name="timeout">Timeout in milliseconds</param> public Motor(GoPiGo brick, MotorPort port, int timeout) { if (port == MotorPort.Both) { throw new ArgumentException($"Motor class can only have 1 motor"); } _goPiGo = brick; Port = port; _periodRefresh = timeout; _timer = new Timer(UpdateSensor, this, TimeSpan.FromMilliseconds(timeout), TimeSpan.FromMilliseconds(timeout)); }
/// <summary> /// /// </summary> /// <param name="goPiGo">The GoPiGo3 class</param> /// <param name="port">The Grove Port, need to be in the list of SupportedPorts</param> public DigitalInput(GoPiGo goPiGo, GrovePort port) { if (!SupportedPorts.Contains(port)) { throw new ArgumentException($"Error: Grove Port not supported"); } _goPiGo = goPiGo; Port = port; _goPiGo.SetGroveType(port, GroveSensorType.Custom); _mode = (port == GrovePort.Grove1) ? GrovePort.Grove1Pin1 : GrovePort.Grove2Pin1; _goPiGo.SetGroveMode(_mode, GroveInputOutput.InputDigital); }
/// <summary> /// Constructor for the generic Analog Sensor /// </summary> /// <param name="goPiGo">The GoPiGo3 class</param> /// <param name="port">The Grove Port, need to be in the list of SupportedPorts</param> public AnalogSensor(GoPiGo goPiGo, GrovePort port) { if (!SupportedPorts.Contains(port)) { throw new ArgumentException(nameof(port), "Grove port not supported"); } _goPiGo = goPiGo; Port = port; _goPiGo.SetGroveType(port, GroveSensorType.Custom); _goPiGo.SetGroveMode(port, GroveInputOutput.InputAnalog); _mode = Port == GrovePort.Grove1 ? GrovePort.Grove1Pin1 : GrovePort.Grove2Pin1; }
/// <summary> /// /// </summary> /// <param name="goPiGo">The GoPiGo3 class</param> /// <param name="port">The Grove Port, need to be in the list of SupportedPorts</param> /// <param name="duty">The PWM duty to use to generate the sound from 0 to 100</param> public Buzzer(GoPiGo goPiGo, GrovePort port, byte duty) { if (!SupportedPorts.Contains(port)) { throw new ArgumentException($"Error: Grove Port not supported"); } _goPiGo = goPiGo; Port = port; _goPiGo.SetGroveType(port, GroveSensorType.Custom); _mode = (port == GrovePort.Grove1) ? GrovePort.Grove1Pin1 : GrovePort.Grove2Pin1; _goPiGo.SetGroveMode(_mode, GroveInputOutput.OutputPwm); Duty = duty; Value = 24_000; //The default value Stop(); }
/// <summary> /// Creates a new instance of <see cref="PotentiometerSensor"/>- /// </summary> /// <param name="goPiGo">The GoPiGo3 class</param> /// <param name="port">The Grove Port, need to be in the list of SupportedPorts</param> public PotentiometerSensor(GoPiGo goPiGo, GrovePort port) : base(goPiGo, port) { }
/// <summary> /// Constructor for the Buzzer class /// </summary> /// <param name="goPiGo">The GoPiGo3 class</param> /// <param name="port">The Grove Port, need to be in the list of SupportedPorts</param> public Buzzer(GoPiGo goPiGo, GrovePort port) : this(goPiGo, port, 50) { }
/// <summary> /// Create a vehicle with 2 motors, one left and one right /// </summary> public Vehicle(GoPiGo goPiGo) { _goPiGo = goPiGo; PortLeft = MotorPort.MotorLeft; PortRight = MotorPort.MotorRight; }
public EncoderController(GoPiGo goPiGo) { _goPiGo = goPiGo; }
/// <summary> /// Test program entry point /// </summary> /// <param name="args">Unused</param> public static void Main(string[] args) { Console.WriteLine("Hello GoPiGo3!"); // Default on the Raspberry is Bus ID = 0 and Chip Set Select Line = 1 for GoPiGo3 var settings = new SpiConnectionSettings(0, 1) { // 500K is the SPI communication with GoPiGo ClockFrequency = 500000, // see http://tightdev.net/SpiDev_Doc.pdf Mode = SpiMode.Mode0, DataBitLength = 8 }; _goPiGo3 = new GoPiGo(SpiDevice.Create(settings)); Console.WriteLine("Choose a test by entering the number and press enter:"); Console.WriteLine(" 1. Basic GoPiGo3 info and embedded led test"); Console.WriteLine(" 2. Control left motor from motor right position"); Console.WriteLine(" 3. Read encoder of right motor"); Console.WriteLine(" 4. Test both servo motors"); Console.WriteLine(" 5. Test Ultrasonic sensor on Grove1"); Console.WriteLine(" 6. Test buzzer on Grove1"); Console.WriteLine(" 7. Change buzzer tone on Grove1 with a potentiometer on Grove2"); Console.WriteLine(" 8. Test sound sensor on Grove1"); Console.WriteLine(" 9. Test a relay on Grove1"); Console.WriteLine(" 10. Test a button on Grove1"); Console.WriteLine(" 11. Control a led light on Grove2 from a light sensor on Grove1"); Console.WriteLine(" 12. Test MotorLeft speed based on encoder"); Console.WriteLine(" 13. Test driving the vehicle"); var readCar = Console.ReadLine(); switch (readCar) { case "1": TestGoPiGoDetails(); break; case "2": TestMotorPosition(); break; case "3": TestMotorEncoder(); break; case "4": TestServo(); break; case "5": TestUltrasound(); break; case "6": TestBuzzer(); break; case "7": TestPotentiometer(); break; case "8": TestSound(); break; case "9": TestRelay(); break; case "10": TestButton(); break; case "11": TestLedPwmLightSensor(); break; case "12": TestMotorTacho(); break; case "13": Testvehicle(); break; default: break; } }
/// <summary> /// /// </summary> /// <param name="goPiGo">The GoPiGo3 class</param> /// <param name="port">The Grove Port, need to be in the list of SupportedPorts</param> public SoundSensor(GoPiGo goPiGo, GrovePort port) : base(goPiGo, port) { }
/// <summary> /// Constructor of the normal Led class /// </summary> /// <param name="goPiGo">The GoPiGo3 class</param> /// <param name="port">The Grove Port, need to be in the list of SupportedPorts</param> /// <param name="inverted">If the led is inverted, off when level if high and off when level is low</param> public Led(GoPiGo goPiGo, GrovePort port, bool inverted) : base(goPiGo, port, inverted) { }
/// <summary> /// Button constructor /// </summary> /// <param name="goPiGo">The GoPiGo3 class</param> /// <param name="port">The Grove Port, need to be in the list of SupportedPorts</param> public Button(GoPiGo goPiGo, GrovePort port) : base(goPiGo, port) { }
/// <summary> /// Constructor for the LedPwm class /// </summary> /// <param name="goPiGo">The GoPiGo3 class</param> /// <param name="port">The Grove Port, need to be in the list of SupportedPorts</param> public LedPwm(GoPiGo goPiGo, GrovePort port) : this(goPiGo, port, 0) { }
/// <summary> /// Creates a new instance of <see cref="LightSensor"/>. /// </summary> /// <param name="goPiGo">The GoPiGo3 class</param> /// <param name="port">The Grove Port, need to be in the list of SupportedPorts</param> public LightSensor(GoPiGo goPiGo, GrovePort port) : base(goPiGo, port) { }
internal UltrasonicRangerSensor(GoPiGo device, Pin pin) { _device = device; _pin = pin; }
/// <summary> /// Create a motor /// </summary> /// <param name="brick">GoPiGo3 brick</param> /// <param name="port">Motor port</param> public Motor(GoPiGo brick, MotorPort port) : this(brick, port, 1000) { }
/// <summary> /// /// </summary> /// <param name="goPiGo">The GoPiGo3 class</param> /// <param name="port">The Grove Port, need to be in the list of SupportedPorts</param> public Relay(GoPiGo goPiGo, GrovePort port) : this(goPiGo, port, false) { }
/// <summary> /// Constructor of the normal Led class /// </summary> /// <param name="goPiGo">The GoPiGo3 class</param> /// <param name="port">The Grove Port, need to be in the list of SupportedPorts</param> public Led(GoPiGo goPiGo, GrovePort port) : this(goPiGo, port, false) { }
/// <summary> /// Constructor for the LedPwm class /// </summary> /// <param name="goPiGo">The GoPiGo3 class</param> /// <param name="port">The Grove Port, need to be in the list of SupportedPorts</param> /// <param name="duty">The duty cycle for the led, 100 = full bright, 0 = full dark</param> public LedPwm(GoPiGo goPiGo, GrovePort port, byte duty) : base(goPiGo, port, duty) { }
/// <summary> /// /// </summary> /// <param name="goPiGo">The GoPiGo3 class</param> /// <param name="port">The Grove Port, need to be in the list of SupportedPorts</param> /// <param name="inverted">If inverted, the relay is on when output is low and off when output is high</param> public Relay(GoPiGo goPiGo, GrovePort port, bool inverted) : base(goPiGo, port) { IsInverted = inverted; }