#include "definition.h"
#include "layout.h"
Layout layout;
int longPressDelay = 350; //customizable encoderValues
int spamSpeed = 15;
int rowval=2;
int colval=4;
char KEY_SPACE = ' ';
byte inputs[] = {3, 4, 5, 6}; //declaring inputs and outputs
const int inCount = sizeof(inputs)/sizeof(inputs[0]);
byte outputs[] = {12,13};
const int outCount = sizeof(outputs)/sizeof(outputs[0]);
int keyDown[2][4];
bool keyLong[2][4];
int PCursor;
void setup() {
layout = layout1;
PCursor = 0;
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32-S2!");
uint16_t time = millis();
for(int i=0; i<outCount; i++){ //declaring all the outputs and setting them high
pinMode(outputs[i],OUTPUT);
digitalWrite(outputs[i],HIGH);
}
for(int i=0; i<inCount; i++){ //declaring all the inputs and activating the internal pullup resistor
pinMode(inputs[i],INPUT_PULLUP);
}
/*for (int i = 0; i < ROWS; i++) {
pinMode(rowPins[i], INPUT_PULLDOWN);
}
for (int i = 0; i < COLS; i++) {
pinMode(colPins[i], OUTPUT);
digitalWrite(colPins[i], LOW);
}*/
time = millis() - time;
}
void loop() {
//digitalWrite(LED_BUILTIN, HIGH);
//delay(1000); // wait for a second
//digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
//delay(1000);
for (int i=0; i<rowval; i++)
{
digitalWrite(outputs[i],LOW); //setting one row low
delayMicroseconds(5); //giving electronics time to settle down
for(int j=0; j<colval; j++)
{
if(digitalRead(inputs[j]) == LOW)
{
keyPressed(i,j); //calling keyPressed function if one of the inputs reads low
}
else if(keyDown[i][j] != 0) //resetting the key if it is not pressed any more
{
resetKey(i,j);
}
}
digitalWrite(outputs[i],HIGH);
delayMicroseconds(500); //setting the row high and waiting 0.5ms until next cycle
}
}
//if a key is pressed, this Funtion is called and outputs to serial the key location, it also sends the keystroke if not already done so
void keyPressed(int row, int col){
/*Serial.print("Output: ");
Serial.print(row);
Serial.print(" Input: ");
Serial.print(col);
Serial.print(" ");
Serial.println(customKey[row][col]);*/
PCursor = PCursor + 1;
if(keyDown[row][col]==0){
Serial.println(customKey[row][col]); //if the function is called for the first time for this key
Serial.println(" First ");
delay(10);
}
else if(keyLong[row][col] && keyDown[row][col] > spamSpeed){ //if the key has been held long enough to warrant another keystroke set
//Serial.println(" Holded ");
keyDown[row][col] = 1;
}
else if(keyDown[row][col] > longPressDelay){ //if the key has been held for longer that longPressDelay, it switches into spam mode
keyLong[row][col] = true;
}
keyDown[row][col]++;
}
void resetKey(int row, int col){ //resetting the variables after key is released
keyDown[row][col] = 0;
keyLong[row][col] = false;
}
Loading
esp32-s2-devkitm-1
esp32-s2-devkitm-1