Motor/GPIO (Simulating Motor With LEDs)#

Meetings/News#

Goal#

Create a Motor implementation, MotorLED, that does not rreally drive a motor. Rather it uses two LEDs - forward and backward - that are used as indicators for the motor driving direction. Both off means “motor idle”. The LEDs are driven using libgpiod.

How#

class MotorLED : public Motor
{
public:
    MotorLED(const std::string& gpiodevice, int line_number_forward, int line_number_backward);
    ...
};
  • gpiodevice is for example /dev/gpiochip0

  • line_number_forward and line_number_backward are the numbers of the respective GPIO line (see for example the Raspberry Pi pinout diagram)

Use the libgpiod library to implement the forward(), backward(), and stop() methods.

Testing#

Real hardware cannot be tested using unit tests (at least not easily). Write a test program (in tests/) that uses MotorLED to manipulate the LED states.