sir,
i made this sketch for Teensy LC board. using keypad library.
2&3 pins are on Rotatry Encoder.encoder is working good according to Sketch.
please look a bit on My sketch and attachment image .
#include <Keypad.h>
#include <Encoder.h>
const byte ROWS = 3; //four rows
const byte COLS = 12; //four columns
char keys[ROWS][COLS] = {
{1,2,3,4,5,6,7,8,9,10,11,12},
{13,14,15,16,17,18,19,20,21,22,23,24},
{25,26,27,28,29,30,31,32,33,34,35,36}
};
byte rowPins[ROWS] = {4, 5, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18}; //connect to the column pinouts of the keypad
//initialize an instance of class NewKeypad
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
Encoder myEnc(2, 3); // which pins are connected to Encoder
String msg;
void setup() {
Mouse.screenSize(1366, 768); // Screen resolutions of your display (check from control panel)
Serial.begin(9600);
msg = "";
}
long oldPosition = -999;
void loop() {
long newPosition = myEnc.read(); // -----------------------------------------------------------------------------------------------------------------------------------------
if (newPosition > oldPosition) {
oldPosition = newPosition;
Mouse.moveTo(512, 54); // put here action to be, when Encoder is rotated upward
Mouse.scroll(-1);
Mouse.moveTo(345, 94);
}
if (newPosition < oldPosition) {
oldPosition = newPosition;
Mouse.moveTo(512, 54); // put here action to be, when Encoder is rotated Downward
Mouse.scroll(+1);
Mouse.moveTo(345, 94);
} // ----------------------------------------------------------------------------------------------------------------------------------------- -----------------------------
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:
msg = " PRESSED.";
break;
case HOLD:
msg = " HOLD.";
break;
case RELEASED:
msg = " RELEASED.";
break;
case IDLE:
msg = " IDLE.";
}
Serial.print("Key ");
Serial.print(kpd.key[i].kchar);
Serial.println(msg);
}
}
}
}
when 3rd rowPIN6 is connected to 11th colPIN17 or 12th colPIN18, output is coming like ($,#,") instead of 35 and 36.
please find where is wrong?????