Keypad Aynı Anda Birden fazla Buton Okuma
  • void CheckAllButtons(void) {
    char key = buttbx.getKey(); if (key == 'a') {
    Keyboard.write(key);
    digitalWrite(ledpinA4, !digitalRead(ledpinA4));
    delay(500);
    Keyboard.releaseAll();;

    }

    if (key == 'b') {
    Keyboard.write(key);

    delay(150);
    Keyboard.releaseAll();;

    }
    Yukardaki kod yazılan kodun bir kısmı. Toplamda 25 tane if ve buna bağlı 30 buton var. Sorun şu bir buton aktifken mesela a butonuna basılıyken diğer butonları okumuyor. Aynı anda keypadda bastıgım butonları nasıl okuturum. Programın tamamı aşagıya yazayim.
    -------------------------------------------------------------
    #include < Keypad.h>
    #include < Keyboard.h>

    #define NUMROTARIES 2
    #define NUMROWS 5
    #define NUMCOLS 5

    char buttons[NUMROWS][NUMCOLS] = {
    {'a','b','c','d'},
    {'e','f','g','h'},
    {'i','j','k','l'},
    {'m','n','o','p'},
    {'q','r','s','t'}
    };
    struct rotariesdef {
    byte pin1;
    byte pin2;
    int ccwchar;
    int cwchar;
    volatile unsigned char state;
    };

    rotariesdef rotaries[NUMROTARIES] {
    {0,1,'u','v',},
    {2,3,'w','x',},
    };

    #define ledpinA4 A4
    #define ledpinA0 A0
    #define ledpinA1 A1
    #define ledpinA2 A2
    #define ledpinA3 A3
    #define DIR_CCW 0x10
    #define DIR_CW 0x20
    #define R_START 0x0
    #define R_CW_FINAL 0x1
    #define R_CW_BEGIN 0x2
    #define R_CW_NEXT 0x3
    #define R_CCW_BEGIN 0x4
    #define R_CCW_FINAL 0x5
    #define R_CCW_NEXT 0x6
    boolean ledA0_state;
    boolean ledA1_state;
    boolean ledA2_state;
    boolean ledA3_state;
    boolean ledA7_state;
    boolean ledA4_state;
    unsigned long loopCount;
    unsigned long startTime;
    String msg;
    const unsigned char ttable[7][4] = {
    // R_START
    {R_START, R_CW_BEGIN, R_CCW_BEGIN, R_START},
    // R_CW_FINAL
    {R_CW_NEXT, R_START, R_CW_FINAL, R_START | DIR_CW},
    // R_CW_BEGIN
    {R_CW_NEXT, R_CW_BEGIN, R_START, R_START},
    // R_CW_NEXT
    {R_CW_NEXT, R_CW_BEGIN, R_CW_FINAL, R_START},
    // R_CCW_BEGIN
    {R_CCW_NEXT, R_START, R_CCW_BEGIN, R_START},
    // R_CCW_FINAL
    {R_CCW_NEXT, R_CCW_FINAL, R_START, R_START | DIR_CCW},
    // R_CCW_NEXT
    {R_CCW_NEXT, R_CCW_FINAL, R_CCW_BEGIN, R_START},
    };
    byte rowPins[NUMROWS] = {4,5,6,7,8,}; //connect to the row pinouts of the keypad
    byte colPins[NUMCOLS] = {9,10,11,12,}; //connect to the column pinouts of the keypad
    Keypad buttbx = Keypad( makeKeymap(buttons), rowPins, colPins, NUMROWS, NUMCOLS);
    void setup() {
    Serial.begin(9600);
    loopCount = 0;
    startTime = millis();
    msg = "";


    pinMode(ledpinA1,OUTPUT);
    pinMode(ledpinA0,OUTPUT);
    pinMode(ledpinA2,OUTPUT);
    pinMode(ledpinA3,OUTPUT);
    pinMode(ledpinA4,OUTPUT);
    delay(100);
    digitalWrite(ledpinA3,HIGH);
    digitalWrite(ledpinA0,HIGH);
    digitalWrite(ledpinA2,HIGH);
    digitalWrite(ledpinA1,HIGH);
    digitalWrite(ledpinA4,HIGH);

    }
    void loop() {
    CheckAllEncoders();
    CheckAllButtons();
    }
    void CheckAllButtons(void) {
    char key = buttbx.getKey();

    if (key == 'a') {
    Keyboard.write(key);
    digitalWrite(ledpinA4, !digitalRead(ledpinA4));
    delay(500);
    Keyboard.releaseAll();;

    }

    if (key == 'b') {
    Keyboard.write(key);

    delay(150);
    Keyboard.releaseAll();;

    }
    if (key == 'c') {
    Keyboard.write(key);
    delay(150);
    Keyboard.releaseAll();;

    }
    if (key == 'd') {
    Keyboard.releaseAll();;

    delay(150);
    Keyboard.release(key);

    }
    if (key == 'e') {
    Keyboard.write(key);

    delay(150);
    Keyboard.releaseAll();;

    }
    if (key == 'f') {
    Keyboard.write(key);

    delay(150);
    Keyboard.releaseAll();;


    }
    if (key == 'g') {
    Keyboard.write(key);
    digitalWrite(ledpinA2,LOW);
    delay(150);
    Keyboard.release(key);
    digitalWrite(ledpinA2,HIGH);
    }
    if (key == 'o') {
    Keyboard.write(key);
    digitalWrite(ledpinA1,LOW);
    delay(150);
    digitalWrite(ledpinA1,HIGH);
    Keyboard.release(key);

    }
    if (key == 'p') {
    Keyboard.write(key);
    digitalWrite(ledpinA1,LOW);
    delay(150);
    digitalWrite(ledpinA1,HIGH);
    Keyboard.release(key);

    }

    if (key == 'q') {
    Keyboard.write(key);
    delay(150);
    Keyboard.release(key);

    }
    if (key == 't') {
    Keyboard.write(key);
    digitalWrite(ledpinA2,LOW);
    delay(150);
    Keyboard.release(key);
    digitalWrite(ledpinA2,HIGH);
    }

    }
    void rotary_init() {
    for (int i=0;i pinMode(rotaries[i].pin1, INPUT);
    pinMode(rotaries[i].pin2, INPUT);
    #ifdef ENABLE_PULLUPS
    digitalWrite(rotaries[i].pin1, HIGH);
    digitalWrite(rotaries[i].pin2, HIGH);
    #endif
    }
    }

    unsigned char rotary_process(int _i) {
    unsigned char pinstate = (digitalRead(rotaries[_i].pin2) << 1) | digitalRead(rotaries[_i].pin1);<br /> rotaries[_i].state = ttable[rotaries[_i].state & 0xf][pinstate];
    return (rotaries[_i].state & 0x30);
    }
    void CheckAllEncoders(void) {
    for (int i=0;i unsigned char result = rotary_process(i);
    if (result) {
    Keyboard.write(result == DIR_CCW ? rotaries[i].ccwchar : rotaries[i].cwchar );
    if(rotaries[i].ccwchar == 'u'){ // blink led from any rotation
    digitalWrite(ledpinA0,LOW);
    delay(50);
    digitalWrite(ledpinA0,HIGH);
    delay(50);
    }
    if(rotaries[i].ccwchar == 'w'){
    digitalWrite(ledpinA0,LOW);
    delay(50);
    digitalWrite(ledpinA0,HIGH);
    delay(50);
    }
    }
    }
    }

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Login with Facebook
Açık kaynak kültürü gereği, çözdüğünüz problemlerin çözümlerini paylaşmayı lütfen unutmayın.