Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: Adding leds into my code (not changing the keyboard part) makes keyboard undeclared?

  1. #1
    Junior Member
    Join Date
    Sep 2017
    Posts
    9

    Adding leds into my code (not changing the keyboard part) makes keyboard undeclared?

    Working with a teensy++2 with Windows 10.

    I built a keyboard sometime ago, and recently tried to return to it. In my previous work, I had completed a successful keyboard (minus a few weird bugs). My final work before putting the project away was to add rgb addressable leds in. At the time, I was successful. When I took out the keyboard, it still worked entirely, keyboard and leds both. However, when I attempted to re-upload (what I thought was) my most recent stable code, I encountered a compilation error about the modifier keys not being declared. I then returned to an older version of the code, and it compiled successfully. After checking the diffs between the two files, I found that the only changes were in regards to the leds being added - the keyboard code was identical.

    tldr: the two files are the same except the second has led code added in. For some reason it doesn't recognize modifier keys in the second.

    Also, are there updates to the teensy library that I should get? afaik I haven't updated those in a year.

    Here is the error message I am getting:
    Code:
    In file included from C:\Users\Benjamin Manninen\Documents\Keyboard\KeyboardV6_ColorPallete\KeyboardV6_ColorPallete.ino:3:0:
    
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\FastLED/FastLED.h:17:21: note: #pragma message: FastLED version 3.001.008
    
     #    pragma message "FastLED version 3.001.008"
    
                         ^
    
    KeyboardV6_ColorPallete:65: error: 'MODIFIERKEY_SHIFT' was not declared in this scope
                                           {MODIFIERKEY_SHIFT,0x1D,0x1B,0x06,0x19,0x05,0x11,0x10,0x36,0x37,0x38,MODIFIERKEY_RIGHT_SHIFT,0x00,0x00,0x59,0x5A,0x5B,0x00 },
    
                                            ^
    
    KeyboardV6_ColorPallete:65: error: 'MODIFIERKEY_RIGHT_SHIFT' was not declared in this scope
                                           {MODIFIERKEY_SHIFT,0x1D,0x1B,0x06,0x19,0x05,0x11,0x10,0x36,0x37,0x38,MODIFIERKEY_RIGHT_SHIFT,0x00,0x00,0x59,0x5A,0x5B,0x00 },
    
                                                                                                                ^
    
    KeyboardV6_ColorPallete:66: error: 'MODIFIERKEY_GUI' was not declared in this scope
                                           {MODIFIERKEY_GUI,MODIFIERKEY_ALT,0x2C,MODIFIERKEY_CTRL,0x00,0x00,0x00,0x2C,MODIFIERKEY_RIGHT_ALT,0x00,MODIFIERKEY_RIGHT_GUI,MODIFIERKEY_RIGHT_CTRL,0x00,0x52,0x00,0x62,0x63,0x58 },
    
                                            ^
    
    KeyboardV6_ColorPallete:66: error: 'MODIFIERKEY_ALT' was not declared in this scope
                                           {MODIFIERKEY_GUI,MODIFIERKEY_ALT,0x2C,MODIFIERKEY_CTRL,0x00,0x00,0x00,0x2C,MODIFIERKEY_RIGHT_ALT,0x00,MODIFIERKEY_RIGHT_GUI,MODIFIERKEY_RIGHT_CTRL,0x00,0x52,0x00,0x62,0x63,0x58 },
    
                                                            ^
    
    KeyboardV6_ColorPallete:66: error: 'MODIFIERKEY_CTRL' was not declared in this scope
                                           {MODIFIERKEY_GUI,MODIFIERKEY_ALT,0x2C,MODIFIERKEY_CTRL,0x00,0x00,0x00,0x2C,MODIFIERKEY_RIGHT_ALT,0x00,MODIFIERKEY_RIGHT_GUI,MODIFIERKEY_RIGHT_CTRL,0x00,0x52,0x00,0x62,0x63,0x58 },
    
                                                                                 ^
    
    KeyboardV6_ColorPallete:66: error: 'MODIFIERKEY_RIGHT_ALT' was not declared in this scope
                                           {MODIFIERKEY_GUI,MODIFIERKEY_ALT,0x2C,MODIFIERKEY_CTRL,0x00,0x00,0x00,0x2C,MODIFIERKEY_RIGHT_ALT,0x00,MODIFIERKEY_RIGHT_GUI,MODIFIERKEY_RIGHT_CTRL,0x00,0x52,0x00,0x62,0x63,0x58 },
    
                                                                                                                      ^
    
    KeyboardV6_ColorPallete:66: error: 'MODIFIERKEY_RIGHT_GUI' was not declared in this scope
                                           {MODIFIERKEY_GUI,MODIFIERKEY_ALT,0x2C,MODIFIERKEY_CTRL,0x00,0x00,0x00,0x2C,MODIFIERKEY_RIGHT_ALT,0x00,MODIFIERKEY_RIGHT_GUI,MODIFIERKEY_RIGHT_CTRL,0x00,0x52,0x00,0x62,0x63,0x58 },
    
                                                                                                                                                 ^
    
    KeyboardV6_ColorPallete:66: error: 'MODIFIERKEY_RIGHT_CTRL' was not declared in this scope
                                           {MODIFIERKEY_GUI,MODIFIERKEY_ALT,0x2C,MODIFIERKEY_CTRL,0x00,0x00,0x00,0x2C,MODIFIERKEY_RIGHT_ALT,0x00,MODIFIERKEY_RIGHT_GUI,MODIFIERKEY_RIGHT_CTRL,0x00,0x52,0x00,0x62,0x63,0x58 },
    
                                                                                                                                                                       ^
    
    KeyboardV6_ColorPallete: In function 'void hyperSend()':
    KeyboardV6_ColorPallete:425: error: 'Keyboard' was not declared in this scope
    To make a USB Keyboard, use the Tools > USB Type menu
       Keyboard.set_key1(keyPack[0]);                                //set keys
    
       ^
    
    'MODIFIERKEY_SHIFT' was not declared in this scope

    Here is my older, compilable code:
    Code:
    //#define rowA  17
    //#define rowB  16
    //#define rowC  15
    //#define rowD  14
    //#define rowE  13
    //#define rowF  12
    //#define rowG  11
    //#define rowH  10
    //
    //
    //#define col1  45
    //#define col1  44
    //#define col2  43
    //#define col3  42
    //#define col4  41
    //#define col5  40
    //#define col6  39
    //#define col7  38
    //#define col8  8
    //#define col9  26
    //#define col10 25
    //#define col11 24
    //#define col12 23
    //#define col13 22
    //#define col14 21
    //#define col15 20
    //#define col16 19
    //#define col17 18
    
    int population = 0;
    int rowPin[] = {10, 11, 12, 13, 14, 15, 16, 17};
    int colPin[] = {18, 19, 20, 21, 22, 23, 24, 25, 26, 8, 38, 39, 40, 41, 42, 43, 44, 45};
    
    
      String  ASCIIkeyMatrix[8][18] = {   {"      ","  fn  ","   fn ","   fn ","   fn ","   fn ","   fn ","   fn ","   fn ","  fn  ","      ","      ","      ","      ","      ","      ","  fn  ","  fn  " },
                                          {"  esc ","  fn  ","  fn  ","   fn ","   fn ","   fn ","   fn ","   fn ","   fn ","  fn  ","      ","      ","      ","      ","      ","      ","  fn  ","  fn  " },
                                          {"tiddle","  1   ","  2   ","   3  ","   4  ","   5  ","   6  ","   7  ","   8  ","  9   ","   0  ","   -  ","   =  ","back  ","numlok","   /  ","  *   ","   -  " },
                                          {" tab  ","  q   ","  w   ","   e  ","   r  ","   t  ","   y  ","   u  ","   i  ","  o   ","   p  ","   [  ","   ]  ","bkslsh","  7   ","  8   ","  9   ","      " },
                                          {" caps ","  a   ","  s   ","   d  ","   f  ","   g  ","   h  ","   j  ","   k  ","  l   ","   ;  ","   '  ","enter ","      ","  4   ","  5   ","  6   ","  +   " },
                                          {"shift ","  z   ","  x   ","   c  ","   v  ","   b  ","   n  ","   m  ","  ,   ","  .   ","   /? ","shift ","      ","      ","  1   ","  2   ","  3   ","      " },
                                          {" win  "," alt  ","space ","  ctrl","      ","      ","      ","space "," alt  ","  fn  ","  win "," ctrl ","      ","  up  ","      ","  0   ","  .   "," enter" },
                                          {"      ","      ","      ","  fn  ","   fn ","   fn ","  fn  ","      ","      ","      ","      ","      ","left  "," down "," right","      ","      ","      " },
                               };
    
    //this only serves to easily compare ascii to raw
    //String    RAWkeyMatrix[8][18] = {   {" 0x00 "," 0x00 "," 0xfn "," 0xfn "," 0xfn "," 0xfn "," 0xfn "," 0xfn "," 0xfn "," 0xfn "," 0x00 "," 0x00 "," 0x00 "," 0x00 "," 0x00 "," 0x00 "," 0xfn "," 0xfn " },
    //                                    {" 0x29 "," 0x00 "," 0xfn "," 0xfn "," 0xfn "," 0xfn "," 0xfn "," 0xfn "," 0xfn "," 0xfn "," 0x00 "," 0x00 "," 0x00 "," 0x00 "," 0x00 "," 0x00 "," 0xfn "," 0xfn " },
    //                                    {" 0x35 "," 0x1E "," 0x1F "," 0x20 "," 0x21 "," 0x22 "," 0x23 "," 0x24 "," 0x25 "," 0x26 "," 0x27 "," 0x2D "," 0x2E "," 0x2A "," 0x83 "," 0x54 "," 0x55 "," 0x56 " },
    //                                    {" 0x2B "," 0x14 "," 0x1A "," 0x08 "," 0x15 "," 0x17 "," 0x1C "," 0x18 "," 0x0C "," 0x12 "," 0x13 "," 0x2F "," 0x30 "," 0x31 "," 0x5F "," 0x60 "," 0x61 "," 0x00 " },
    //                                    {" 0x39 "," 0x04 "," 0x16 "," 0x07 "," 0x09 "," 0x0A "," 0x0B "," 0x0D "," 0x0E "," 0x0F "," 0x33 "," 0x34 "," 0x28 "," 0x00 "," 0x5D "," 0x5C "," 0x5E "," 0x57 " },
    //                                    {" 0xE1 "," 0x1D "," 0x1B "," 0x06 "," 0x19 "," 0x05 "," 0x11 "," 0x10 "," 0x36 "," 0x37 "," 0x38 "," 0xE5 "," 0x00 "," 0x00 "," 0x59 "," 0x5A "," 0x5B "," 0x00 " },
    //                                    {" 0xE3 "," 0xE2 "," 0x2C "," 0x3A "," 0x00 "," 0x00 "," 0x00 "," 0x2C "," 0xE6 "," 0xfn "," 0xE7 "," 0xE4 "," 0x00 "," 0x52 "," 0x00 "," 0x62 "," 0x63 "," 0x58 " },
    //                                    {" 0x00 "," 0x00 "," 0x00 "," 0xfn "," 0xfn "," 0xfn "," 0xfn "," 0x00 "," 0x00 "," 0x00 "," 0x00 "," 0x00 "," 0x50 "," 0x51 "," 0x4F "," 0x00 "," 0x00 "," 0x00 " },
    //                                };
                               
      int    RAWkeyMatrix[8][18] = {      {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },
                                          {0x29,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },
                                          {0x35,0x1E,0x1F,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x2D,0x2E,0x2A,0x83,0x54,0x55,0x56 },
                                          {0x2B,0x14,0x1A,0x08,0x15,0x17,0x1C,0x18,0x0C,0x12,0x13,0x2F,0x30,0x31,0x5F,0x60,0x61,0x00 },
                                          {0x39,0x04,0x16,0x07,0x09,0x0A,0x0B,0x0D,0x0E,0x0F,0x33,0x34,0x28,0x00,0x5D,0x5C,0x5E,0x57 }, 
                                          {MODIFIERKEY_SHIFT,0x1D,0x1B,0x06,0x19,0x05,0x11,0x10,0x36,0x37,0x38,MODIFIERKEY_RIGHT_SHIFT,0x00,0x00,0x59,0x5A,0x5B,0x00 },
                                          {MODIFIERKEY_GUI,MODIFIERKEY_ALT,0x2C,MODIFIERKEY_CTRL,0x00,0x00,0x00,0x2C,MODIFIERKEY_RIGHT_ALT,0x00,MODIFIERKEY_RIGHT_GUI,MODIFIERKEY_RIGHT_CTRL,0x00,0x52,0x00,0x62,0x63,0x58 },
                                          {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x50,0x51,0x4F,0x00,0x00,0x00 },
                                      };
                               
    bool keyPress[8][18];
    
    int currentKeyIndex = 0; 
    int currentModIndex = 0; 
    
    int keyPack[6];
    int modPack[8];
    
    int modIndices[8][2] = {{5,0},{6,1},{6,3},{6,8},{6,11},{5,11},{6,0},{6,10}};
    
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    void setup()
    {
      Serial.begin(9600);                                         //Start serial connection
    
      for (int col = 0; col < 18; col++)                          //Set all column pins to be Outputs
      {
        pinMode(colPin[col], OUTPUT);
      }
      
      for (int row = 0; row < 8; row++)                           //Set all row pins to be inputs with pull up resistors
      {
        pinMode(rowPin[row], INPUT_PULLUP);
      }
    
      eraseState();
    
    
      Serial.println("lookin good so far.   Init successful");
    }
    
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    void eraseState()
    {
      for (int col = 0; col < 18; col++)                          //cycle through columns                                                             --- Sets all temp values to default/null/false
      {
        for (int row = 0; row < 8; row++)                         //cycle through rows
        {
                keyPress[row][col] = false;                       //set matrix position to false
        }
      }
      for(int i = 0;i<6;i++)                                      //cycle through keypack                                                             --- Clear keypack and modpack
      {
        keyPack[i] = 0x00;                                        //set keypack to null
      }
      for(int i = 0;i<8;i++)
      {
        modPack[i] = 0x00;                                        //set modpack to null
      }
      currentModIndex = 0;
      currentKeyIndex = 0;
      
    }
    
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    void populate()
    {
      for (int col = 0; col < 18; col++)                          //Iterate through sending each column                                               --- Sending high, will cause the any input pins connected to become "high" since they are pulled down with external resistors
      {                                                           //                                                                                  --- Sending low, will revert to nothing happening
      digitalWrite(colPin[col],HIGH);
        for (int row = 0; row < 8; row++)                         //senses on each row pin, to determin which keys from the current column are being pressed
        {
          if( digitalRead(rowPin[row]))                           //if key pressed
          {
            keyPress[row][col] = true;                            //record key as pressed in the keypress matrix
          }
        }  
      digitalWrite(colPin[col],LOW);                              //return the column to passive
      }
    
    
      
    }
    
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    void printKeyPress()
    {
      Serial.println(population);
      for(int row = 0;row<8;row++)                                //cycle through all rows                                                            --- This section prints the matrix out to serial
      {
        Serial.println();
        for(int col = 0;col<18;col++)                             //cycle through columns
        {
          if(keyPress[row][col] == false)                         //if key is not pressed, print 0000
          {
            Serial.print(" 0000 ");
          }
          else
          {
            Serial.print(ASCIIkeyMatrix[row][col]);               //if key is pressed print its plaintext value
          }
        }
      }
      Serial.println();
      for(int i =0;i<8;i++)
      {
        Serial.print(modPack[i]);
        Serial.print(" ");
      }
      Serial.println();
      for(int i =0;i<6;i++)
      {
        Serial.print(keyPack[i]);
      }
      Serial.println();
      Serial.println("--------");
      Serial.println("--------");
      Serial.println("--------");
      Serial.println("--------");
      population++;
    }
    
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    void keySearch()
    {
      if(keyPress[6][2]&&keyPress[6][7])
      {
        keyPress[6][2] = false;
      }
      for (int col = 0; col < 18; col++)                          //Iterate through sending logic signals through each  --- Sending high, will have no effect on the input pins, which are pulled up by internal resistors
      {                                                           //                                                    --- Sending low, will cause the pin to act as a current sink, and thereby pull the input pins down to a low signal
        for (int row = 0; row < 8; row++)                         //senses on each row pin, to determin which keys from the current column are being pressed
        {
          if(currentKeyIndex<6)
          {
            
            if(keyPress[row][col])
            {
               keyPack[currentKeyIndex] = RAWkeyMatrix[row][col];
               currentKeyIndex++;
            }
          }
        }  
      }
    }
    
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    void modSearch()
    {
      for(int i = 0;i<8;i++)
      {
        int temp = modIndices[i][0];
        int temp2= modIndices[i][1];
        if(keyPress[temp][temp2])
        {
          if(currentModIndex<8)
          {
            modPack[currentModIndex] = RAWkeyMatrix[modIndices[i][0]][modIndices[i][1]];
            currentModIndex++;
          }
          keyPress[modIndices[i][0]][modIndices[i][1]]=false;
        }
      }
    }
    
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    
    void hyperSend()                                                //this method sends all of the kepresses to the computer
    {
      Keyboard.set_key1(keyPack[0]);                                //set keys
      Keyboard.set_key2(keyPack[1]);                                //set keys
      Keyboard.set_key3(keyPack[2]);                                //set keys
      Keyboard.set_key4(keyPack[3]);                                //set keys
      Keyboard.set_key5(keyPack[4]);                                //set keys
      Keyboard.set_key6(keyPack[5]);                                //set keys
    
      Keyboard.set_modifier(modPack[0]|modPack[1]|modPack[2]|modPack[3]|modPack[4]|modPack[5]|modPack[6]|modPack[7]);                                  //set modifiers
      Keyboard.send_now();                                          //send all
    }
    
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    void loop() 
    {
      delay(100);
      eraseState();                                                 //clear all states
      populate();                                                   //check and record all key press current values
      
      modSearch();                                                  //pull up to 8 modifiers out of all pressed keys
      keySearch();                                                  //pull up to 6 key presses out of all pressed keys
    
      printKeyPress();                                              //print key presses to serial monitor for debugging
    
      hyperSend();                                                  //send key presses to computer as a keyboard.
      
    
    
      //change and update led state
    }
    Here is the updated code with leds that throws an error:
    Code:
    #include<FastLED.h>
    
    const uint8_t kMatrixWidth  = 26;
    const uint8_t kMatrixHeight = 10;
    const bool    kMatrixSerpentineLayout = true;
    
    #define NUM_LEDS (kMatrixWidth * kMatrixHeight)
    #define MAX_DIMENSION ((kMatrixWidth>kMatrixHeight) ? kMatrixWidth : kMatrixHeight)
    CRGB leds[kMatrixWidth * kMatrixHeight];
    
    #define LED_PIN     5
    #define BRIGHTNESS  40
    #define LED_TYPE    WS2812
    #define COLOR_ORDER GRB
    
    uint16_t speed = 20; // speed is set dynamically once we've started up
    
    uint16_t scale = 30; // scale is set dynamically once we've started up
    
    uint8_t noise[MAX_DIMENSION][MAX_DIMENSION];
    
    static uint16_t x;
    static uint16_t y;
    static uint16_t z;
    
    #define HOLD_PALETTES_X_TIMES_AS_LONG 1
    
    CRGBPalette16 currentPalette( PartyColors_p );
    uint8_t       colorLoop = 1;
    
    
    int population = 0;
    int rowPin[] = {10, 11, 12, 13, 14, 15, 16, 17};
    int colPin[] = {18, 19, 20, 21, 22, 23, 24, 25, 26, 8, 38, 39, 40, 41, 42, 43, 44, 45};
    
    
      String  ASCIIkeyMatrix[8][18] = {   {"      ","  fn  ","   fn ","   fn ","   fn ","   fn ","   fn ","   fn ","   fn ","  fn  ","      ","      ","      ","      ","      ","      ","  fn  ","  fn  " },
                                          {"  esc ","  fn  ","  fn  ","   fn ","   fn ","   fn ","   fn ","   fn ","   fn ","  fn  ","      ","      ","      ","      ","      ","      ","  fn  ","  fn  " },
                                          {"tiddle","  1   ","  2   ","   3  ","   4  ","   5  ","   6  ","   7  ","   8  ","  9   ","   0  ","   -  ","   =  ","back  ","numlok","   /  ","  *   ","   -  " },
                                          {" tab  ","  q   ","  w   ","   e  ","   r  ","   t  ","   y  ","   u  ","   i  ","  o   ","   p  ","   [  ","   ]  ","bkslsh","  7   ","  8   ","  9   ","      " },
                                          {" caps ","  a   ","  s   ","   d  ","   f  ","   g  ","   h  ","   j  ","   k  ","  l   ","   ;  ","   '  ","enter ","      ","  4   ","  5   ","  6   ","  +   " },
                                          {"shift ","  z   ","  x   ","   c  ","   v  ","   b  ","   n  ","   m  ","  ,   ","  .   ","   /? ","shift ","      ","      ","  1   ","  2   ","  3   ","      " },
                                          {" win  "," alt  ","space ","  ctrl","      ","      ","      ","space "," alt  ","  fn  ","  win "," ctrl ","      ","  up  ","      ","  0   ","  .   "," enter" },
                                          {"      ","      ","      ","  fn  ","   fn ","   fn ","  fn  ","      ","      ","      ","      ","      ","left  "," down "," right","      ","      ","      " },
                               };
    
    //this only serves to easily compare ascii to raw
    //String    RAWkeyMatrix[8][18] = {   {" 0x00 "," 0x00 "," 0xfn "," 0xfn "," 0xfn "," 0xfn "," 0xfn "," 0xfn "," 0xfn "," 0xfn "," 0x00 "," 0x00 "," 0x00 "," 0x00 "," 0x00 "," 0x00 "," 0xfn "," 0xfn " },
    //                                    {" 0x29 "," 0x00 "," 0xfn "," 0xfn "," 0xfn "," 0xfn "," 0xfn "," 0xfn "," 0xfn "," 0xfn "," 0x00 "," 0x00 "," 0x00 "," 0x00 "," 0x00 "," 0x00 "," 0xfn "," 0xfn " },
    //                                    {" 0x35 "," 0x1E "," 0x1F "," 0x20 "," 0x21 "," 0x22 "," 0x23 "," 0x24 "," 0x25 "," 0x26 "," 0x27 "," 0x2D "," 0x2E "," 0x2A "," 0x83 "," 0x54 "," 0x55 "," 0x56 " },
    //                                    {" 0x2B "," 0x14 "," 0x1A "," 0x08 "," 0x15 "," 0x17 "," 0x1C "," 0x18 "," 0x0C "," 0x12 "," 0x13 "," 0x2F "," 0x30 "," 0x31 "," 0x5F "," 0x60 "," 0x61 "," 0x00 " },
    //                                    {" 0x39 "," 0x04 "," 0x16 "," 0x07 "," 0x09 "," 0x0A "," 0x0B "," 0x0D "," 0x0E "," 0x0F "," 0x33 "," 0x34 "," 0x28 "," 0x00 "," 0x5D "," 0x5C "," 0x5E "," 0x57 " },
    //                                    {" 0xE1 "," 0x1D "," 0x1B "," 0x06 "," 0x19 "," 0x05 "," 0x11 "," 0x10 "," 0x36 "," 0x37 "," 0x38 "," 0xE5 "," 0x00 "," 0x00 "," 0x59 "," 0x5A "," 0x5B "," 0x00 " },
    //                                    {" 0xE3 "," 0xE2 "," 0x2C "," 0x3A "," 0x00 "," 0x00 "," 0x00 "," 0x2C "," 0xE6 "," 0xfn "," 0xE7 "," 0xE4 "," 0x00 "," 0x52 "," 0x00 "," 0x62 "," 0x63 "," 0x58 " },
    //                                    {" 0x00 "," 0x00 "," 0x00 "," 0xfn "," 0xfn "," 0xfn "," 0xfn "," 0x00 "," 0x00 "," 0x00 "," 0x00 "," 0x00 "," 0x50 "," 0x51 "," 0x4F "," 0x00 "," 0x00 "," 0x00 " },
    //                                };
                               
      int    RAWkeyMatrix[8][18] = {      {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },
                                          {0x29,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },
                                          {0x35,0x1E,0x1F,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x2D,0x2E,0x2A,0x83,0x54,0x55,0x56 },
                                          {0x2B,0x14,0x1A,0x08,0x15,0x17,0x1C,0x18,0x0C,0x12,0x13,0x2F,0x30,0x31,0x5F,0x60,0x61,0x00 },
                                          {0x39,0x04,0x16,0x07,0x09,0x0A,0x0B,0x0D,0x0E,0x0F,0x33,0x34,0x28,0x00,0x5D,0x5C,0x5E,0x57 }, 
                                          {MODIFIERKEY_SHIFT,0x1D,0x1B,0x06,0x19,0x05,0x11,0x10,0x36,0x37,0x38,MODIFIERKEY_RIGHT_SHIFT,0x00,0x00,0x59,0x5A,0x5B,0x00 },
                                          {MODIFIERKEY_GUI,MODIFIERKEY_ALT,0x2C,MODIFIERKEY_CTRL,0x00,0x00,0x00,0x2C,MODIFIERKEY_RIGHT_ALT,0x00,MODIFIERKEY_RIGHT_GUI,MODIFIERKEY_RIGHT_CTRL,0x00,0x52,0x00,0x62,0x63,0x58 },
                                          {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x50,0x51,0x4F,0x00,0x00,0x00 },
                                      };
                               
    bool keyPress[8][18];
    
    int currentKeyIndex = 0; 
    int currentModIndex = 0; 
    
    int keyPack[6];
    int modPack[8];
    
    int modIndices[8][2] = {{5,0},{6,1},{6,3},{6,8},{6,11},{5,11},{6,0},{6,10}};
    
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    void fillnoise8() {
      // If we're runing at a low "speed", some 8-bit artifacts become visible
      // from frame-to-frame.  In order to reduce this, we can do some fast data-smoothing.
      // The amount of data smoothing we're doing depends on "speed".
      uint8_t dataSmoothing = 0;
      if( speed < 50) {
        dataSmoothing = 200 - (speed * 4);
      }
      
      for(int i = 0; i < MAX_DIMENSION; i++) {
        int ioffset = scale * i;
        for(int j = 0; j < MAX_DIMENSION; j++) {
          int joffset = scale * j;
          
          uint8_t data = inoise8(x + ioffset,y + joffset,z);
    
          // The range of the inoise8 function is roughly 16-238.
          // These two operations expand those values out to roughly 0..255
          // You can comment them out if you want the raw noise data.
          data = qsub8(data,16);
          data = qadd8(data,scale8(data,39));
    
          if( dataSmoothing ) {
            uint8_t olddata = noise[i][j];
            uint8_t newdata = scale8( olddata, dataSmoothing) + scale8( data, 256 - dataSmoothing);
            data = newdata;
          }
          
          noise[i][j] = data;
        }
      }
      
      z += speed;
      
      // apply slow drift to X and Y, just for visual variation.
      x += speed / 8;
      y -= speed / 16;
    }
    
    
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    void mapNoiseToLEDsUsingPalette()
    {
      static uint8_t ihue=0;
      
      for(int i = 0; i < kMatrixWidth; i++) {
        for(int j = 0; j < kMatrixHeight; j++) {
          // We use the value at the (i,j) coordinate in the noise
          // array for our brightness, and the flipped value from (j,i)
          // for our pixel's index into the color palette.
    
          uint8_t index = noise[j][i];
          uint8_t bri =   noise[i][j];
    
          // if this palette is a 'loop', add a slowly-changing base value
          if( colorLoop) { 
            index += ihue;
          }
    
          // brighten up, as the color palette itself often contains the 
          // light/dark dynamic range desired
          if( bri > 127 ) {
            bri = 255;
          } else {
            bri = dim8_raw( bri * 2);
          }
    
          CRGB color = ColorFromPalette( currentPalette, index, bri);
          leds[XY(i,j)] = color;
        }
      }
      
      ihue+=1;
    }
    
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    void ChangePaletteAndSettingsPeriodically()
    {
      uint8_t secondHand = ((millis() / 1000) / HOLD_PALETTES_X_TIMES_AS_LONG) % 60;
      static uint8_t lastSecond = 99;
      
      if( lastSecond != secondHand) {
        lastSecond = secondHand;
        if( secondHand ==  0)  { currentPalette = RainbowColors_p;         speed = 20; scale = 30; colorLoop = 1; }
        if( secondHand ==  5)  { SetupPurpleAndGreenPalette();             speed = 10; scale = 50; colorLoop = 1; }
        if( secondHand == 10)  { SetupBlackAndWhiteStripedPalette();       speed = 20; scale = 30; colorLoop = 1; }
        if( secondHand == 15)  { currentPalette = ForestColors_p;          speed =  8; scale =120; colorLoop = 0; }
        if( secondHand == 20)  { currentPalette = CloudColors_p;           speed =  4; scale = 30; colorLoop = 0; }
        if( secondHand == 25)  { currentPalette = LavaColors_p;            speed =  8; scale = 50; colorLoop = 0; }
        if( secondHand == 30)  { currentPalette = OceanColors_p;           speed = 20; scale = 90; colorLoop = 0; }
        if( secondHand == 35)  { currentPalette = PartyColors_p;           speed = 20; scale = 30; colorLoop = 1; }
        if( secondHand == 40)  { SetupRandomPalette();                     speed = 20; scale = 20; colorLoop = 1; }
        if( secondHand == 45)  { SetupRandomPalette();                     speed = 50; scale = 50; colorLoop = 1; }
        if( secondHand == 50)  { SetupRandomPalette();                     speed = 90; scale = 90; colorLoop = 1; }
        if( secondHand == 55)  { currentPalette = RainbowStripeColors_p;   speed = 30; scale = 20; colorLoop = 1; }
      }
    }
    
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    void SetupRandomPalette()
    {
      currentPalette = CRGBPalette16( 
                          CHSV( random8(), 255, 32), 
                          CHSV( random8(), 255, 255), 
                          CHSV( random8(), 128, 255), 
                          CHSV( random8(), 255, 255)); 
    }
    
    // This function sets up a palette of black and white stripes,
    // using code.  Since the palette is effectively an array of
    // sixteen CRGB colors, the various fill_* functions can be used
    // to set them up.
    void SetupBlackAndWhiteStripedPalette()
    {
      // 'black out' all 16 palette entries...
      fill_solid( currentPalette, 16, CRGB::Black);
      // and set every fourth one to white.
      currentPalette[0] = CRGB::White;
      currentPalette[4] = CRGB::White;
      currentPalette[8] = CRGB::White;
      currentPalette[12] = CRGB::White;
    
    }
    
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    void SetupPurpleAndGreenPalette()
    {
      CRGB purple = CHSV( HUE_PURPLE, 255, 255);
      CRGB green  = CHSV( HUE_GREEN, 255, 255);
      CRGB black  = CRGB::Black;
      
      currentPalette = CRGBPalette16( 
        green,  green,  black,  black,
        purple, purple, black,  black,
        green,  green,  black,  black,
        purple, purple, black,  black );
    }
    
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    uint16_t XY( uint8_t x, uint8_t y)
    {
      uint16_t i;
      if( kMatrixSerpentineLayout == false) {
        i = (y * kMatrixWidth) + x;
      }
      if( kMatrixSerpentineLayout == true) {
        if( y & 0x01) {
          // Odd rows run backwards
          uint8_t reverseX = (kMatrixWidth - 1) - x;
          i = (y * kMatrixWidth) + reverseX;
        } else {
          // Even rows run forwards
          i = (y * kMatrixWidth) + x;
        }
      }
      return i;
    }
    
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    void setup()
    {
      Serial.begin(9600);                                         //Start serial connection
    
      for (int col = 0; col < 18; col++)                          //Set all column pins to be Outputs
      {
        pinMode(colPin[col], OUTPUT);
      }
      
      for (int row = 0; row < 8; row++)                           //Set all row pins to be inputs with pull up resistors
      {
        pinMode(rowPin[row], INPUT_PULLUP);
      }
    
      eraseState();
    
    
      Serial.println("lookin good so far.   Init successful");
    
      LEDS.addLeds<LED_TYPE,LED_PIN,COLOR_ORDER>(leds,NUM_LEDS);
      LEDS.setBrightness(BRIGHTNESS);
    
      x = random16();
      y = random16();
      z = random16();
    }
    
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    void eraseState()
    {
      for (int col = 0; col < 18; col++)                          //cycle through columns                                                             --- Sets all temp values to default/null/false
      {
        for (int row = 0; row < 8; row++)                         //cycle through rows
        {
                keyPress[row][col] = false;                       //set matrix position to false
        }
      }
      for(int i = 0;i<6;i++)                                      //cycle through keypack                                                             --- Clear keypack and modpack
      {
        keyPack[i] = 0x00;                                        //set keypack to null
      }
      for(int i = 0;i<8;i++)
      {
        modPack[i] = 0x00;                                        //set modpack to null
      }
      currentModIndex = 0;
      currentKeyIndex = 0;
      
    }
    
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    void populate()
    {
      for (int col = 0; col < 18; col++)                          //Iterate through sending each column                                               --- Sending high, will cause the any input pins connected to become "high" since they are pulled down with external resistors
      {                                                           //                                                                                  --- Sending low, will revert to nothing happening
      digitalWrite(colPin[col],HIGH);
        for (int row = 0; row < 8; row++)                         //senses on each row pin, to determin which keys from the current column are being pressed
        {
          if( digitalRead(rowPin[row]))                           //if key pressed
          {
            keyPress[row][col] = true;                            //record key as pressed in the keypress matrix
          }
        }  
      digitalWrite(colPin[col],LOW);                              //return the column to passive
      }
    
    
      
    }
    
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    void printKeyPress()
    {
      Serial.println(population);
      for(int row = 0;row<8;row++)                                //cycle through all rows                                                            --- This section prints the matrix out to serial
      {
        Serial.println();
        for(int col = 0;col<18;col++)                             //cycle through columns
        {
          if(keyPress[row][col] == false)                         //if key is not pressed, print 0000
          {
            Serial.print(" 0000 ");
          }
          else
          {
            Serial.print(ASCIIkeyMatrix[row][col]);               //if key is pressed print its plaintext value
          }
        }
      }
      Serial.println();
      for(int i =0;i<8;i++)
      {
        Serial.print(modPack[i]);
        Serial.print(" ");
      }
      Serial.println();
      for(int i =0;i<6;i++)
      {
        Serial.print(keyPack[i]);
      }
      Serial.println();
      Serial.println("--------");
      Serial.println("--------");
      Serial.println("--------");
      Serial.println("--------");
      population++;
    }
    
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    void keySearch()
    {
      if(keyPress[6][2]&&keyPress[6][7])
      {
        keyPress[6][2] = false;
      }
      for (int col = 0; col < 18; col++)                          //Iterate through sending logic signals through each  --- Sending high, will have no effect on the input pins, which are pulled up by internal resistors
      {                                                           //                                                    --- Sending low, will cause the pin to act as a current sink, and thereby pull the input pins down to a low signal
        for (int row = 0; row < 8; row++)                         //senses on each row pin, to determin which keys from the current column are being pressed
        {
          if(currentKeyIndex<6)
          {
            
            if(keyPress[row][col])
            {
               keyPack[currentKeyIndex] = RAWkeyMatrix[row][col];
               currentKeyIndex++;
            }
          }
        }  
      }
    }
    
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    void modSearch()
    {
      for(int i = 0;i<8;i++)
      {
        int temp = modIndices[i][0];
        int temp2= modIndices[i][1];
        if(keyPress[temp][temp2])
        {
          if(currentModIndex<8)
          {
            modPack[currentModIndex] = RAWkeyMatrix[modIndices[i][0]][modIndices[i][1]];
            currentModIndex++;
          }
          keyPress[modIndices[i][0]][modIndices[i][1]]=false;
        }
      }
    }
    
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    
    void hyperSend()                                                //this method sends all of the keypresses to the computer
    {
      Keyboard.set_key1(keyPack[0]);                                //set keys
      Keyboard.set_key2(keyPack[1]);                                //set keys
      Keyboard.set_key3(keyPack[2]);                                //set keys
      Keyboard.set_key4(keyPack[3]);                                //set keys
      Keyboard.set_key5(keyPack[4]);                                //set keys
      Keyboard.set_key6(keyPack[5]);                                //set keys
    
      Keyboard.set_modifier(modPack[0]|modPack[1]|modPack[2]|modPack[3]|modPack[4]|modPack[5]|modPack[6]|modPack[7]);                                  //set modifiers
      Keyboard.send_now();                                          //send all
    }
    
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    void loop()
    {
      delay(100);
      eraseState();                                                 //clear all states
      populate();                                                   //check and record all key press current values
      
      modSearch();                                                  //pull up to 8 modifiers out of all pressed keys
      keySearch();                                                  //pull up to 6 key presses out of all pressed keys
    
      printKeyPress();                                              //print key presses to serial monitor for debugging
    
      hyperSend();                                                  //send key presses to computer as a keyboard.
      
    
    
      ChangePaletteAndSettingsPeriodically();
      fillnoise8();
      mapNoiseToLEDsUsingPalette();
      LEDS.show();}

  2. #2
    Junior Member
    Join Date
    Sep 2017
    Posts
    9
    Just found an extra file that is identical to the earlier code (the functional one) but has the same compile errors as the later one... Does this mean that its more an issue with my installation/file paths and such rather than with the code necessarily? Thanks for any help.

  3. #3
    Senior Member
    Join Date
    May 2017
    Posts
    164
    How can the one you say works, actually not also have errors? You have no #define statements and no #include statements.
    The only thing I can think of is that this sketch must have other tabs and the IDE has a way to automatically include files ( or your not using the IDE ).

    Edit: I find that multiple .ino files will be compiled together as one file. The only thing that makes sense is that in your project that works, there is a file with the same name as the directory that has the #define statements, and that the file you posted is a 2nd .ino file in the directory and that 2nd file is not the same name as the directory.

    In the project that does not compile, you may have both files, but the wrong file is the same name as the directory. ( the file with the same name gets compiled first ).

    If this is correct then I suggest you rename the first file as a .h file and include it the normal way.
    Last edited by rcarr; 01-13-2019 at 12:42 AM.

  4. #4
    Junior Member
    Join Date
    Sep 2017
    Posts
    9
    Thank you for your response. I actually found the problem while writing a response to your message. I had thought that the definitions I needed were automatically included, since I was compiling it as a keyboard (in usb type). I went back to check before I hit post, and it turns out that I had that setting correct on the older code, but had forgotten to change that setting in the ide on the newer code... Now I feel kinda silly.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •