Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include ﹤Keypad.h﹥
- #include ﹤Keyboard.h﹥
- #include ﹤Encoder.h﹥
- #include ﹤Mouse.h﹥
- Encoder encTwo(A3, A2);
- Encoder encOne(A1, A0);
- const byte ROWS = 3; //four rows
- const byte COLS = 3; //three columns
- char keys[ROWS][COLS] = {
- {'1','2','3'},
- {'4','5','6'},
- {'7','8','9'}
- };
- char knees[9]= {97,98,99,100,101,102,103,104,105};
- byte rowPins[ROWS] = {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 );
- unsigned long loopCount;
- unsigned long startTime;
- String msg;
- int bbb;
- void setup() {
- Serial.begin(9600);
- loopCount = 0;d
- startTime = millis();
- msg = "";
- }
- long oldPosition1 = -999;
- long oldPosition2 = -999;
- int count = 0;
- int sped = 1; // controls speed of mouse movement
- void loop() {
- long newPosition1 = encOne.read();
- long newPosition2 = encTwo.read();
- if (count == 50) // slows scan rate (a debounce of sorts)
- {
- if (newPosition1 != oldPosition1)
- {
- if (newPosition1 ﹤ (oldPosition1))
- {
- Mouse.move(0, sped, 0);
- }
- else if ((newPosition1) ﹥ oldPosition1)
- {
- Mouse.move(0, -sped, 0);
- }
- oldPosition1 = newPosition1;
- Serial.println(newPosition1);
- }
- if (newPosition2 != oldPosition2)
- {
- if (newPosition2 ﹤ (oldPosition2))
- {
- Mouse.move(sped, 0, 0);
- }
- else if ((newPosition2) ﹥ oldPosition2)
- {
- Mouse.move(-sped, 0, 0);
- }
- oldPosition2 = newPosition2;
- Serial.println(newPosition2);
- }
- count = 0;
- }
- count++;
- loopCount++;
- if ( (millis()-startTime)>5000 ) {
- Serial.print("Average loops per second = ");
- Serial.println(loopCount/5);
- startTime = millis();
- loopCount = 0;
- }
- // 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.
- {
- switch (kpd.key[i].kstate) { // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
- case PRESSED:
- Serial.print(kpd.key[i].kchar);
- Keyboard.press(kpd.key[i].kchar+92);
- msg = " PRESSED.";
- break;
- case HOLD:
- Serial.print(kpd.key[i].kchar);
- msg = " HOLD.";
- break;
- case RELEASED:
- Keyboard.release(kpd.key[i].kchar+92);
- msg = " RELEASED.";
- break;
- case IDLE:
- Serial.print(kpd.key[i].kchar);
- msg = " IDLE.";
- }
- Serial.print(kpd.key[i].kchar);
- Serial.print("Key ");
- Serial.print(kpd.key[i].kchar);
- Serial.println(msg);
- }
- }
- }
- } // End loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement