// SimpleRx - the slave or the receiver #include #include #include #define CE_PIN 20 #define CSN_PIN 17 #define LM_PIN 14 #define RM_PIN 15 #define LED_PIN 0 const byte thisSlaveAddress[5] = {'R','x','A','A','A'}; RF24 radio(CE_PIN, CSN_PIN); char dataReceived = '0'; // this must match dataToSend in the TX bool newData = false; unsigned long currentMillis = 0; unsigned long prevMillis = 0; unsigned long txIntervalMillis = 1000; // send once per second const int HIGH_PULSE = 2000; const int LOW_PULSE = 1000; int PULSE = LOW_PULSE; const int PERIOD = 20000; //=========== void setup() { pinMode(LED_PIN, OUTPUT); Serial.begin(9600); if (!radio.begin()) { while (true) { Serial.println("FUCK"); } } Serial.println("SimpleRx Starting"); radio.setPALevel(RF24_PA_HIGH); radio.setDataRate( RF24_250KBPS ); // radio.setChannel(49); radio.enableAckPayload(); radio.openReadingPipe(1, thisSlaveAddress); radio.startListening(); pinMode(LM_PIN, OUTPUT); pinMode(RM_PIN, OUTPUT); } //============= int MIN_PULSE = 1300; int MAX_PULSE = 1400; void loop() { if (dataReceived == '1') { Serial.println("We have entered the 1 loop"); digitalWrite(LED_PIN, HIGH); digitalWrite(LM_PIN, HIGH); digitalWrite(RM_PIN, HIGH); delayMicroseconds(2000); digitalWrite(LM_PIN, LOW); digitalWrite(RM_PIN, LOW); delayMicroseconds(PERIOD - 2000); }; if (dataReceived == '0') { Serial.println("We have entered the 0 loop"); digitalWrite(LED_PIN, LOW); digitalWrite(LM_PIN, HIGH); digitalWrite(RM_PIN, HIGH); delayMicroseconds(1000); digitalWrite(LM_PIN, LOW); digitalWrite(RM_PIN, LOW); delayMicroseconds(PERIOD - 1000); }; if (dataReceived == 'l') { Serial.println("We have entered the l loop"); digitalWrite(LED_PIN, HIGH); digitalWrite(LM_PIN, HIGH); digitalWrite(RM_PIN, HIGH); delayMicroseconds(MIN_PULSE); digitalWrite(LM_PIN, LOW); delayMicroseconds(MAX_PULSE - MIN_PULSE); digitalWrite(RM_PIN, LOW); delayMicroseconds(PERIOD - MAX_PULSE); }; if (dataReceived == 'r') { Serial.println("We have entered the r loop"); digitalWrite(LED_PIN, HIGH); digitalWrite(LM_PIN, HIGH); digitalWrite(RM_PIN, HIGH); delayMicroseconds(MIN_PULSE); digitalWrite(RM_PIN, LOW); delayMicroseconds(MAX_PULSE - MIN_PULSE); digitalWrite(LM_PIN, LOW); delayMicroseconds(PERIOD - MAX_PULSE); }; if (dataReceived == 'u') { Serial.println("We have entered the u loop"); digitalWrite(LED_PIN, HIGH); digitalWrite(LM_PIN, HIGH); digitalWrite(RM_PIN, HIGH); delayMicroseconds(MIN_PULSE); digitalWrite(LM_PIN, LOW); digitalWrite(RM_PIN, LOW); delayMicroseconds(PERIOD - MIN_PULSE); }; getData(); showData(); currentMillis = millis(); if (currentMillis - prevMillis >= txIntervalMillis) { Serial.println("A second has passed"); prevMillis = millis(); }; } //============== void getData() { if (radio.available()) { Serial.println("New data is available"); char temp; // Temporary variable to store the incoming data radio.read(&temp, sizeof(temp)); // Read the data into temp // Check if the temp data is one of the specified characters if (temp == '0' || temp == '1' || temp == 'u' || temp == 'l' || temp == 'r') { dataReceived = temp; // Update dataReceived only if temp is valid newData = true; } } } void showData() { if (newData == true) { Serial.print("Data received "); Serial.println(dataReceived); newData = false; }; }