/***********************************************************************************************************************************
Code for PADys(micropad) with execories - go watch a video about it → SOON WILL BE SOME
Made by → Jendys/Jendyx in 2022
email→ korky707@gmail.com
PS:Make sure you are using Arduino Pro micro 5V Atmega 32U4 board with build in 5V USB controler, it will be much more easy.
***********************************************************************************************************************************/
#include "Keyboard.h" // keyboard(FX keys) library
#include <Keypad.h> // This library is for interfacing with the Matrix
#include <Mouse.h> // mouse move library
#include <SPI.h> // OLED
#include <Wire.h> // OLED
#include <Adafruit_GFX.h> // OLED
#include <Adafruit_SSD1306.h> // OLED
#include <HID-Project.h> // encoder library
#include <SimpleDHT.h> // include DHT
#define inputCLK 5 // Rotary Encoder Inputs on the board of the encoder
#define inputDT 6 // Rotary Encoder Inputs on the board of the encoder
#define inputSW 7 // Rotary Encoder Inputs on the board of the encoder
#define piezo 4 // PIEZO input pin 4
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1); //declaration for OLED
const byte ROWS = 3; // 6 rows
const byte COLS = 6; // 4 columns
char keys[ROWS][COLS] = {
{'Q', 'W', 'E', '7', '8', '9'}, // Matrix
{'A', 'S', 'D', '4', '5', '6'},
{'Y', 'X', 'C', '1', '2', '3'}, // these values need to be single character...
};
byte rowPins[ROWS] = {8, 9, 10, 16, 14, 15,}; //connect to the row pinouts of the keypad to arduino
byte colPins[COLS] = {18, 19, 20}; //connect to the column pinouts of the keypad to arduino
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void changeMode() { // changing mode of the ENCODER
mode = (mode % maxModes) + 1;
}
int currentStateCLK;
int previousStateCLK;
int modePushCounter = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int latButtonState = 0; // previous state of the button
int mouseMove;
int mode = 1; // modes of the ENCODER
int maxModes = 4; // modes of the ENCODER
const int ModeButton = 7; // the pin that the Modebutton is attached to
const int pot = A1; // pot for adjusting attract mode demoTime or mouseMouse pixel value
//const int Mode1= A2;
//const int Mode2= A3; //Mode status LEDs
void setup() {
Serial.begin(9600); // set serial being to 9600
pinMode(piezo, OUTPUT); // set piezo pin to output mode
pinMode (inputCLK,INPUT); // Set encoder pins as inputs
pinMode (inputDT,INPUT); // Set encoder pins as inputs
pinMode(inputSW, INPUT_PULLUP); //Set encoder pins as input_pullup
note(piezo, 261, 800); //C - play it
delay(500);
noTone(piezo); // do not play
delay(500);
note(piezo, 330, 800); //E
delay(500);
noTone(piezo);
note(piezo, 392, 800); //G
delay(500);
noTone(piezo);
note(piezo, 294, 800); //D
delay(500);
noTone(piezo);
note(piezo, 370, 800); //F#
delay(500);
noTone(piezo);
note(piezo, 440, 800); //A
delay(500);
noTone(piezo);
Consumer.begin(); // encoder
Keyboard.begin(); // encoder
previousStateCLK = digitalRead(inputCLK); // Assign to previousStateCLK variable // Read the initial state of inputCLK
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3D)) { // Address 0x3D for 128x64 or 0x3C for 128x32
Serial.println(F("SSD1306 allocation failed")); // OLED
for (;;); // Don't proceed, loop forever
}
display.clearDisplay(); //display Text
display.setTextSize(3);
display.setTextColor(WHITE);
display.setCursor(0,10);
display.print("PADys");
display.display();
display.setTextSize(1);
display.setCursor(0, 55);
display.print("Macro PAD by Jendys");
display.display();
delay(2000);
display.clearDisplay();
}
void loop() {
//ENCODER PART
currentStateCLK = digitalRead(inputCLK); // Read the current state of inputCLK
if (currentStateCLK != previousStateCLK){ // If the previous and the current state of the inputCLK are different then a pulse has occured
if (digitalRead(inputDT) != currentStateCLK) { // If the inputDT state is different than the inputCLK state then
rotateRight();
} else { // the encoder is rotating counterclockwise
rotateLeft();
}
}
previousStateCLK = currentStateCLK; // Update previousStateCLK with the current state
if(!digitalRead(inputSW)) { // changing mode and delay 300
changeMode();
delay(300);
}
}
void changeMode(){
mode = (mode % maxModes) + 1;
}
void rotateLRight() { // adding thinks to modes/case RIGHT ROTATE
switch(mode) {
case 1:
// Increase the volume
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0, 10);
display.print("VOLUME +");
Consumer.write(MEDIA_VOLUME_UP);
break;
case 2:
// WEB - GOOGLE - Cltr + TAB
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0, 10);
display.print("Tabs ->");
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_TAB);
Keyboard.releaseAll();
break;
case 3:
// Scroling
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0, 10);
display.print("Arrow Down");
Keyboard.write(KEY_UP_ARROW);
break;
case 4:
// Brush size
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0, 10);
display.print("Size +");
Keyboard.press('[ ');
break;
}
}
void rotateLeft() { // adding thinks to modes/case LEFT ROTATE
switch(mode) {
case 1:
// Decrease the volume
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0, 10);
display.print("VOLUME -");
Consumer.write(MEDIA_VOLUME_DOWN);
break;
case 2:
//Cltr + SHIFT + TAB
display.clearDisplay();
display.setTextSize(2));
display.setTextColor(WHITE);
display.setCursor(0, 10);
display.print("Tabs <-");
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_LEFT_SHIFT);
Keyboard.press(KEY_TAB);
Keyboard.releaseAll();
break;
case 3:
// Scroling
display.clearDisplay();
display.setTextSize(3);
display.setTextColor(WHITE);
display.setCursor(0, 10);
display.print("Arrow Up");
Keyboard.press(KEY_DOWN_ARROW);
break;
case 4:
// Brush size
display.clearDisplay();
display.setTextSize(3);
display.setTextColor(WHITE);
display.setCursor(0, 10);
display.print("Size - ");
Keyboard.press(']');
break;
}
}
// Keypad/MATRIX/Switches part
char key = keypad.getKey();
mouseMove = (analogRead(pot)); //reading the analog input, pot = pin A1
mouseMove = map(mouseMove, 0,1023, 1,124); //remap the analog pot values fron 1 to 124
checkModeButton();
switch (modePushCounter) { // switch between keyboard configurations:
case 0: //Application Alpha or MODE 0. Example = Every button ends your Zoom call
if (key) {
Serial.println(key);
switch (key) {
case '1':
KeyBoard.press(KEY_CONTROL);
KeyBoard.press(KEY_NUM1);
KeyBoard.releaseAll();
break;
case '2':
KeyBoard.press(KEY_CONTROL);
KeyBoard.press(KEY_NUM2);
KeyBoard.releaseAll();
break;
case '3':
KeyBoard.press(KEY_CONTROL);
KeyBoard.press(KEY_NUM3);
KeyBoard.releaseAll();
break;
case '4':
KeyBoard.press(KEY_CONTROL);
KeyBoard.press(KEY_NUM1);
KeyBoard.releaseAll();
break;
case '5':
KeyBoard.press(KEY_CONTROL);
KeyBoard.press(KEY_NUM1);
KeyBoard.releaseAll();
break;
case '6':
KeyBoard.press(KEY_CONTROL);
KeyBoard.press(KEY_NUM1);
KeyBoard.releaseAll();
break;
case '7':
break;
case '8'
break;
case '9':
break;
case 'Q':
break;
case 'W':
break;
case 'E':
break;
case 'A':
break;
case 'S':
break;
case 'D':
break;
case 'Y':
break;
case 'X':
break;
case 'C':
break;
}
delay(100);
Keyboard.releaseAll(); // this releases the buttons
}
break;
}