Help with map function and pulseIn for a DC motor

I am trying to use PulseIn to read a PPM signal from an RC receiver and then turn it into something useful for a motor driver board. Im not advanced enough yet for interrupts, but I am trying to learn that for the future.

My motor keeps spinning ever so slightly like there is still some signal getting to it.
The serial window shows “ch4” at 1435 when the stick is not moving but “left” fluctuates from 2-20.


ch4 = pulseIn(3, HIGH);
if (ch4 < 1480 && ch4 > 1400)     // creates a deadband to stop the motor from 
{                                 //constantly turning
 ch4 = 1435;

left = map(ch4,1150,1726, -500, 500); //center over zero
left = constrain(left, -255, 255); //only pass values whose absolutes are
                                   //valid pwm values


1438 would be the mid point between 1150 and 1726, not 1435.

Secondly, if you are fixing a “dead band”, it would be better to do it after your map/constrain operations.

if ( abs( left ) <= 10 ) {  //  small +/- value of left forced to zero
  left = 0 ;

6v6gt, Thanks for your help. When using PulseIn, I've noticed there isn't a fixed high or low value from the Receiver. 1150 and 1726 are very, very close to the high and low range.

I will definitely give your code a try. Thanks!