Advertisement
Guest User

portavoltex "code"

a guest
Dec 28th, 2020
530
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.90 KB | None | 0 0
  1. #include ﹤Keypad.h
  2.               #include ﹤Keyboard.h
  3.               #include ﹤Encoder.h
  4.               #include ﹤Mouse.h
  5.              
  6.               Encoder encTwo(A3, A2);
  7.               Encoder encOne(A1, A0);
  8.              
  9.              
  10.               const byte ROWS = 3; //four rows
  11.               const byte COLS = 3; //three columns
  12.               char keys[ROWS][COLS] = {
  13.               {'1','2','3'},
  14.               {'4','5','6'},
  15.               {'7','8','9'}
  16.               };
  17.               char knees[9]= {97,98,99,100,101,102,103,104,105};
  18.               byte rowPins[ROWS] = {4, 3, 2}; //connect to the row pinouts of the kpd
  19.               byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the kpd
  20.              
  21.               Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
  22.              
  23.               unsigned long loopCount;
  24.               unsigned long startTime;
  25.               String msg;
  26.               int bbb;
  27.              
  28.               void setup() {
  29.                   Serial.begin(9600);
  30.                   loopCount = 0;d
  31.                   startTime = millis();
  32.                   msg = "";
  33.               }
  34.              
  35.               long oldPosition1  = -999;
  36.               long oldPosition2  = -999;
  37.               int count = 0;
  38.               int sped = 1; // controls speed of mouse movement
  39.              
  40.               void loop() {
  41.                   long newPosition1 = encOne.read();
  42.                   long newPosition2 = encTwo.read();
  43.                   if (count == 50) // slows scan rate (a debounce of sorts)
  44.                   {
  45.                     if (newPosition1 != oldPosition1)
  46.                     {
  47.                       if (newPosition1 ﹤ (oldPosition1))
  48.                       {
  49.                         Mouse.move(0, sped, 0);
  50.                       }
  51.                       else if ((newPosition1) ﹥ oldPosition1)
  52.                       {
  53.                         Mouse.move(0, -sped, 0);
  54.                       }
  55.                  
  56.                       oldPosition1 = newPosition1;
  57.                        
  58.                       Serial.println(newPosition1);
  59.                     }
  60.                     if (newPosition2 != oldPosition2)
  61.                     {
  62.                       if (newPosition2 ﹤ (oldPosition2))
  63.                       {
  64.                         Mouse.move(sped, 0, 0);
  65.                       }
  66.                       else if ((newPosition2) ﹥ oldPosition2)
  67.                       {
  68.                         Mouse.move(-sped, 0, 0);
  69.                       }
  70.                  
  71.                       oldPosition2 = newPosition2;
  72.                        
  73.                       Serial.println(newPosition2);
  74.                     }
  75.                     count = 0;
  76.                   }
  77.                   count++;
  78.                   loopCount++;
  79.                   if ( (millis()-startTime)>5000 ) {
  80.                       Serial.print("Average loops per second = ");
  81.                       Serial.println(loopCount/5);
  82.                       startTime = millis();
  83.                       loopCount = 0;
  84.                   }
  85.              
  86.                   // Fills kpd.key[ ] array with up-to 10 active keys.
  87.                   // Returns true if there are ANY active keys.
  88.                   if (kpd.getKeys())
  89.                   {
  90.                       for (int i=0; i﹤LIST_MAX; i++)   // Scan the whole key list.
  91.                       {
  92.                           if ( kpd.key[i].stateChanged )   // Only find keys that have changed state.
  93.                           {
  94.                               switch (kpd.key[i].kstate) {  // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
  95.                                   case PRESSED:
  96.                                   Serial.print(kpd.key[i].kchar);
  97.                                   Keyboard.press(kpd.key[i].kchar+92);
  98.                                   msg = " PRESSED.";
  99.                               break;
  100.                                   case HOLD:
  101.                                   Serial.print(kpd.key[i].kchar);
  102.                                   msg = " HOLD.";
  103.                               break;
  104.                                   case RELEASED:
  105.                                   Keyboard.release(kpd.key[i].kchar+92);
  106.                                   msg = " RELEASED.";
  107.                               break;
  108.                                   case IDLE:
  109.                                   Serial.print(kpd.key[i].kchar);
  110.                                   msg = " IDLE.";
  111.                               }
  112.                               Serial.print(kpd.key[i].kchar);
  113.                               Serial.print("Key ");
  114.                               Serial.print(kpd.key[i].kchar);
  115.                               Serial.println(msg);
  116.                           }
  117.                       }
  118.                   }
  119.               }  // End loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement