Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1f5fcce287 | |||
| d8235a6534 | |||
| fe0b2112f4 | |||
| 082b434042 |
@ -2,32 +2,41 @@
|
|||||||
|
|
||||||
//Buttons go 1-4 from Top to bottom
|
//Buttons go 1-4 from Top to bottom
|
||||||
|
|
||||||
//This project uses an Arduino Pro Micro (also known as an Arduino Leonardo)
|
//This project uses an Arduino Pro Micro (also known as an Arduino Leonardo?)
|
||||||
|
|
||||||
|
//If using an clone arduino board, you may also need the USB driver from http://www.wch-ic.com/downloads/CH341SER_EXE.html before you will be able to upload
|
||||||
|
|
||||||
//Includes
|
//Includes
|
||||||
//These can be installed in the arduino IDE by clicking on tools in the top bar, then manage libraries.
|
//These can be installed in the arduino IDE by clicking on tools in the top bar, then manage libraries.
|
||||||
#include <EasyButton.h> //Used to define a button and debounces it
|
#include <EasyButton.h> //Used to define a button and debounces it
|
||||||
#include "HID-Project.h" //Lets us simulate keyboard presses.
|
#include "HID-Project.h" //Lets us simulate keyboard presses.
|
||||||
|
|
||||||
|
////////////////////////////////////
|
||||||
|
/////// PIN DEFINITIONS //////////
|
||||||
|
////////////////////////////////////
|
||||||
|
//These numbers refer to the physical GPIO pins on the board
|
||||||
|
|
||||||
//Pin Definitions. These numbers refer to the physical GPIO pins on the board
|
|
||||||
//LEDS
|
//LEDS
|
||||||
#define LED1 3
|
#define LED1 3
|
||||||
#define LED2 5
|
#define LED2 5
|
||||||
#define LED3 6
|
#define LED3 6
|
||||||
#define LED4 9
|
#define LED4 9
|
||||||
|
|
||||||
|
#define LED_TIME_OUT 10000 //How long it will take for the LEDs to turn off after a button press, in milliseconds
|
||||||
|
#define LED_MAX_BRIGHTNESS 100 //Max brightness of LEDs, from 0-255. Note that this is not really linear.
|
||||||
|
#define LED_MIN_BRIGHTNESS 100 //Min brightness of LEDs, from 0-255. Note that this is not really linear. 0 is off.
|
||||||
|
|
||||||
|
unsigned long ledTickTime = 0; //Time since the last time the LED state was updated
|
||||||
|
unsigned long lastPressTime = 0; //Time since the last button was pressed or released
|
||||||
|
uint8_t ledBrightness = 100; //Brightness that the LEDs should be aiming for
|
||||||
|
bool ledOn = false; //Should the LEDs turning/staying on or off
|
||||||
|
|
||||||
//Buttons
|
//Buttons
|
||||||
#define BUTTON1 A3
|
#define BUTTON1 A3
|
||||||
#define BUTTON2 A2
|
#define BUTTON2 A2
|
||||||
#define BUTTON3 A1
|
#define BUTTON3 A1
|
||||||
#define BUTTON4 A0
|
#define BUTTON4 A0
|
||||||
|
|
||||||
unsigned long ledTickTime = 0;
|
|
||||||
unsigned long lastPressTime = 0;
|
|
||||||
uint8_t ledBrightness = 100;
|
|
||||||
bool ledOn = false;
|
|
||||||
|
|
||||||
//Using the EasyButton library we create 4 buttons, with each button being connected to a GPIO pin as defined above, and having a 35ms debounce time. From memory, these do not have internal pullup resistors, and are not inverted. Hence the two falses.
|
//Using the EasyButton library we create 4 buttons, with each button being connected to a GPIO pin as defined above, and having a 35ms debounce time. From memory, these do not have internal pullup resistors, and are not inverted. Hence the two falses.
|
||||||
EasyButton button1(BUTTON1, 35, false, false);
|
EasyButton button1(BUTTON1, 35, false, false);
|
||||||
EasyButton button2(BUTTON2, 35, false, false);
|
EasyButton button2(BUTTON2, 35, false, false);
|
||||||
@ -67,8 +76,21 @@ void loop() {
|
|||||||
button3.read();
|
button3.read();
|
||||||
button4.read();
|
button4.read();
|
||||||
|
|
||||||
|
////////////////////////////////////
|
||||||
|
/////////// Buttons //////////////
|
||||||
|
////////////////////////////////////
|
||||||
|
|
||||||
//This should be pretty self explanitory. Make sure to always release a button.
|
//This should be pretty self explanitory. Make sure to always release a button.
|
||||||
|
|
||||||
|
/*
|
||||||
|
Also updates the lastPressTime on press and release.
|
||||||
|
If only release, then Lights wont turn on when pressed, and if only when pressed depending on hold length lights may turn off instantly after release.
|
||||||
|
Lights will not turn off while button is held, as lastPressTime will be updated each loop while button is pressed.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Depending on what you want to do, Keyboard.write() may be more useful to you than Keyboard.press(). Check the Keyboard library docs.
|
||||||
|
|
||||||
|
// 1st (Top) Button
|
||||||
if(button1.isPressed())
|
if(button1.isPressed())
|
||||||
{
|
{
|
||||||
Keyboard.press(KEY_LEFT_ALT);
|
Keyboard.press(KEY_LEFT_ALT);
|
||||||
@ -81,6 +103,7 @@ void loop() {
|
|||||||
lastPressTime = millis();
|
lastPressTime = millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 2nd Button
|
||||||
if(button2.isPressed())
|
if(button2.isPressed())
|
||||||
{
|
{
|
||||||
Keyboard.press(KEY_LEFT_CTRL);
|
Keyboard.press(KEY_LEFT_CTRL);
|
||||||
@ -93,6 +116,7 @@ void loop() {
|
|||||||
lastPressTime = millis();
|
lastPressTime = millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 3rd Button
|
||||||
if(button3.isPressed())
|
if(button3.isPressed())
|
||||||
{
|
{
|
||||||
Keyboard.press(KEY_LEFT_SHIFT);
|
Keyboard.press(KEY_LEFT_SHIFT);
|
||||||
@ -105,6 +129,7 @@ void loop() {
|
|||||||
lastPressTime = millis();
|
lastPressTime = millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 4th (Bottom) Button
|
||||||
if(button4.isPressed())
|
if(button4.isPressed())
|
||||||
{
|
{
|
||||||
Keyboard.press(KEY_SPACE);
|
Keyboard.press(KEY_SPACE);
|
||||||
@ -117,7 +142,12 @@ void loop() {
|
|||||||
lastPressTime = millis();
|
lastPressTime = millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
if((millis() - lastPressTime) > 10000)
|
////////////////////////////////////
|
||||||
|
/////////// Lights ///////////////
|
||||||
|
////////////////////////////////////
|
||||||
|
|
||||||
|
//If the time between now and the last time the buttons were pushed is greater than the time set in LED_TIME_OUT, set the LEDs to turn off, otherwise turn them on.
|
||||||
|
if((millis() - lastPressTime) > LED_TIME_OUT)
|
||||||
{
|
{
|
||||||
ledOn = false;
|
ledOn = false;
|
||||||
}
|
}
|
||||||
@ -126,28 +156,27 @@ void loop() {
|
|||||||
ledOn = true;
|
ledOn = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((millis() - ledTickTime) > 10)
|
//This part fades the LEDs to their new state
|
||||||
|
if ((millis() - ledTickTime) > 10) //Update brightness every 10 milliseconds
|
||||||
{
|
{
|
||||||
ledTickTime = millis();
|
ledTickTime = millis();
|
||||||
if(!ledOn && (ledBrightness > 0))
|
|
||||||
|
//If led turning off, and brightness is still not low enough, decrement brihtness by 1
|
||||||
|
if(!ledOn && (ledBrightness > LED_MIN_BRIGHTNESS))
|
||||||
{
|
{
|
||||||
ledBrightness=ledBrightness-1;
|
ledBrightness=ledBrightness-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(ledOn && (ledBrightness < 100))
|
//If led turning on, and brightness is still not high enough, increment brihtness by 10
|
||||||
|
else if(ledOn && (ledBrightness < LED_MAX_BRIGHTNESS))
|
||||||
{
|
{
|
||||||
ledBrightness=ledBrightness+10;
|
ledBrightness=ledBrightness+10; //Making this 10 instead of 1 means it will fade in faster than it fades out. Easier than making another setup with another ledTickTime2 or something variable.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Set new brightness on pins
|
||||||
analogWrite(LED1, ledBrightness);
|
analogWrite(LED1, ledBrightness);
|
||||||
analogWrite(LED2, ledBrightness);
|
analogWrite(LED2, ledBrightness);
|
||||||
analogWrite(LED3, ledBrightness);
|
analogWrite(LED3, ledBrightness);
|
||||||
analogWrite(LED4, ledBrightness);
|
analogWrite(LED4, ledBrightness);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Serial.print("Led Brightness = ");
|
|
||||||
// Serial.print(ledBrightness);
|
|
||||||
// Serial.print("\t Led State = ");
|
|
||||||
// Serial.println(ledOn);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
10
README.md
10
README.md
@ -0,0 +1,10 @@
|
|||||||
|
Basic 4 button keypad with 3d printable case
|
||||||
|
|
||||||
|
# PCB
|
||||||
|
**Files Currently Lost**
|
||||||
|
|
||||||
|
# Code
|
||||||
|
.ino File
|
||||||
|
|
||||||
|
# Case
|
||||||
|
3 Files, top bottom and button. Print Button 4 times. I recomend doing most of the button in a transparent filament, then the last top few in what every color works for you.
|
||||||
Loading…
x
Reference in New Issue
Block a user