Make a reverse PWM to a normal PWM

Hi guys. I'm using a MOSFET to drive a motor. To control the MOSFET I'm using a 2.4Ghz R/C transmitter and receiver. I don't want the motor to go in reverse but there is no setting on the transmitter. I want to feed in the output from the receiver (-255 to 255) to an Arduino and have the Arduino give a 0 to 255 PWM out. I have no idea where to start on the code. Thanks.

Would the map() function do what you want?

y = map(x, -255, 255, 0, 255);

I think it might but I've never used it before. Would you mind putting it in something I could quickly upload? I want the input from the receiver to be pin 6 and the output to the MOSFET to be pin 9. Thanks again.

this is what I have but it doesn't seem to do anything

void setup() {}

void loop() { int val = digitalRead(6); val = map(val, -255, 255, 0, 255); digitalWrite(9, val); }

if I connect pin 6 to ground or 5v it doesn't change pin 9

val is either one or zero. What do they map to?

So you have a RC receiver servo signal connected to pin 6? Would you draw a schematic or block diagram of your setup? Hand drawn and photographed and posted is fine.

The servo works fine connected to the receiver alone, that can be left out of the equation. It's the MOSFET motor controller that's giving me trouble. I'm making a fritzing now.

CraftKing7777:
The servo works fine connected to the receiver alone,

You did not read Reply #5 carefully. He did not ask if you have a servo connected to pin 6.

Make life easy for everyone. Post your complete existing program. Also post the diagram that was requested in Reply #5.

…R

For some reason, my fritzing kept crashing so I made a circuits.io The three wires towards the bottom right are the receiver. White: PWM, Red: 5v, Black: GND https://circuits.io/circuits/2586829-the-unnamed-circuit/

So you are feeding a servo SIGNAL to pin 6? If not, kindly tell us what the receiver is. A servo signal is a pulse 1000 to 2000 microseconds every 20ms. The 1000 - 2000 microsecond sets the servo position (0 - 180). It is not a digitalRead or analogRead compatible signal. You can use pulseIn() to read the width of the servo signal and then map that number (1000 - 2000) to the PWM (0 -255) output.

void setup() {
pinMode (9, OUTPUT);   <<< need this to start
Serial.begin(9600);    <<< add some debugging help
}

void loop()
{
  int val = digitalRead(6);  <<< val can only be 0, 1
  val = map(val, -255, 255, 0, 255);  <<< what does this create?
Serial.println (val);  <<< find out
 digitalWrite(9, val);  <<< this can only set the pin HIGH or LOW
}

Are you attempting to read an analog level and convert it to a PWM output for the motor?
Is that where the -255 to 255 comes from? Or is that a 2-byte (signed int) number that you are trying to read?
PWM out to the motor would use analogWrite, not digitalWrite.

(posted without seeing the picture yet)