Im looking at the wiring_analog.c file and I noticed that if val == 0 it outputs LOW as a digital signal and if val == 255 the output is digital HIGH. I see that if val is not 0 or 255, it goes to the timer. Usually we need to map the input signal to 0 and 255 because you get weird data if the input is less than or greater than 0 and 255.
Why not make set a limit in the wiring_analog.c file, instead of val == 0 (LOW) or val == 255 (HIGH), make it val <= 0 (LOW) and val >= 255 (HIGH).
My reason I noticed that when I mapped my data, I still for some reason got out numbers greater and less than what I wanted to get.
Example, controlling two independent motors from one value ranging -255 and 255, negative number would represent reverse and likewise for positive.
So I did,
DRVFor = map(Drive, 0,255,0, 255); // not really needed
DRVRev = map(Drive, -255,0,0,255);
MotorFor = analogWrite(9, DRVFor);
MotorRev = analogWrite(6, DRVRev);
But when the I did a print out of the Motor1 & 2, this is what I noticed. When Drive was less than 0, MotorFor was a negative number and when Drive was greater than 0, MotorRev was negative. Why is that?
So this was when I checked the analog Read/Write file.
In the end, I changed my code and used an IF/ELSE statement, but it’s still weird to see that if a number is negative (and mapped that way), the results will be wrong. I was looking to get 0 when Drive was negative for DRVFor, but nope.
Again, it’s just a suggestion.