So the serial doesnt print. thats it, the motor changes speeds and all but it just doesnt print in the serial monitor.
Receiver code:
#include <SPI.h>
#include <RF24.h>
#include <Wire.h>
#include <Adafruit_MotorShield.h>
RF24 radio(9, 10); // CE, CSN pins
const byte address[6] = "00069";
Adafruit_MotorShield AFMS = Adafruit_MotorShield(); // Create an instance of the Adafruit Motor Shield library
Adafruit_DCMotor motor1 = AFMS.getMotor(1); // Assign the motor objects
Adafruit_DCMotormotor2 = AFMS.getMotor(2);
void setup()
{
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(1, address);
radio.setPALevel(RF24_PA_LOW);
radio.startListening();
AFMS.begin(); // Initialize the Adafruit Motor Shield
}
void loop()
{
if (radio.available())
{
char receivedMessage[12] = ""; // Array to store the received message
radio.read(&receivedMessage, sizeof(receivedMessage));
if (strcmp(receivedMessage, "MOTOR1_ON") == 0)
{
Serial.println("Received: MOTOR1_ON");
motor1->setSpeed(255); // Set the speed of motor 1 to maximum
motor1->run(FORWARD); // Set the motor 1 direction
}
else if (strcmp(receivedMessage, "MOTOR1_OFF") == 0)
{
Serial.println("Received: MOTOR1_OFF");
motor1->setSpeed(0); // Set the speed of motor 1 to 0 (stop)
motor1->run(RELEASE); // Release motor 1
}
else if (strcmp(receivedMessage, "MOTOR2_ON") == 0)
{
Serial.println("Received: MOTOR2_ON");
motor2->setSpeed(255); // Set the speed of motor 2 to maximum
motor2->run(FORWARD); // Set the motor 2 direction
}
else if (strcmp(receivedMessage, "MOTOR2_OFF") == 0)
{
Serial.println("Received: MOTOR2_OFF");
motor2->setSpeed(0); // Set the speed of motor 2 to 0 (stop)
motor2->run(RELEASE); // Release motor 2
}
}
}