Nrf_problem_button_and_led

hey, can smbd suggest how to operate whith simple button and led??
idea such I have button on sender uno and led on receiving, how to make such way that i press button once and led switches on and when i press another button, the led switches off?

here I tried this, but in serial i can receive nothing

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

RF24 radio(9, 10); // Пины CE, CSN

const byte address[6] = "00001"; // Адрес канала
int a;
void setup() {
  pinMode(2, OUTPUT);
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MIN);
  radio.startListening();
}

void loop() {
  if (radio.available()) {
    char command[6];
    radio.read(command, sizeof(command)); // Чтение команды
    command[5] = '\0'; // Добавление нулевого символа для преобразования в строку

    if (strcmp(command, "aa") == 0) {
      Serial.println("1"); // Включение светодиода
    } else if (strcmp(command, "bb") == 0) {
      Serial.println("0"); // Выключение светодиода
    }
  }
if (Serial.available()>0){
  int kk = Serial.parseInt();
  if(kk == 1){
    a = 1;
  }
  if(kk == 0){
    a = 0;
  }
}
switch(a){
  case (1):
  digitalWrite(2, HIGH);
  break;
  case (0):
  digitalWrite(2, LOW);
  break;
}
}

pls smbd help find out what's the deal))))))))))))))))
PS this is a receiver code only, on transmitter I checked all works, but when I played whith code it stopped receive even 1 and 0.

If the first statement really terminates the string, the comparisons can never be true,
because they have different lengths.

But this is only guesswork, as I can not see the transmitter code.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.