Julian Becker
Published

Shortcut Keyboard

Shortcut Keyboard powered by Seeed Studio XIAO RP2040 featuring 4 mechanical switches and a 1.47 inch LCD Display.

AdvancedShowcase (no instructions)1,745
Shortcut Keyboard

Things used in this project

Hardware components

Seeed XIAO RP2040
Seeed Studio Seeed XIAO RP2040
×1
1.47inch LCD Display Module
×1
MX1B-L2NA
×4
SK6812 2020
×6
Resistor 200 Ohm
×1
Resistor 1k
×4
Resistor 10k
×1
Diode 1N4007
×1
Capacitor 100nF
×7
TTP223 Touch-Module
×1

Software apps and online services

Fusion 360
Autodesk Fusion 360
Siemens Solid Edge
Keyshot
EasyEDA
Freerouting
Figma
ImageConverter565

Story

Read more

Custom parts and enclosures

3D Data

Schematics

Schematic

Code

Shortcut_Keyboard_1.ino

Arduino
//For the full code, visit the github repository 
//https://github.com/Beckju96/Shortcut_Keyboard

#include <TFT_eSPI.h> 
#include <Adafruit_NeoPixel.h>
#include "PluggableUSBHID.h"
#include "USBKeyboard.h"
#include "seeed_intro.h"
#include "Contest_Screen.h"

//Step 1: include pages here:
#include "page_1.h"
#include "page_2.h"
#include "page_3.h"
#include "page_4.h"

//Step 2: Define the number of pages (counting from 1 not 0):
int number_of_pages = 4;

//Step 3: Add all pages to the array:
const unsigned short* pages[] = {
  page_1, 
  page_2, 
  page_3, 
  page_4};


USBKeyboard Keyboard;

TFT_eSPI tft = TFT_eSPI(); 
TFT_eSprite screen = TFT_eSprite(&tft);

int touchpad = D2;
int buttonpin = A1;

//Step 4: Define the colors of the Neopixel LEDs when powering on
int r = 0;
int g = 0;
int b = 100;

//Step 5: Open Keyboard_Setup.ino 

///// Don't change the code below ////

int current_page = 1;
int z = 0;  //variable used for for swipe animation 

#define NUMPIXELS 6
int PIN = D3;
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);


void setup() {
  pinMode(touchpad, INPUT);
  pinMode(buttonpin, INPUT);
  pixels.begin();

  pixels.setPixelColor(0, pixels.Color(r/8, g/8, b/8));
  pixels.show();

  pinMode(D6, OUTPUT);
  digitalWrite(D6, LOW);
  tft.init();
  tft.setRotation(1);
  tft.fillScreen(TFT_BLACK);
  tft.setSwapBytes(true);
  digitalWrite(D6, HIGH);
  screen.createSprite(320, 172);
  screen.setSwapBytes(true);
  delay(2000);
  intro();
  delay(3000);
  tft.pushImage(0, 0, 320, 172, Contest_Screen);
  delay(3000);
  tft.pushImage(0, 0, 320, 172, pages[0]);
 }

void loop() {

  //void check_touchpad();

int buttonState = digitalRead(D2);

if(buttonState == 1)
{
  current_page = current_page +1;
  if(current_page==5)
  {
    current_page=1;
  }
   set_color(current_page);
   z = z+1;
   screenswipe();
  }

int buttonvalue = analogRead(buttonpin);

if(buttonvalue  > 100)
{
delay(20);
int buttonvalue = analogRead(buttonpin); //check Value again, to avoid wrong Readings

  if (buttonvalue >= 900)
{
  delay(20);
  buttonvalue = analogRead(A1);
  if (buttonvalue >= 900)
{
 send_key(1, current_page); 
  delay(200);
  }
}
if (buttonvalue <900 && buttonvalue >820)
{
  delay(20);
  buttonvalue = analogRead(A1);
  if (buttonvalue <900 && buttonvalue >820)
{
  send_key(2, current_page); 
  delay(200);
  }
}

if (buttonvalue <=820 && buttonvalue >760)
{
  delay(20);
  buttonvalue = analogRead(A1);
  if (buttonvalue <820 && buttonvalue >760)
{
  send_key(3, current_page); 
  delay(200);
  }  
}
  
if (buttonvalue <=760 && buttonvalue >700)
{
  delay(20);
  buttonvalue = analogRead(A1);
  if (buttonvalue <=760 && buttonvalue >700)
{
  send_key(4, current_page); 
  delay(200);
  } 
}

//signalize buttonpress by showing Neopixel Animation:  
for(int i=1; i<NUMPIXELS; i++) { // For each pixel...

    // pixels.Color() takes RGB values, from 0,0,0 up to 255,255,255
    // Here we're using a moderately bright green color:
    pixels.setPixelColor(i, pixels.Color(r, g, b));

    pixels.show();   // Send the updated pixel colors to the hardware.

    delay(30); // Pause before next pass through loop
}
  
for(int i=1; i<NUMPIXELS; i++) { // For each pixel...
  
    pixels.setPixelColor(i, pixels.Color(0, 0, 0));

    pixels.show();   // Send the updated pixel colors to the hardware.

    delay(20); // Pause before next pass through loop
}
    
  } 
}

void screenswipe()
{
int x = 0;
int y = 172;

if(z<number_of_pages){ 
  
while (x >-(172-40))
{
screen.pushImage(0, x, 320, 172, pages[z-1]);
screen.pushImage(0, y, 320, 172, pages[z]);
screen.pushSprite(0, 0);

x= x-40;
y= y-40;
delay(1);
}
screen.pushImage(0, -172, 320, 172, pages[z-1]);
screen.pushImage(0, 0, 320, 172, pages[z]);
screen.pushSprite(0, 0);


}

if(z==number_of_pages){  
while (x >-(172-40))
{
screen.pushImage(0, x, 320, 172, pages[z-1]);
screen.pushImage(0, y, 320, 172,pages[0]);
screen.pushSprite(0, 0);

x= x-40;
y= y-40;
delay(1);
}
screen.pushImage(0, -172, 320, 172, pages[z-1]);
screen.pushImage(0, 0, 320, 172, pages[0]);
screen.pushSprite(0, 0);

z=0;
}




}

void intro()
{
  int x = 70;
  tft.pushImage(0,0, 320, 172, seeed_1);
  delay(x);
  tft.pushImage(0,0, 320, 172, seeed_2);
  delay(x);
  tft.pushImage(0,0, 320, 172, seeed_3);
  delay(x);
  tft.pushImage(0,0, 320, 172, seeed_4);
  delay(x);
  tft.pushImage(0,0, 320, 172, seeed_5);
  delay(x);
  tft.pushImage(0,0, 320, 172, seeed_6);
  delay(x);
  tft.pushImage(0,0, 320, 172, seeed_7);
  delay(x);
  tft.pushImage(0,0, 320, 172, seeed_8);
  delay(x);
  tft.pushImage(0,0, 320, 172, seeed_9);
  delay(x);
  tft.pushImage(0,0, 320, 172, seeed_10);
}

Keyboard_Setup.ino

Arduino
//Step 6: set the color of the LEDs for each page:

void set_color(int page)
{
  if (page == 1)
  {
  r = 0;
  g = 0;
  b = 100;
  }
  if (page == 2)
  {
  r = 0;
  g = 100;
  b = 0;
  }
  if (page == 3)
  {
  r = 100;
  g = 0;
  b = 0;
  }
  if (page == 4)
  {
  r = 100;
  g = 100;
  b = 100;
  }

  pixels.setPixelColor(0, pixels.Color(r/8, g/8, b/8)); //decrease the brightness of the status LED
  pixels.show();

}


//Final Step: Define your shortcuts here 
//To add pages, just copy and paste additional if statements (page ==5 , page == 6, ...) and add the button definition:
//Example: Keyboard.key_code('s', KEY_CTRL); Keyboard.printf("a"); Keyboard.media_control(KEY_VOLUME_UP);

void send_key(int button, int page){

  if (page == 1)
  {
    if(button == 1)
    {
    Keyboard.key_code('c', KEY_CTRL);
    }
    if(button == 2)
    {
    Keyboard.key_code('y', KEY_CTRL);  
    }
    if(button == 3)
    {
    Keyboard.key_code('z', KEY_CTRL); 
    }
    if(button == 4)
    {
    Keyboard.key_code('v', KEY_CTRL); 
    }

  }

    if (page == 2)
  {
    if(button == 1)
    {
    Keyboard.key_code(KEY_F11);
    }
    if(button == 2)
    {
    Keyboard.key_code('e', KEY_LOGO);  
    }
    if(button == 3)
    {
    Keyboard.key_code('s', KEY_CTRL);   
    }
    if(button == 4)
    {
    Keyboard.key_code('f', KEY_CTRL);   
    }

  }
  if (page == 3)
  {
    if(button == 1)
    {
    Keyboard.key_code('t', KEY_CTRL);   
    }
    if(button == 2)
    {
    Keyboard.key_code(KEY_F5); 
    }
    if(button == 3)
    {
    Keyboard.key_code('l', KEY_LOGO);  
    }
    if(button == 4)
    {
    Keyboard.key_code('r', KEY_CTRL); 
    
    }

  }

  if (page == 4)
  {
    if(button == 1)
    {
    Keyboard.media_control(KEY_VOLUME_DOWN);
    delay(50);
    Keyboard.media_control(KEY_VOLUME_DOWN);

    }
    if(button == 2)
    {
    Keyboard.media_control(KEY_VOLUME_UP); 
    delay(50);
    Keyboard.media_control(KEY_VOLUME_UP);  
    }
    if(button == 3)
    {
    Keyboard.media_control(KEY_STOP);   
    }
    if(button == 4)
    {
    Keyboard.media_control(KEY_PLAY_PAUSE); 
    }

  }
  //add if statements here...

}

Shortcut_Keyboard

Credits

Julian Becker

Julian Becker

1 project • 1 follower

Comments