I didn't say the Map function could not use negative numbers. I said the AnalogWrite (and motor control Enable pins that accept PWM)
do not take negative numbers. .If you want the motor to turn the opposite direction you need to change the state of the direction pin. .You did not post your entire code so we don't know what "pwm_M1" mean other than what the name says it means, which is a PWM input to a motor control that only accepts PWM. We don't know what you are doing with this pwm_M1 AFTER the Map function because you didn't post your entire code. We can only assume that you are using it as the argument for an analogWrite statement, because there is no other way to get a PWM signal (short of bit banging) from the arduino to a motor control. If you post your ENTIRE code then maybe we can figure out what is going wrong. I am simply saying that although the Map function has no problem at all with negative numbers, they are not valid for analogWrite statements. (which of course, without your code, we don't know if that is what you are using the pwm_M1 for).
(which is another way of saying there is no such thing as a negative TTL PWM signal.)
I just saw this , which confirms the above:
// SEND PULSE TO ENABLE PIN IN A L293B
analogWrite(pinpwm_M1,abs(pwm_M1))
Example
/* Map an analog value to 8 bits (0 to 255) */
void setup() {}void loop()
{
int val = analogRead(0);
val = map(val, 0, 1023, 0, 255);
analogWrite(9, val);
}
Do you see any negative values for the analogWrite() statement ?