Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1f5fcce287 | |||
| d8235a6534 | |||
| fe0b2112f4 | |||
| 082b434042 |
@ -1,105 +1,51 @@
|
||||
//#########################################################################################################
|
||||
//# PROGRAM NAME: 'ClareButtons'
|
||||
//#########################################################################################################
|
||||
//# Purpose : Controlled by an Arduino Board, this code programs preset actions on up to 6 Buttons (currently only 4 defined).
|
||||
//# For example, the buttons may be defined as:
|
||||
//# * 'Keyboard Keys' (eg. Ctrl, Alt, Shift)
|
||||
//# * 'KeyBoard combinations' shortcuts (eg. Crtl + C, Crtl + V)
|
||||
//# * 'Whole Text' (eg. "Hello World")
|
||||
//# Code Type : MAIN PROGRAM: C - Arduino Leonardo (Arduino IDE)
|
||||
//# Usage : Ideal for one-handed keyboard usage
|
||||
//# Prereqs : 1) May Require 'USB Driver' for Arduio Board (Chinese Board):
|
||||
//# * CH341SER_EXE (from http://www.wch-ic.com/downloads/CH341SER_EXE.html)
|
||||
//# 2) Requires 'Board' Selection via Tools > Board: If the Board is not in the dropdown list the install\update via 'Tools > Board > Board Manager'.
|
||||
//# * Arduino Leonardo (Arduino Pro Micro)
|
||||
//# 3) Requires 'Port' to be specified. 'Tools > Port' (The 'Board' should be clearly identified with the corresponding Port):
|
||||
//# * eg. COM3(Arduino Leonardo)
|
||||
//# 4) Requires 'Librarys' to be Installed via 'Sketch > Incldue Library > Manage Libraries':
|
||||
//# * EasyButton.h
|
||||
//# * HID-Project.h
|
||||
//# Author(s) : Zachery Seibel-Barnes and Anthony Seibel-Barnes
|
||||
//# Date : 23/09/2022 (Ver 2.2)
|
||||
//# Notes : 1) Hardware: Buttons are defined as '1' to '4' from Top (furthest from USB lead) to Bottom (closest to USB lead)
|
||||
//# 2) IMPORTANT: A 'Button Press' action needs to have corresponding a 'Button Release' action (either 'implicidly defined' or as a generic 'release all')
|
||||
//# 2) Testing: To check parameters values (as generated by run code), use 'Serial Monitor' (Ctrl+Shft+M). Examples:
|
||||
//# Serial.print("Led Brightness = ");
|
||||
//# Serial.print(ledBrightness);
|
||||
//# Serial.print("\t Led State = ");
|
||||
//# Serial.println(ledOn);
|
||||
//#########################################################################################################
|
||||
//Recommend reading: https://www.arduino.cc/reference/en/
|
||||
|
||||
//Buttons go 1-4 from Top to bottom
|
||||
|
||||
//*********************************************
|
||||
//*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
|
||||
//* INITIALISE *
|
||||
//*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
|
||||
//*********************************************
|
||||
//This project uses an Arduino Pro Micro (also known as an Arduino Leonardo?)
|
||||
|
||||
//////////////////////
|
||||
// LIBRARIES //
|
||||
//////////////////////
|
||||
//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
|
||||
//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 "HID-Project.h" //Lets us simulate keyboard presses.
|
||||
|
||||
//////////////////////
|
||||
// DEFINITIONS //
|
||||
//////////////////////
|
||||
//These PIN numbers refer to the physical GPIO pins on the board.
|
||||
////////////////////////////////////
|
||||
/////// PIN DEFINITIONS //////////
|
||||
////////////////////////////////////
|
||||
//These numbers refer to the physical GPIO pins on the board
|
||||
|
||||
//LEDS
|
||||
#define LED1 3
|
||||
#define LED2 5
|
||||
#define LED3 6
|
||||
#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
|
||||
#define BUTTON1 A3
|
||||
#define BUTTON2 A2
|
||||
#define BUTTON3 A1
|
||||
#define BUTTON4 A0
|
||||
|
||||
//////////////////////
|
||||
// Global Constants //
|
||||
//////////////////////
|
||||
const int cintLedOffTime = 10000; //LED 'OFF' time (milliseconds) is how long LED will remain on for after a button was pressed (For reference: 60,000 = 1 minute). This only relevant if 'cblnLEDsToDimCycle = False'.
|
||||
const int cintLedMaxBrightness = 100; //LED Maximum brightness level (0 will be off, and 255 is brightest... like the SUN !!)
|
||||
const int cintLedMinBrightness = 1; //LED Minimum brightness level (0 will be off, and 255 is brightest)
|
||||
const int cintLedDimmerStepTime = 100; //Time interval for LED Dimmer (milliseconds) (Higher=slow fade ; Lower=quick fade). NOTE: 'cintLedDimmerStep' is relative (linked) to this & will also influence how fast/slow actions occur.
|
||||
const int cintLedDimmerStep = 1; //Step interval for LED Dimmer (1=very smooth fades ; >10=stepped fades). NOTE: 'cintLedDimmerStepTime' is relative (linked) to this and will also influence how fast/slow this action occurs.
|
||||
const bool cblnLEDsToDimCycle = true; //Used to set when 'LEDs' are required to CYCLE back to Max after the LEDs are Minimised - even when NO Button Activity has occurred.
|
||||
//When TRUE, it will (forever) cycle LEDS brightness - GRADUALLY cycling UP (using cintLedDimmerStep) from 'Mimimum' (cintLedMinBrightness) to 'Max ' (cintLedMaxBrightness),
|
||||
//then 'Dimming' back down to the Mimimum.
|
||||
//Whem FALSE, the LEDs will simply Dim to the Minimum (cintLedMinBrightness) until next button press.
|
||||
const int cintDebounceTime = 180; //DebounceTime (milliseconds) is used with the 'Delay' function to pause code after a button press. This helps to slow 'extra' commands from
|
||||
//a Button like 'PASTING repeated data'). Increase the 'time' if wishing to 'hold' an action from happening (or repeating) for longer.
|
||||
//This is currently only used when 'blnDelayActions' is set to 'true'. If it is 'false', then the delay is effectively 'zero'.
|
||||
//////////////////////
|
||||
// Global Variables //
|
||||
//////////////////////
|
||||
unsigned long ledTickTime = 0;
|
||||
unsigned long lastPressTime = 0;
|
||||
uint8_t ledBrightness = cintLedMaxBrightness;
|
||||
bool blnLEDsOn = true; //Used to flag when 'LEDs' are ON at any Brightness level (ie. when LEDs are NOT off). Initated to True for initial illumination.
|
||||
bool blnButtonActivty = false; //Used to flag when a Button action has actually occured. This is used primarily so it can correctly turn off LEDs after the specified activity time (ie. indirectly works with 'cintLedOffTime')
|
||||
bool blnLEDsAreCyclingUp = false; //Only used when 'cblnLEDsDimCycle' is TRUE - It identifies when LEDs are in the process of 'Cycling UP' (to LEDs Max On) or when False they will 'Cycle Down' first.
|
||||
|
||||
//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 button2(BUTTON2, 35, false, false);
|
||||
EasyButton button3(BUTTON3, 35, false, false);
|
||||
EasyButton button4(BUTTON4, 35, false, false);
|
||||
|
||||
//*********************************************
|
||||
//*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
|
||||
//* MAIN *
|
||||
//*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
|
||||
//*********************************************
|
||||
//Standard Arduino setup function. Code that only needs to 'run once' goes here.
|
||||
void setup()
|
||||
{
|
||||
// Send a clean report to the host. This is important on any Arduino type.
|
||||
//Standard Arduino setup function. Code that only needs to run once goes here
|
||||
void setup() {
|
||||
Keyboard.begin();
|
||||
Keyboard.end();
|
||||
|
||||
//LEDS - Setting the LED pins to be outputs. Normally, the buttons would be set as inputs, but they are handled by that library.
|
||||
pinMode(LED1, OUTPUT);
|
||||
@ -107,7 +53,7 @@ void setup()
|
||||
pinMode(LED3, OUTPUT);
|
||||
pinMode(LED4, OUTPUT);
|
||||
|
||||
//Here we output a PWM signal to the LEDs. This is the INITIAL LEDs illumination when the device is plugged in (prior to any button actions or dimming checks occur).
|
||||
//Here we output a PWM signal to the LEDs, where 0 will be off, and 255 is brightest
|
||||
analogWrite(LED1, ledBrightness);
|
||||
analogWrite(LED2, ledBrightness);
|
||||
analogWrite(LED3, ledBrightness);
|
||||
@ -120,15 +66,9 @@ void setup()
|
||||
button4.begin();
|
||||
}
|
||||
|
||||
//*********************************************
|
||||
//*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
|
||||
//* MAIN LOOP *
|
||||
//*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
|
||||
//*********************************************
|
||||
//Code that is 'runs constantly' goes here.
|
||||
|
||||
//Code that is run constantly goes here
|
||||
void loop() {
|
||||
//Reset 'Button Activity' flag (when False it sits in a wait-state for someone to press a button)
|
||||
blnButtonActivty=false;
|
||||
|
||||
//Read all the buttons
|
||||
button1.read();
|
||||
@ -136,374 +76,107 @@ void loop() {
|
||||
button3.read();
|
||||
button4.read();
|
||||
|
||||
//---------------------------------
|
||||
//--- Button Activity ---
|
||||
//---------------------------------
|
||||
////////////////////////////////////
|
||||
/////////// Buttons //////////////
|
||||
////////////////////////////////////
|
||||
|
||||
//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())
|
||||
{
|
||||
blnButtonActivty = ButtonPressAction(1);
|
||||
Keyboard.press(KEY_LEFT_ALT);
|
||||
lastPressTime = millis();
|
||||
}
|
||||
|
||||
else if(button1.wasReleased())
|
||||
{
|
||||
blnButtonActivty = ButtonReleaseAction(1,true);
|
||||
Keyboard.release(KEY_LEFT_ALT);
|
||||
lastPressTime = millis();
|
||||
}
|
||||
|
||||
// 2nd Button
|
||||
if(button2.isPressed())
|
||||
{
|
||||
blnButtonActivty = ButtonPressAction(2);
|
||||
Keyboard.press(KEY_LEFT_CTRL);
|
||||
lastPressTime = millis();
|
||||
}
|
||||
|
||||
else if(button2.wasReleased())
|
||||
{
|
||||
blnButtonActivty = ButtonReleaseAction(2,true);
|
||||
Keyboard.release(KEY_LEFT_CTRL);
|
||||
lastPressTime = millis();
|
||||
}
|
||||
|
||||
// 3rd Button
|
||||
if(button3.isPressed())
|
||||
{
|
||||
blnButtonActivty = ButtonPressAction(3);
|
||||
Keyboard.press(KEY_LEFT_SHIFT);
|
||||
lastPressTime = millis();
|
||||
}
|
||||
|
||||
else if(button3.wasReleased())
|
||||
{
|
||||
blnButtonActivty = ButtonReleaseAction(3,true);
|
||||
Keyboard.release(KEY_LEFT_SHIFT);
|
||||
lastPressTime = millis();
|
||||
}
|
||||
|
||||
// 4th (Bottom) Button
|
||||
if(button4.isPressed())
|
||||
{
|
||||
blnButtonActivty = ButtonPressAction(4);
|
||||
Keyboard.press(KEY_SPACE);
|
||||
lastPressTime = millis();
|
||||
}
|
||||
|
||||
else if(button4.wasReleased())
|
||||
{
|
||||
blnButtonActivty = ButtonReleaseAction(4,false);
|
||||
Keyboard.release(KEY_SPACE);
|
||||
lastPressTime = millis();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
//--- LED Illumination: Full ON (when Button Activity) ---
|
||||
//---------------------------------------------------------
|
||||
// Check if a 'Button action' has recently occurred.
|
||||
switch (blnButtonActivty)
|
||||
////////////////////////////////////
|
||||
/////////// 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)
|
||||
{
|
||||
case true:
|
||||
// A 'Button Activty' HAS occurred.
|
||||
|
||||
//Reset the 'lastPressTime' timer variable to current time(r).
|
||||
lastPressTime = millis();
|
||||
|
||||
//Increase LEDs to 'MAX Brightness'
|
||||
if(ledBrightness < cintLedMaxBrightness)
|
||||
{
|
||||
ledBrightness = cintLedMaxBrightness;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
// A 'Button Activty' HAS NOT Occurred. No need to do anything - This will also retain the 'lastPressTime' time value.
|
||||
break;
|
||||
ledOn = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
ledOn = true;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
//--- LED Illumination: Minimised or DIMMING CYCLING ---
|
||||
//---------------------------------------------------------
|
||||
if((millis() - lastPressTime) > cintLedOffTime)
|
||||
//This part fades the LEDs to their new state
|
||||
if ((millis() - ledTickTime) > 10) //Update brightness every 10 milliseconds
|
||||
{
|
||||
//The maximun 'LED on' time has elapsed since the last Button Press (or initial on). Check if 'Dimming Cycling' is set to occur, otherwise simply MINIMISE LEDs.
|
||||
ledTickTime = millis();
|
||||
|
||||
switch (cblnLEDsToDimCycle) //Global Constant 'cblnLEDsToDimCycle' determines if 'DIMMING CYCLING' occurs.
|
||||
//If led turning off, and brightness is still not low enough, decrement brihtness by 1
|
||||
if(!ledOn && (ledBrightness > LED_MIN_BRIGHTNESS))
|
||||
{
|
||||
case true:
|
||||
//Call LED Dimming function (to Cycle LED Brightness)
|
||||
ledBrightness = GetLEDsDimCycleValue(ledBrightness);
|
||||
break;
|
||||
case false:
|
||||
//If LEDs are ON (at ANY Brightness level ... LEDS should now be MINIMISED.
|
||||
if(blnLEDsOn)
|
||||
{
|
||||
//MINIMISE LEDs: MAX time has ELAPSED for LEDs to be on Max Brightness.
|
||||
lastPressTime = 0; //Reset for 'No Button Activity'
|
||||
ledBrightness = cintLedMinBrightness; //Set LEDs to 'Minimum Brightness'
|
||||
}
|
||||
break;
|
||||
default:
|
||||
//Should not ever get here, but 'break' out just in case.
|
||||
break;
|
||||
ledBrightness=ledBrightness-1;
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
//--- WRITE LED Values ---
|
||||
//---------------------------------------------------------
|
||||
if (blnLEDsOn)
|
||||
{
|
||||
//Write LED brightness level to the LEDs.
|
||||
//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; //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(LED2, ledBrightness);
|
||||
analogWrite(LED3, ledBrightness);
|
||||
analogWrite(LED4, ledBrightness);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
//--- RESET LED Variables for MAIN LOOP ---
|
||||
//---------------------------------------------------------
|
||||
if(ledBrightness > cintLedMinBrightness)
|
||||
{
|
||||
//LED's ON:
|
||||
if (!blnLEDsOn)
|
||||
{
|
||||
blnLEDsOn=true;
|
||||
}
|
||||
}
|
||||
else if(ledBrightness <= cintLedMinBrightness)
|
||||
{
|
||||
//LED's at MINIMUM: Minimun LED Brightness has been reached (this is considered as 'LED Off', but they may not be FULLY Off - it depends on the constant cintLedMinBrightness)
|
||||
if (blnLEDsOn)
|
||||
{
|
||||
blnLEDsOn = false;
|
||||
}
|
||||
|
||||
if (cblnLEDsToDimCycle)
|
||||
{
|
||||
//Reset the flag to begin 'LED cycle Up' process (This is only relevant when cblnLEDsToDimCycle = true)
|
||||
blnLEDsAreCyclingUp = true;
|
||||
}
|
||||
}
|
||||
// LOOP MAIN
|
||||
}
|
||||
|
||||
|
||||
//********************************************************************************************
|
||||
//* FUNCTION NAME: 'ButtonPressAction'
|
||||
//********************************************************************************************
|
||||
//* Purpose : Performs pre-defined action(s) when an Arduino Board button is PRESSED.
|
||||
//* Code Type : FUCTION CALL: C - Arduino Leonardo (Arduino IDE)
|
||||
//* Usage : Can be called anytime. Function call example: blnButtonActivty = ButtonPressAction(1);
|
||||
//* Where: * 'ButtonPressAction(1)' specifies the button for which the defined action(s) will execute.
|
||||
//* * 'blnButtonActivty' receives the return result (treated as 'success' or 'fail'). It should
|
||||
//* only fail when the 'Button ID is not 1-6'.
|
||||
//* Returns : 'True' if successful, otherwise 'False' where button is undefined.
|
||||
//* Parameters: 'intButtonNumber' - Corresponds to the Arduino Board button ID number.
|
||||
//* Prereqs : Requires the following Libraries set in the Main (Libraries) Code:
|
||||
//* *Keyboard Libray - HID-Project.h
|
||||
//* Requires the following GLOBAL Contants or Variables set in the Main (Initialisation) Code:
|
||||
//* * Constant 'cintDebounceTime' specifies DELAY before preformaing additional buttion actions.
|
||||
//* Author : A. Seibel-Barnes (from original source by Z. Seibel-Barnes)
|
||||
//* Date : 17/09/2022 (Ver 1.0)
|
||||
//* Notes : 'Keyboard.press' code options (examples for reference)
|
||||
//* * Keyboard.press(KEY_LEFT_CTRL)
|
||||
//* * Keyboard.press(KEY_LEFT_ALT)
|
||||
//* * Keyboard.press(KEY_LEFT_SHIFT)
|
||||
//'**********************************************************************************************
|
||||
bool ButtonPressAction(int intButtonNumber)
|
||||
{
|
||||
bool blnButtonActioned = false;
|
||||
bool blnDelayActions = false; //Used to SLOW 'button actions' from repeating (ie. it is a simple debounce to retard 'extra' or 'unwanted' actions from Buttons).
|
||||
|
||||
// Perform 'Button PRESS' action
|
||||
switch (intButtonNumber)
|
||||
{
|
||||
case 1:
|
||||
// DEFINITION: PASTE COMMAND (Ctrl+v)
|
||||
Keyboard.press(KEY_LEFT_CTRL);
|
||||
Keyboard.write('v');
|
||||
blnDelayActions = true;
|
||||
blnButtonActioned = true;
|
||||
break;
|
||||
case 2:
|
||||
// DEFINITION: COPY COMMAND (Ctrl+c)
|
||||
Keyboard.press(KEY_LEFT_CTRL);
|
||||
Keyboard.write('c');
|
||||
blnDelayActions = false;
|
||||
blnButtonActioned = true;
|
||||
break;
|
||||
case 3:
|
||||
// DEFINITION: 'SHIFT' KEY (Only)
|
||||
Keyboard.press(KEY_LEFT_SHIFT);
|
||||
blnDelayActions = false;
|
||||
blnButtonActioned = true;
|
||||
break;
|
||||
case 4:
|
||||
// DEFINITION: CUSTOM TEXT (Message)
|
||||
//Keyboard.println("Hi");
|
||||
//Keyboard.println;
|
||||
Keyboard.print("Tracking progress applies on business days as it processes through Postal and Customs facilities.");
|
||||
//Keyboard.println("Just confirming that your item is in the mail (and may have already been delivered)... See pics.");
|
||||
//Keyboard.println();
|
||||
//Keyboard.println("Tracking is available via Australia Post: TMP40083004070052454xxxxx");
|
||||
//Keyboard.println("Tracking progress applies on business days as it processes through Australia Post facilities..");
|
||||
//Keyboard.println();
|
||||
//Keyboard.print("Thank-you and All the best ;)");
|
||||
blnDelayActions = true;
|
||||
blnButtonActioned = true;
|
||||
break;
|
||||
case 5:
|
||||
// DEFINITION: TBA
|
||||
blnDelayActions = false;
|
||||
blnButtonActioned = true;
|
||||
break;
|
||||
case 6:
|
||||
// DEFINITION: TBA
|
||||
blnDelayActions = false;
|
||||
blnButtonActioned = true;
|
||||
break;
|
||||
default:
|
||||
//Returns a 'fail' if the 'Button ID' was not specified between 1-6.
|
||||
break;
|
||||
}
|
||||
|
||||
// Check if a 'Pause' is required while performing 'Button' action(s): This stops (or rather 'SLOWS') 'repeated button actions' if a button is 'held down too long' (eg. helps stop extra 'PASTE data' commands)
|
||||
switch (blnDelayActions)
|
||||
{
|
||||
case true:
|
||||
// Pause
|
||||
delay(cintDebounceTime);
|
||||
blnDelayActions = false;
|
||||
break;
|
||||
default:
|
||||
// No Delay, or maybe repeat action(s)
|
||||
delay(0);
|
||||
break;
|
||||
}
|
||||
|
||||
//Return the fuctions result
|
||||
return blnButtonActioned;
|
||||
}
|
||||
|
||||
|
||||
//********************************************************************************************
|
||||
//* FUNCTION NAME: 'ButtonReleaseAction'
|
||||
//********************************************************************************************
|
||||
//* Purpose : Performs pre-defined action(s) when an Arduino Board button is RELEASED.
|
||||
//* Code Type : FUCTION CALL: C - Arduino Leonardo (Arduino IDE)
|
||||
//* Usage : Can be called anytime. Function call example: blnButtonActivty = ButtonReleaseAction(1,false);
|
||||
//* Where: * 'ButtonReleaseAction(1,false)' specifies the button for which the implicidly defined Key-release action(s) will execute (when false specified). Or,
|
||||
//* (when true) 'Releases ALL keys' irrelevant of which 'Button ID' was released.
|
||||
//* * 'blnButtonActivty' receives the return result (treated as 'success' or 'fail'). Should only fail when 'blnReleaseALLKeys is false' AND the 'Button ID is not 1-6'.
|
||||
//* Returns : 'True' if successful, otherwise 'False' where button is undefined.
|
||||
//* Parameters: 'intButtonNumber' - Corresponds to the Arduino Board 'Button ID' number (1-6)
|
||||
//* 'blnReleaseALLKeys' - When 'true' it simply 'Releases ALL Keys' (and ignores the 'Button ID' since there are no specific Key-release requirements).
|
||||
//* When 'false' it requires that specific Key(s) are implicidly released.
|
||||
//* Prereqs : Keyboard Library (HID-Project.h) should be set in the Main (Libraries) Code.
|
||||
//* Author : A. Seibel-Barnes (from original source by Z. Seibel-Barnes)
|
||||
//* Date : 17/09/2022 (Ver 1.0)
|
||||
//* Notes : 'Keyboard.release' code options (for use when blnReleaseALLKeys = false)
|
||||
//* * Keyboard.release(KEY_SPACE)
|
||||
//* * Keyboard.release(KEY_LEFT_CTRL)
|
||||
//'**********************************************************************************************
|
||||
bool ButtonReleaseAction(int intButtonNumber, bool blnReleaseALLKeys)
|
||||
{
|
||||
bool blnButtonActioned = false;
|
||||
|
||||
// Check if ALL Keyboard Keys should now be released (Usually 'true', but perhaps 'false' if 'multi-button hold combinations' are required)
|
||||
switch (blnReleaseALLKeys)
|
||||
{
|
||||
case true:
|
||||
// SIMPLE - 'Release 'ALL Keyboard Keys' (this should almost always be the case).
|
||||
Keyboard.releaseAll();
|
||||
blnButtonActioned = true;
|
||||
break;
|
||||
default:
|
||||
// SPECIFIC - 'Implicidly set what Key(s)' need to be released. This is REQUIRED when Key-hold combination are required.
|
||||
switch (intButtonNumber)
|
||||
{
|
||||
case 1:
|
||||
// DEFINITION: TBA
|
||||
blnButtonActioned = true;
|
||||
break;
|
||||
case 2:
|
||||
// DEFINITION: TBA
|
||||
blnButtonActioned = true;
|
||||
break;
|
||||
case 3:
|
||||
// DEFINITION: 'SHIFT' KEY (Only)
|
||||
Keyboard.release(KEY_LEFT_SHIFT);
|
||||
blnButtonActioned = true;
|
||||
break;
|
||||
case 4:
|
||||
// DEFINITION: TBA
|
||||
blnButtonActioned = true;
|
||||
break;
|
||||
case 5:
|
||||
// DEFINITION: TBA
|
||||
blnButtonActioned = true;
|
||||
break;
|
||||
case 6:
|
||||
// DEFINITION: TBA
|
||||
blnButtonActioned = true;
|
||||
break;
|
||||
default:
|
||||
//Returns a 'fail' if the 'Button ID' was not specified between 1-6.
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
//Return the fuctions result
|
||||
return blnButtonActioned;
|
||||
}
|
||||
|
||||
//********************************************************************************************
|
||||
//* FUNCTION NAME: 'GetLEDsDimCycleValue'
|
||||
//********************************************************************************************
|
||||
//* Purpose : Determines the LED Brightness 'Dimming Cycle' Value.
|
||||
//* Code Type : FUCTION CALL: C - Arduino Leonardo (Arduino IDE)
|
||||
//* Usage : Can be called anytime. Function call example: ledBrightness = GetLEDsDimCycleValue(ledBrightness);
|
||||
//* Where: * 'GetLEDsDimCycleValue(ledBrightness)' calls the fuction and specifies the CURRENT LED Brigtness Value.
|
||||
//* * 'ledBrightness=' would receive the RETURN LED Brightness Value.
|
||||
//* Returns : An integer value to specify the new LED Brightness.
|
||||
//* Parameters: 'intCurrentLEDBrightnessValue' - Is the current / existing LED Brightness value.
|
||||
//* Prereqs : Requires the following GLOBAL Contants or Variables set in the Main (Initialisation) Code:
|
||||
//* * Constant 'cblnLEDsToDimCycle' to be set to TRUE in MAIN PROGRAM (and evaluated as TRUE with an 'If or Switch Statement' in the main code)
|
||||
//* * Constant 'cintLedDimmerStep' is used to moderate the LED Brightness change (in steps)
|
||||
//* * Constant 'cintLedMinBrightness' specifies the MINIMUM LED brightness to DIM to.
|
||||
//* * Variable 'ledTickTime' keeps track of the LED Timer between LED Brightness value changes.
|
||||
//* Author : A. Seibel-Barnes
|
||||
//* Date : 23/09/2022 (Ver 1.0)
|
||||
//* Notes : Live Long and Propser _\//
|
||||
//'**********************************************************************************************
|
||||
int GetLEDsDimCycleValue(int intCurrentLEDBrightnessValue)
|
||||
{
|
||||
int intLEDBrightnessValue; //LED brightness level to return to Main Code
|
||||
|
||||
intLEDBrightnessValue = intCurrentLEDBrightnessValue;
|
||||
|
||||
//Begin to 'Cycle LED DIMMING' (Up or DOWN) - even if there has been NO Button Activity.
|
||||
if(!blnLEDsAreCyclingUp)
|
||||
{
|
||||
//CYCLE LEDs DOWN: Adjust LEDs brightness Down. LEDs are not in the process of Cycling up to Max ... So, DIM LEDs brightness (slowly 'Dim step DOWN' to Off)
|
||||
if ((millis() - ledTickTime) > cintLedDimmerStepTime)
|
||||
{
|
||||
ledTickTime = millis();
|
||||
|
||||
if(intLEDBrightnessValue > cintLedMinBrightness)
|
||||
{
|
||||
intLEDBrightnessValue = intLEDBrightnessValue - cintLedDimmerStep;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(blnLEDsAreCyclingUp)
|
||||
{
|
||||
//CYCLE LEDs UP: Adjust LEDs brightness Up (slowly 'Dim step UP' to Max)
|
||||
if ((millis() - ledTickTime) > cintLedDimmerStepTime)
|
||||
{
|
||||
ledTickTime = millis();
|
||||
|
||||
if(intLEDBrightnessValue < cintLedMaxBrightness)
|
||||
{
|
||||
intLEDBrightnessValue = intLEDBrightnessValue + cintLedDimmerStep;
|
||||
}
|
||||
else if(intLEDBrightnessValue >= cintLedMaxBrightness)
|
||||
{
|
||||
//Max LED Brightness has been reached (Reset the flag to begin 'LED cycle Down' process)
|
||||
blnLEDsAreCyclingUp = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(intLEDBrightnessValue = cintLedMaxBrightness)
|
||||
{
|
||||
blnLEDsAreCyclingUp = false;
|
||||
}
|
||||
|
||||
//Return the fuctions result
|
||||
return intLEDBrightnessValue;
|
||||
}
|
||||
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