A simple arduino program

Hi , I have 1 receiver (( my receiver is a 5v Arduino PRO MICRO )) box and 2 transfer box

Transfer 1 has 2 bottom , bottom 1 and bottom 2

If I push bottom 1 it transfer it to receiver box and receiver gets that and send order to windows to press F1 bottom on keyboard ( I use keyboard library )

And , If I push bottom 2 it transfer it to receiver box and receiver gets that and send order to windows to press F2 bottom on keyboard

Transfer 2 has 2 bottom , bottom 3 and bottom 4

And it is the same as transfer box 1 but uses** **F6 and F7 Bottom
it works great

What I need is when I push bottom 1 , a simple 3v LED light gets ON too (( on the transfer Box1 and on the receiver Boxin same time )) and when I release the bottom it gets OFF

Just that
if only the receiver Box LED works is enough

I send the codes for receiver BOX and Transfer box 1 for u

Thanks you

.......................................................................
Receiver Box code
......................................

#include <Keyboard.h>
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
RF24 radio(7,8);
RF24Network network(radio);
const uint16_t this_node = 00;
const uint16_t other_node = 01;

unsigned int laser_state=0;
const unsigned long my_interval = 500;
unsigned long last_sent;
unsigned int income=0;


void setup(void)
{
  Serial.begin(115200);
  pinMode(9,INPUT_PULLUP);
  SPI.begin();
  radio.begin();
  network.begin(90,this_node);
}


void loop(void){
  
  network.update();
  
  if ( network.available() ) {
    RF24NetworkHeader header;
    network.read(header,&income,sizeof(income));
    if(income==1){
      Serial.println('a');
      Keyboard.press(KEY_F1);
      income=0;
    }
    if(income==2){
      Serial.println('b');
      Keyboard.press(KEY_F2);
      income=0;
    }
    if(income==3){
      Serial.println('c');
      Keyboard.press(KEY_F6);
      income=0;
    }
    if(income==4){
      Serial.println('d');
      Keyboard.press(KEY_F7);
      income=0;
    }
    Keyboard.releaseAll();
  }

  unsigned long now = millis();
  if ( now - last_sent >= my_interval  )
  {
//    Serial.print("pin ");
//    Serial.println(digitalRead(9));
    last_sent = now;
    laser_state = digitalRead(9);
    RF24NetworkHeader header(other_node);
    bool ok = network.write(header,&laser_state,sizeof(laser_state));
  }
}

...............................................................................................................
Transfer 1 Box code
....................................

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



RF24 radio(8,7);
RF24Network network(radio);
const uint16_t this_node = 03;
const uint16_t other_node = 00;

unsigned int laser_state=0;
const unsigned long interval = 50;
unsigned long last_sent;

unsigned int b1=1;
unsigned int b2=1;

unsigned int d1=1;
unsigned int d2=2;



void setup(void)
{
//  Serial.begin(9600);
  pinMode(6,INPUT_PULLUP);
  pinMode(10,INPUT_PULLUP);
  SPI.begin();
  radio.begin();
  network.begin(90,this_node);
}


void loop(void){
  
  network.update();

  unsigned long now = millis();
  if ( now - last_sent >= interval  )
  {
    last_sent = now;
    b1 = digitalRead(6);
    b2 = digitalRead(10);
    if(b1==1){
//      Serial.println("b1 is on");
      RF24NetworkHeader header(other_node);
      bool ok = network.write(header,&d1,sizeof(d1));
    }
    if(b2==0){
//      Serial.println("b2 is on");
      RF24NetworkHeader header(other_node);
      bool ok = network.write(header,&d2,sizeof(d2));
    }
  }
}

please read forum rules and use code tags (and indent your code)

1 Like

its ok now ?

i cant upload codes becuz i am new

no

please edit your post, select the code part and press the </> icon in the tool bar to mark it as code. (also make sure you indented the code in the IDE before copying, that's done by pressing ctrlT on a PC or cmdT on a Mac)

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)

Like this ?

yeah , i am the same idiot

pouvez vous m'aider s'il vous plaît

TOPIC MERGED.

Could you take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum.

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