Ist zwar Geschmackssache, aber statt struct würde ich C++Vererbung empfehlen. Beispiel:
Code:#include <AFMotor.h> class myMotor : public AF_DCMotor { public: uint8_t enc_pin; volatile uint32_t ticks = 0; uint32_t start_time = 0; uint32_t stop_time = 0; myMotor(uint8_t motornum, uint8_t enc_pin) : AF_DCMotor(motornum) { this->enc_pin = enc_pin; } }; enum motoren_e { M_VL, M_HL, M_VR, M_HR, M_MAX }; myMotor motor[4] { myMotor(1,18) , // M_VL myMotor(2,19) , // M_HL myMotor(3,20) , // M_VR myMotor(4,21) // M_HR }; void setup() { motor[M_VL].ticks = 55; } void loop() { motor[M_VL].setSpeed(127); motor[M_VL].run(FORWARD); }







Zitieren

Lesezeichen