Dual DC motor controller with Arduino (part 2)

Now with wireless control using 433MHz frequency. Code uses RadioHead-library.

Transmitter Arduino code:

#include <RH_ASK.h>
#include <SPI.h> // Not actualy used but needed to compile

RH_ASK driver(2000, 2, A5, 4);

byte old_mot_1;
byte old_mot_2;

void setup() {
  driver.init();
}

void loop() {
  int pot_1 = analogRead(1); // potentiometers values
  int pot_2 = analogRead(0);

  byte mot_1 = map(pot_1, 0, 1023, 0, 255);
  byte mot_2 = map(pot_2, 0, 1023, 0, 255);

  byte msg[3];
  msg[0] = mot_1;
  msg[1] = mot_2;
  driver.send(msg, 3);
  driver.waitPacketSent();
  delay(200);
}

Receiver Arduino code:

#include <RH_ASK.h>
#include <SPI.h> // Not actualy used but needed to compile

RH_ASK driver(2000, 13, 2, 4);

int pot_1 = 128;
int pot_2 = 128;

void setup() {
  driver.init();
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
}

void loop() {
  byte buf[3];
  if (driver.recv(buf, 3)) { // Non-blocking
    pot_1 = buf[0]; // potentiometers values
    pot_2 = buf[1];
  }

// MOTOR ONE
  // direction backward
  if(pot_1 < 128-10) {
    digitalWrite(7,0); // motor direction
    int mot_1 = map(pot_1, 0, 128-10, 255, 0);
    analogWrite(3,mot_1);
  }
  // stop motor in middle position
  else if((pot_1 > 128-9) && (pot_1 < 128+9)) {
    digitalWrite(7,0); // motor direction
    analogWrite(3,0); // motor speed
  }
  // direction forward
  else if(pot_1 > 128+10) {
    digitalWrite(7,1); // motor direction
    int mot_1 = map(pot_1, 128+10, 255, 255, 0);
    analogWrite(3,mot_1);
  }

// MOTOR TWO
  // direction backward
  if(pot_2 < 128-10) {
    digitalWrite(8,0); // motor direction
    int mot_2 = map(pot_2, 0, 128-10, 255, 0);
    analogWrite(11,mot_2);
  }
  // stop motor in middle position
  else if((pot_2 > 128-9) && (pot_2 < 128+9)) {
    digitalWrite(8,0); // motor direction
    analogWrite(11,0); // motor speed
  }
  // direction forward
  else if(pot_2 > 128+10) {
    digitalWrite(8,1); // motor direction
    int mot_2 = map(pot_2, 128+10, 255, 255, 0);
    analogWrite(11,mot_2);
  }
}