// SimpleTx - the master or the transmitter #include #include #include #define CE_PIN 20 #define CSN_PIN 17 const byte slaveAddress[5] = {'R','x','A','A','A'}; RF24 radio(CE_PIN, CSN_PIN); // Create a Radio char command = '0'; unsigned long currentMillis; unsigned long prevMillis; unsigned long txIntervalMillis = 1000; // send once per second void setup() { Serial.begin(9600); Serial.println("SimpleTx Starting"); if (!radio.begin()) { while (true) { Serial.println("FUCK"); } } radio.setPALevel(RF24_PA_HIGH); radio.setDataRate( RF24_250KBPS ); radio.setRetries(3,5); // delay, count radio.enableAckPayload(); // radio.setChannel(49); radio.openWritingPipe(slaveAddress); radio.stopListening(); } //==================== void loop() { currentMillis = millis(); if (currentMillis - prevMillis >= txIntervalMillis) { send(); prevMillis = millis(); } } //==================== void send() { bool rslt; if (Serial.available() > 0) { char command = Serial.read(); // Read a character from the Serial Monitor // Send the command wirelessly using your module rslt = radio.write( &command, sizeof(command) ); // Always use sizeof() as it gives the size as the number of bytes. // For example if dataToSend was an int sizeof() would correctly return 2 Serial.print("Data Sent "); Serial.print(command); if (rslt) { Serial.println("Acknowledge received"); } else { Serial.println("Tx failed"); } } }