tylersweat / arduino-L293D

Arduino library for using a L293D motor controller chip
MIT License
16 stars 11 forks source link

negative analogWrite #2

Closed karmanyaahm closed 3 years ago

karmanyaahm commented 3 years ago

Hello, thanks for this great library. I'm running into a bug which can be fixed by multiplying the value by -1 in analogWrite because that only takes in positive numbers.

https://github.com/tylersweat/arduino-L293D/blob/6bf7a332ce09c47fe336a840ead7fe05c268bf42/L293D.cpp#L55-L59

tylersweat commented 3 years ago

Can you provide more details on what is causing the bug and how multiplying by negative one helps? Once I know what the underlying issue is I can fix it or you can for the repo and fix it then send a pull request

karmanyaahm commented 3 years ago

The Arduino documentation here says

value: the duty cycle: between 0 (always off) and 255 (always on). Allowed data types: int.

When I input something like -0.33 into the motor control the PWM voltage I get out is ~3.5volts when it should be 1.66V because as far as I can tell the underlying implementation assumes it's an unsigned int and processes it accordingly.