#2 Апаратні питання » Клавиатура на arduino » 2018-08-06 22:55:56

flying
відповідей: 2

Приветствую.
Имеется следующая проблема, плата lattepanda с leonardo на борту, написал программу для клавиатуры 8х8 . После загрузки работает отлично, но после перезагрузки уже не работает нужно снова загружать в контроллер. Код ниже. Может кто знает как вылечить?


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

const byte ROWS = 8; //число строк

const byte COLS = 8; //число столбцов 

char hexaKeys[ROWS][COLS] = {

{'1','2','3','4','5','6','7','8'},

{'9','0','a','b','c','d','e','f'},

{'g','h','i','j','k','l','m','n'},

{'o','p','q','r','s','t','u','v'},

{'w','x','y','z','A','B','C','D'},

{'E','F','G','H','I','J','K','L'},

{'M','N','O','P','Q','R','S','T'},

{'U','V','W','X','Y','Z','#','@'},

};

byte rowPins[ROWS] = {2, 3, 4, 5, 6, 18, 19, 20}; 

byte colPins[COLS] = {9, 10, 11, 12, 13, 21, 22, 23}; 

//initialize an instance of class NewKeypad

Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

void setup(){

Serial.begin(9600);
pinMode(7, INPUT_PULLUP);
Keyboard.begin();


}

void loop(){

    /*  
char customKey = customKeypad.getKey();
if (customKey){
Serial.println(customKey);
}
  */
if ( !digitalRead(7) )
 {
    doAction();
 }


}
void doAction()
{
  char customKey = customKeypad.getKey();

 if  ((customKey)=='D')
  {
     Keyboard.press('1');
     delay(100);
     Keyboard.release('1');    
  }
  
//if  (customKeypad.getKey()=='C')
 if  ((customKey)=='C')
  {
     Keyboard.press('2');
     delay(100);
     Keyboard.release('2');    
  }

//if  (customKeypad.getKey()=='B')
 if  ((customKey)=='B')
  {
     Keyboard.press('3');
     delay(100);
     Keyboard.release('3');    
  }

if  ((customKey)=='z')
  {
     Keyboard.press('0');
     delay(100);
     Keyboard.release('0');    
  }
  
if  ((customKey)=='L')
  {
     Keyboard.press('4');
     delay(100);
     Keyboard.release('4');    
  }
  
  if  ((customKey)=='K')
  {
     Keyboard.press('5');
     delay(100);
     Keyboard.release('5');    
  }
  
  
  if  ((customKey)=='J')
  {
     Keyboard.press('6');
     delay(100);
     Keyboard.release('6');    
  }
  
  
  if  ((customKey)=='T')
  {
     Keyboard.press('7');
     delay(100);
     Keyboard.release('7');    
  }
  
 if  ((customKey)=='S')
  {
     Keyboard.press('8');
     delay(100);
     Keyboard.release('8');    
  }
 
 
 if  ((customKey)=='R')
  {
     Keyboard.press('9');
     delay(100);
     Keyboard.release('9');    
  }
  
  if  ((customKey)=='A')
  {
     Keyboard.press('-');
     delay(100);
     Keyboard.release('-');    
  }
  
  
  if  ((customKey)=='y')
  {
     Keyboard.press('.');
     delay(100);
     Keyboard.release('.');    
  }
  
  if  ((customKey)=='m')
  {
     Keyboard.press('A');
     delay(100);
     Keyboard.release('A');    
  }
  
  if  ((customKey)=='k')
  {
     Keyboard.press('I');
     delay(100);
     Keyboard.release('I');    
  }
  
  if  ((customKey)=='j')
  {
     Keyboard.press('M');
     delay(100);
     Keyboard.release('M');    
  }
  
  if  ((customKey)=='l')
  {
     Keyboard.press('U');
     delay(100);
     Keyboard.release('U');    
  }
  
  if  ((customKey)=='i')
  {
     Keyboard.press('X');
     delay(100);
     Keyboard.release('X');    
  }
  
  if  ((customKey)=='h')
  {
     Keyboard.press('R');
     delay(100);
     Keyboard.release('R');    
  }
  
  if  ((customKey)=='g')
  {
     Keyboard.press('N');
     delay(100);
     Keyboard.release('N');    
  }
  
  if  ((customKey)=='e')
  {
     Keyboard.press('O');
     delay(100);
     Keyboard.release('O');    
  }
  
   if  ((customKey)=='c')
  {
     Keyboard.press('J');
     delay(100);
     Keyboard.release('J');    
  }
  
   if  ((customKey)=='b')
  {
     Keyboard.press('S');
     delay(100);
     Keyboard.release('S');    
  }
  
  
   if  ((customKey)=='d')
  {
     Keyboard.press('V');
     delay(100);
     Keyboard.release('V');    
  }
  
   if  ((customKey)=='a')
  {
     Keyboard.press('Y');
     delay(100);
     Keyboard.release('Y');    
  }
  
  
   if  ((customKey)=='0')
  {
     Keyboard.press('Q');
     delay(100);
     Keyboard.release('Q');    
  }
  
  
   if  ((customKey)=='9')
  {
     Keyboard.press('L');
     delay(100);
     Keyboard.release('L');    
  }
  
   if  ((customKey)=='7')
  {
     Keyboard.press('D');
     delay(100);
     Keyboard.release('D');    
  }
  
   if  ((customKey)=='5')
  {
     Keyboard.press('K');
     delay(100);
     Keyboard.release('K');    
  }
  
   if  ((customKey)=='4')
  {
     Keyboard.press('T');
     delay(100);
     Keyboard.release('T');    
  }
  
   if  ((customKey)=='6')
  {
     Keyboard.press('W');
     delay(100);
     Keyboard.release('W');    
  }
  
   if  ((customKey)=='3')
  {
     Keyboard.press('Z');
     delay(100);
     Keyboard.release('Z');    
  }
  
   if  ((customKey)=='2')
  {
     Keyboard.press('C');
     delay(100);
     Keyboard.release('C');    
  }
  
   if  ((customKey)=='1')
  {
     Keyboard.write(KEY_RETURN);
  //   delay(100);
 //    Keyboard.release(KEY_RETURN);    
  }
  
  if  ((customKey)=='#')
  {
     Keyboard.press('H');
     delay(100);
     Keyboard.release('H');    
  }
  
   if  ((customKey)=='Y')
  {
     Keyboard.press('G');
     delay(100);
     Keyboard.release('G');    
  }
  
   if  ((customKey)=='X')
  {
     Keyboard.press('F');
     delay(100);
     Keyboard.release('F');    
  }
  
   if  ((customKey)=='Z')
  {
     Keyboard.press('B');
     delay(100);
     Keyboard.release('B');    
  }
  
   if  ((customKey)=='W')
  {
     Keyboard.press('P');
     delay(100);
     Keyboard.release('P');    
  }
 
  if  ((customKey)=='V')
  {
     Keyboard.press('E');
     delay(100);
     Keyboard.release('E');    
  }
 
  if  ((customKey)=='8')
  {
     Keyboard.press(KEY_RIGHT_CTRL);
     Keyboard.press(KEY_RIGHT_SHIFT);
     Keyboard.press(KEY_RIGHT_ALT);
     Keyboard.press('R');
     delay(100);
     Keyboard.releaseAll();    
  }
 if  ((customKey)=='r')
  {
     Keyboard.press(KEY_RIGHT_CTRL);
     Keyboard.press(KEY_RIGHT_SHIFT);
     Keyboard.press(KEY_RIGHT_ALT);
     Keyboard.press('I');
     delay(100);
     Keyboard.releaseAll();    
  }
 
 if  ((customKey)=='U')
  {
     Keyboard.press(KEY_BACKSPACE);
     delay(100);
     Keyboard.release(KEY_BACKSPACE);    
  }
 
 
 if  ((customKey)=='N')
  {
     Keyboard.press(KEY_RIGHT_CTRL);
     Keyboard.press(KEY_RIGHT_SHIFT);
     Keyboard.press(KEY_RIGHT_ALT);
     Keyboard.press('H');
     delay(100);
     Keyboard.releaseAll();    
  }
  
  if  ((customKey)=='s')
  {
     Keyboard.press('KEY_F2');
     delay(100);
     Keyboard.release('KEY_F2');    
  }
 
 if  ((customKey)=='I')
  {
     Keyboard.press('KEY_F5');
     delay(100);
     Keyboard.release('KEY_F5');    
  }
  
}

Підвал форуму