Home Forums Programming Send button sign from arduino to pc via bluetooth

This topic contains 3 replies, has 3 voices, and was last updated by  Ches Lans 1 month, 1 week ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #6006

    Hi everyone, I have som trouble with Arduino code,

    I have multikeys 12 button which is connect to my Arduino on pin 2,3,4,5,6,7,8

    I need to send every button click (sign) from my Arduino to my PC via bluetooth module HC06

     

    keypad exempel

    Here is my code which i tried to use but it not working 🙁

    Is someone who can help my issue?

    #include <Keyboard.h>
    #include <Keypad.h>
    #include <SoftwareSerial.h>

    // Declaration of bluetooth RX and TX
    SoftwareSerial Bluetooth(9, 10);

    char button;

    //Declarera array
    const byte ROWS = 4; //four rows
    const byte COLS = 3; //three columns
    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 kpd
    byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the kpd

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

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

    }

    void loop() {
    // Fills kpd.key[ ] array with up-to 10 active keys.
    // Returns true if there are ANY active keys.
    if (kpd.getKeys())
    {
    for (int i = 0; i < LIST_MAX; i++) // Scan the whole key list.
    {
    if ( kpd.key[i].stateChanged ) // Only find keys that have changed state.
    {
    // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
    switch (kpd.key[i].kstate) {
    case PRESSED:

    //write keys via USB
    //Keyboard.write(kpd.key[i].kchar);

    //send button to bluetooth
    button = kpd.key[i].kchar;
    bluetoothFunc(button);

    break;
    }
    }
    }
    }
    } // End loop

    void bluetoothFunc(char button)
    {
    if (Bluetooth.available()) {
    Bluetooth.write(Keyboard.write(button));
    }
    }

     

     

     

     

    #6009

    here is my hardware

    hardware

    #6024

    Pankaj Verma
    Keymaster

    Hi George Kalandarishvili,

    I have identified the problem. In the function declaration,

    void bluetoothFunc(char button)
    {
    if (Bluetooth.available()) {
    Bluetooth.write(Keyboard.write(button));
    }
    }

    What you are doing here is wrong. You are sending button data if and only if there is bytes available on the Bluetooth. You just have to send the data, when button is pressed. Please try this code and it may work for you.

    void bluetoothFunc(char button)
    {
    Bluetooth.write(Keyboard.write(button));
    }

    #6584

    Ches Lans
    Participant

    Hi..according to me post a link to the shield. Typically, such shields use pins 0 and 1, 2 and 3, or 7 and 8, with some way to switch between pins 0 and 1 and the other pair. Also, when anything is connected to pins 0 and 1, you will have a hard time uploading sketches, because those pins are involved in uploading the sketch.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.