/// <summary> /// Constructor for a single servo output. /// </summary> /// <param name="pwm">PWM output instance.</param> /// <param name="freq">PWM pulse frequency.</param> /// <param name="position">Initial servo position.</param> public Output(IO.Interfaces.PWM.Output pwm, int freq = 50, double position = IO.Interfaces.Servo.Positions.Neutral) { this.pwm = pwm; this.period = 1000000000 / freq; this.position = position; }
/// <summary> /// Constructor for a single GPIO pin. /// </summary> /// <param name="outp">PWM output instance.</param> /// <param name="state">Initial GPIO output state.</param> /// <param name="dutycycle">Initial PWM output duty cycle. /// Allowed values are 0.0 to 100.0 percent.</param> public Pin(IO.Interfaces.PWM.Output outp, bool state = false, double dutycycle = IO.Interfaces.PWM.DutyCycles.Maximum) { this.myoutput = outp; this.myduty = dutycycle; this.state = state; }
// Type 2 motor drivers, using two PWM outputs: One for CW // rotation and one for CCW rotation /// <summary> /// Constructor for a single motor, using two PWM outputs /// for clockwise and counterclockwise rotation control. /// </summary> /// <param name="clockwise">PWM output instance (for clockwise /// rotation control).</param> /// <param name="counterclockwise">PWM output instance (for /// counterclockwise rotation control).</param> /// <param name="velocity">Initial normalized motor velocity. /// Allowed values are -1.0 (full speed reverse) to +1.0 /// (full speed forward.</param> public Output(IO.Interfaces.PWM.Output clockwise, IO.Interfaces.PWM.Output counterclockwise, double velocity = IO.Interfaces.Motor.Velocities.Stop) { dirpin = null; pwm0 = clockwise; pwm1 = counterclockwise; this.velocity = velocity; }
private IO.Interfaces.PWM.Output pwm1; // CCW // Type 1 motor drivers, using one GPIO output for direction, // and one PWM output for speed /// <summary> /// Constructor for a single motor, using one GPIO pin for /// direction control, and one PWM output for speed control. /// </summary> /// <param name="direction">GPIO pin instance (for direction /// control).</param> /// <param name="speed">PWM output instance (for speed /// control).</param> /// <param name="velocity">Initial normalized motor velocity. /// Allowed values are -1.0 (full speed reverse) to +1.0 /// (full speed forward.</param> public Output(IO.Interfaces.GPIO.Pin direction, IO.Interfaces.PWM.Output speed, double velocity = IO.Interfaces.Motor.Velocities.Stop) { dirpin = direction; pwm0 = speed; pwm1 = null; this.velocity = velocity; }
/// <summary> /// Constructor for a single servo output. /// </summary> /// <param name="pwm">PWM output instance.</param> /// <param name="freq">PWM pulse frequency.</param> /// <param name="position">Initial servo position.</param> public Output(IO.Interfaces.PWM.Output pwm, int freq = 50, double position = IO.Interfaces.Servo.Positions.Neutral) { if ((position < IO.Interfaces.Servo.Positions.Minimum) || (position > IO.Interfaces.Servo.Positions.Maximum)) { throw new System.Exception("Invalid servo position"); } this.pwm = pwm; this.period = 1000000000 / freq; this.position = position; }
/// <summary> /// Constructor for a single 7seg click. /// </summary> /// <param name="socket">mikroBUS socket number.</param> /// <param name="radix">Numerical base or radix. Allowed values are /// <c>Decimal</c> and <c>Hexadecimal</c>.</param> /// <param name="blanking">Zero blanking. Allowed values are /// <c>None</c>, <c>Leading</c>, and <c>Full</c>.</param> /// <param name="pwmfreq">PWM frequency. Set to zero to use GPIO /// instead of PWM.</param> /// <param name="remdev">Remote I/O server device object.</param> public Board(int socket, Base radix = Base.Decimal, ZeroBlanking blanking = ZeroBlanking.None, int pwmfreq = 100, IO.Remote.Device remdev = null) { // Create Remote I/O server device object, if one wasn't supplied if (remdev == null) { remdev = new IO.Remote.Device(); } // Create a mikroBUS socket object IO.Remote.mikroBUS.Socket S = new IO.Remote.mikroBUS.Socket(socket); // Configure hardware reset GPIO pin myRSTgpio = remdev.GPIO_Create(S.RST, IO.Interfaces.GPIO.Direction.Output, true); // Issue hardware reset Reset(); // Configure PWM pin -- Prefer PWM over GPIO, if possible, and // assume full brightness until otherwise changed. myPWMgpio = null; myPWMout = null; if ((pwmfreq > 0) && (S.PWMOut != IO.Remote.Device.Unavailable)) { myPWMout = remdev.PWM_Create(S.PWMOut, pwmfreq, 100.0); } else if (S.PWM != IO.Remote.Device.Unavailable) { myPWMgpio = remdev.GPIO_Create(S.PWM, IO.Interfaces.GPIO.Direction.Output, true); } // Configure 74HC595 shift register chain mychain = new SN74HC595.Device(remdev.SPI_Create(S.SPIDev, IO.Devices.SN74HC595.Device.SPI_Mode, 8, IO.Devices.SN74HC595.Device.SPI_MaxFreq), 2); myradix = radix; myblanking = blanking; Clear(); }
// Type 2 motor drivers, using two PWM outputs: One for CW // rotation and one for CCW rotation /// <summary> /// Constructor for a single motor, using two PWM outputs /// for clockwise and counterclockwise rotation control. /// </summary> /// <param name="clockwise">PWM output instance (for clockwise /// rotation control).</param> /// <param name="counterclockwise">PWM output instance (for /// counterclockwise rotation control).</param> /// <param name="velocity">Initial motor velocity.</param> public Output(IO.Interfaces.PWM.Output clockwise, IO.Interfaces.PWM.Output counterclockwise, double velocity = IO.Interfaces.Motor.Velocities.Stop) { if ((velocity < IO.Interfaces.Motor.Velocities.Minimum) || (velocity > IO.Interfaces.Motor.Velocities.Maximum)) { throw new System.Exception("Invalid motor velocity"); } dirpin = null; pwm0 = clockwise; pwm1 = counterclockwise; this.velocity = velocity; }
private IO.Interfaces.PWM.Output pwm1; // CCW // Type 1 motor drivers, using one GPIO output for direction, // and one PWM output for speed /// <summary> /// Constructor for a single motor, using one GPIO pin for /// direction control, and one PWM output for speed control. /// </summary> /// <param name="direction">GPIO pin instance (for direction /// control).</param> /// <param name="speed">PWM output instance (for speed /// control).</param> /// <param name="velocity">Initial motor velocity.</param> public Output(IO.Interfaces.GPIO.Pin direction, IO.Interfaces.PWM.Output speed, double velocity = IO.Interfaces.Motor.Velocities.Stop) { if ((velocity < IO.Interfaces.Motor.Velocities.Minimum) || (velocity > IO.Interfaces.Motor.Velocities.Maximum)) { throw new System.Exception("Invalid motor velocity"); } dirpin = direction; pwm0 = speed; pwm1 = null; this.velocity = velocity; }
/// <summary> /// Constructor for a single 7seg click. /// </summary> /// <param name="socket">mikroBUS socket number.</param> /// <param name="radix">Numerical base or radix. Allowed values are /// <c>Decimal</c> and <c>Hexadecimal</c>.</param> /// <param name="blanking">Zero blanking. Allowed values are /// <c>None</c>, <c>Leading</c>, and <c>Full</c>.</param> /// <param name="pwmfreq">PWM frequency. Set to zero to use GPIO /// instead of PWM.</param> public Board(int socket, Base radix = Base.Decimal, ZeroBlanking blanking = ZeroBlanking.None, int pwmfreq = 100) { IO.Objects.libsimpleio.mikroBUS.Socket S = new IO.Objects.libsimpleio.mikroBUS.Socket(socket); // Configure RST pin myRSTgpio = new IO.Objects.libsimpleio.GPIO.Pin(S.RST, IO.Interfaces.GPIO.Direction.Output, true); // Configure PWM pin -- Prefer PWM over GPIO, if possible, and // assume full brightness until otherwise changed. myPWMgpio = null; myPWMout = null; if ((pwmfreq > 0) && (S.PWMOut.available)) { myPWMout = new IO.Objects.libsimpleio.PWM.Output(S.PWMOut, pwmfreq, 100.0); } else if (S.PWM.available) { myPWMgpio = new IO.Objects.libsimpleio.GPIO.Pin(S.PWM, IO.Interfaces.GPIO.Direction.Output, true); } // Configure 74HC595 shift register chain mychain = new SN74HC595.Device(new IO.Objects.libsimpleio.SPI.Device(S.SPIDev, IO.Devices.SN74HC595.Device.SPI_Mode, 8, IO.Devices.SN74HC595.Device.SPI_MaxFreq, S.CS.available ? new IO.Objects.libsimpleio.GPIO.Pin(S.CS, IO.Interfaces.GPIO.Direction.Output, true) : null), 2); mybase = radix; myblanking = blanking; Clear(); }
static void Main(string[] args) { Console.WriteLine("\nmikroBUS PWM Output Test\n"); // Get mikroBUS socket number Console.Write("Socket number? "); var num = int.Parse(Console.ReadLine()); Console.Write("PWM pulse frequency? "); var freq = int.Parse(Console.ReadLine()); // Create objects var socket = new IO.Remote.mikroBUS.Socket(num); var remdev = new IO.Remote.Device(); IO.Interfaces.PWM.Output outp = remdev.PWM_Create(socket.PWMOut, freq); // Sweep PWM output pulse width for (;;) { for (double d = 0; d <= 100; d++) { outp.dutycycle = d; System.Threading.Thread.Sleep(20); } for (double d = 100; d >= 0; d--) { outp.dutycycle = d; System.Threading.Thread.Sleep(20); } } }