RF project video question

Hi guys,

in order to explain my question briefly;

i shoot a 1.5 minute video about it.

elements

transceiver side: arduino mega, transceiver, 12 buttons
receiver side: arduino mega,receiver, 8 leds.

and whole base is simulation of omni robot with 4 moves.

link:

here are the parts of the applied in the video:

receiver:

#include <VirtualWire.h> //RF Module library


char*mesaj;  // massage variable

void setup() {


  pinMode(3,OUTPUT);  //right
    pinMode(4,OUTPUT);//left
      pinMode(5,OUTPUT);  // forward
    pinMode(6,OUTPUT);//backward
    pinMode(7,OUTPUT);  //B Move
    pinMode(8,OUTPUT);// A Move
    pinMode(9,OUTPUT);  //C Move
    pinMode(10,OUTPUT);// D Move
     
 
Serial.begin(9600);

    vw_set_ptt_inverted(true);
    vw_set_rx_pin(22);  //RF receiver data pin
    vw_setup(4000);
    vw_rx_start();
}
 
void loop() {
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;
    if (vw_get_message(buf, &buflen)) 
    {

//NO MOVEMENT     
         if(buf[0]=='A'){ 
           Serial.println(buf[0]);
           
        digitalWrite(3,0);
        digitalWrite(4,0);
        digitalWrite(5,0);
        digitalWrite(6,0);
        digitalWrite(7,0);
         digitalWrite(8,0);
         digitalWrite(9,0);
         digitalWrite(10,0);
             digitalWrite(11,0);
              digitalWrite(12,0);
               digitalWrite(38,0);
           
      
         }

//FORWARD RİGHT
           if(buf[0]=='F'){ 
           Serial.println(buf[0]);
           
        digitalWrite(3,1);
        digitalWrite(5,1);
          
          
         }   

    




//FORWARD RIGHT- B MOVE
                 if(buf[0]=='S'){ 
           Serial.println(buf[0]);
               
                       digitalWrite(5,1);
              digitalWrite(3,1);
                 digitalWrite(7,1);
}

}
}

transceiver:

#include <VirtualWire.h> //RF Modüle library
char*mesaj; // massage variable

//int potpin = 2 ;  // analog pin used to connect the potentiometer
//int val;    // variable to read the value from the analog pin

 void setup() {
Serial.begin(9600);
   vw_set_ptt_inverted(true);
   vw_set_tx_pin(24); // RF Transceiver data pin
   vw_setup(4000);
  
   pinMode(3,INPUT); // RIGHT
   pinMode(4,INPUT);  // LEFT
   pinMode(5,INPUT);//  FORWARD
   pinMode(6,INPUT);//  BACKWARD
   pinMode(7,INPUT);//FORWARD LEFT
   pinMode(8,INPUT);//FORWARD RIGHT
   pinMode(9,INPUT);//BACKWARD RIGHT
   pinMode(10,INPUT);//BACKWARD LEFT
   pinMode(11,INPUT);//B MOVE
   pinMode(12,INPUT);//A MOVE
   pinMode(13,INPUT);// C MOVE
   pinMode(2,INPUT);//  D MOVE
     
}
 
void loop() {

  //FORWARD RIGHT- B MOVE
  if( digitalRead(7)==1 && digitalRead(11)==1){
     mesaj="S" ; 
}else{
      mesaj="A" ; 

// FORWARD-RIGHT
if(digitalRead(7)==1){
     mesaj="F" ; .
}else{
      mesaj="A" ; 

}
}

Serial.println(mesaj); //Oluşturduğumuz mesaj değişkenini serial ekranda yazdırdık.
   vw_send((uint8_t *)mesaj, strlen(mesaj)); //Mesaj değişkenini RF 433 ile alıcı modüle gönderiyoruz.
   vw_wait_tx();
   delay(100);

  }

i am sorry for not sharing for all the code due to the arduino character limitations.
but as you predict other pushing and blinking actions are written in the same way in this regular code.

as you see in the video when i push 2 buttons i get two leds into turn on position.
but when i hold my finger up from one button, the leds are still keep on blinking
until i take my second finger up from the button.

i know i should do something about the code.please help me.

Give the pins symbolic names.
You’ve been told this before.

İ have asked about those modules one year ago,but questions are totally different from each other fella..

So..

Can you figure out the problem?

mesaj="A" ; Why a string of one character?

Can you figure out the problem?

Can I be bothered to remember which pin does what? Probably not.

Good luck.

Do remember that the people on these forums whoes help you want are volunteers, if you make your code difficult to follow a lot of people wont bother to look at it.

When you define an LED output like this;

pinMode(3, OUTPUT); //right

If instead you do this;

#define rightLED 3
pinMode(rightLED, OUTPUT); //right

You can then do this in the code;

digitalWrite(rightLED, 1);

Which a lot easier to follow.

It might even help you when you come back to look at the code sometime later ........

//Transceiver code
#include <VirtualWire.h> //RF Modüle library
char*mesaj; // massage variable

//int potpin = 2 ;  // analog pin used to connect the potentiometer
//int val;    // variable to read the value from the analog pin

 void setup() {
Serial.begin(9600);
   vw_set_ptt_inverted(true);
   vw_set_tx_pin(24); // RF Transceiver data pin
   vw_setup(4000);
 
   pinMode(3,INPUT); // RIGHT
   pinMode(4,INPUT);  // LEFT
   pinMode(5,INPUT);//  FORWARD
   pinMode(6,INPUT);//  BACKWARD
   pinMode(7,INPUT);//FORWARD LEFT
   pinMode(8,INPUT);//FORWARD RIGHT
   pinMode(9,INPUT);//BACKWARD RIGHT
   pinMode(10,INPUT);//BACKWARD LEFT
   pinMode(11,INPUT);//B MOVE
   pinMode(12,INPUT);//A MOVE
   pinMode(13,INPUT);// C MOVE
   pinMode(2,INPUT);//  D MOVE
     
}
 
void loop() {

  //FORWARD RIGHT- B MOVE
  if( digitalRead(7)==1 && digitalRead(11)==1){
     mesaj="S" ;
}else{
      mesaj="A" ;
//Button 7= forward right
//Button 11= B MOVE

// FORWARD-RIGHT
if(digitalRead(7)==1){
     mesaj="F" ; .
}else{
      mesaj="A" ;
// Button 7= forward right
}
}

Serial.println(mesaj); 
   vw_send((uint8_t *)mesaj, strlen(mesaj)); //
   vw_wait_tx();
   delay(100);

  }

//Receiver;

#include <VirtualWire.h> //RF Module library

char*mesaj; // massage variable

void setup() {

pinMode(3,OUTPUT); //right
pinMode(4,OUTPUT);//left
pinMode(5,OUTPUT); // forward
pinMode(6,OUTPUT);//backward
pinMode(7,OUTPUT); //B Move
pinMode(8,OUTPUT);// A Move
pinMode(9,OUTPUT); //C Move
pinMode(10,OUTPUT);// D Move

Serial.begin(9600);

vw_set_ptt_inverted(true);
vw_set_rx_pin(22); //RF receiver data pin
vw_setup(4000);
vw_rx_start();
}

void loop() {
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen))
{

//NO MOVEMENT
if(buf[0]==‘A’){
Serial.println(buf[0]);

digitalWrite(3,0);//right
digitalWrite(4,0);
digitalWrite(5,0);//forward
digitalWrite(6,0);
digitalWrite(7,0);//b move
digitalWrite(8,0);
digitalWrite(9,0);
digitalWrite(10,0);
digitalWrite(11,0);
digitalWrite(12,0);
digitalWrite(38,0);

}

//FORWARD RİGHT
if(buf[0]==‘F’){
Serial.println(buf[0]);

digitalWrite(3,1);//Right
digitalWrite(5,1);//forward

}

//FORWARD RIGHT- B MOVE
if(buf[0]==‘S’){
Serial.println(buf[0]);

digitalWrite(5,1);//forward
digitalWrite(3,1);//right
digitalWrite(7,1);//B MOVE
}

}
}

[/code]

İ only add explanation to the applied leds and buttons on the system,now it is better i guess, but thanks i take that notes for the #define variable application.