Arduino serial communication HELP

Machan mata podi help ekak oona.. mata karanna oona..
1- keypad ekak thiyenawa (4x3).. eeka arduino ekata connect karala thiyenne..
2- key ekak press karama serial buffer ekata ya na oona eeka..
3- serial read karama eeka ganna puluwn wenna oona iita passe...

Mama kare.. key eka press karama.. e press karana key eka serial.write(key) karamawa iita passe, serial.available() check karala, Serial.read() walin aragena eka '1' kiyala (hari wena mkakhri character ekakata) check karala if function eken ithuru tika wenna..
E unata ee labba hariyanne na bn.. mokakd magulak enawa bn..
Poddak kiyala dipanko karana widiya..
 
Code:
 #include <Keypad.h>

const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'#','0','*'}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(){
  Serial.begin(9600);
}

void loop(){
  char key = keypad.getKey();

  if (key){
    Serial.write(key);
  }

if(Serial.available() > 0){
Char rec=Serial.read();

if(rec=='1'){
digitalWrite(10,HIGH); //led light up
}else{
digitalWrite(10,LOW);
}
}


}

SKU088310j.JPG



Mee code eka wada krnne na.. mata oona de wenne na..
 

madhawas1

Active member
  • Jul 5, 2015
    542
    249
    43
    මචන් keypad to Arduino connection එක හරි නේද? code එකේ නම් awlak penna ne.
     

    _A_I_I_

    Member
    Feb 22, 2014
    8
    3
    3
    මේකේ arduino එක මොකටවත් connect කරලා නෑ නේද. එහෙමනම් serial.write කරලා ඒක serial.read කලාට හරියන්නේ නෑ. serial.write එකෙන් TX buffer එකට write වෙන්නේ. serial.read() එකෙන් RX buffer එකෙන් read වෙන්නේ. මට පේන විදිහට Serial එක ඕනේ නෑ. key එක read කරන char එක use කලාම ඇති.
    Code:
    #include <Keypad.h>
    
    const byte ROWS = 4;
    const byte COLS = 3;
    char keys[ROWS][COLS] = {
      {'1','2','3'},
      {'4','5','6'},
      {'7','8','9'},
      {'#','0','*'}
    };
    byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
    byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad
    
    Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
    
    void setup(){
      
    }
    
    void loop(){
      char key = keypad.getKey();
    
      if(key){
         if(key=='1'){
             digitalWrite(10,HIGH); //led light up
         }else{
             digitalWrite(10,LOW);
         }
      }
    }
     
    මේකේ arduino එක මොකටවත් connect කරලා නෑ නේද. එහෙමනම් serial.write කරලා ඒක serial.read කලාට හරියන්නේ නෑ. serial.write එකෙන් TX buffer එකට write වෙන්නේ. serial.read() එකෙන් RX buffer එකෙන් read වෙන්නේ. මට පේන විදිහට Serial එක ඕනේ නෑ. key එක read කරන char එක use කලාම ඇති.
    Code:
    #include <Keypad.h>
    
    const byte ROWS = 4;
    const byte COLS = 3;
    char keys[ROWS][COLS] = {
      {'1','2','3'},
      {'4','5','6'},
      {'7','8','9'},
      {'#','0','*'}
    };
    byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
    byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad
    
    Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
    
    void setup(){
      
    }
    
    void loop(){
      char key = keypad.getKey();
    
      if(key){
         if(key=='1'){
             digitalWrite(10,HIGH); //led light up
         }else{
             digitalWrite(10,LOW);
         }
      }
    }

    Ow ehemath puluwn.. e unata mata oona serial communication eka haraha yanna ban.. Rx eke buffer ekata send karanna barida bn ithin? Widiyak nadda?