ASB version
This commit is contained in:
parent
b30c50d20e
commit
3ef25bc177
@ -9,7 +9,6 @@
|
|||||||
#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
|
||||||
@ -23,12 +22,21 @@
|
|||||||
#define BUTTON3 A1
|
#define BUTTON3 A1
|
||||||
#define BUTTON4 A0
|
#define BUTTON4 A0
|
||||||
|
|
||||||
|
const int cintLedOffTime = 60000; //LED 'OFF' time (milliseconds) is how long LED will remain on for after a button was pressed (For reference: 60,000 = 1 minute)
|
||||||
|
const int cintDebounceTime = 200; //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' becomes 'true'. If it is 'false', then the delay is 'zero'.
|
||||||
|
|
||||||
unsigned long ledTickTime = 0;
|
unsigned long ledTickTime = 0;
|
||||||
unsigned long lastPressTime = 0;
|
unsigned long lastPressTime = 0;
|
||||||
uint8_t ledBrightness = 100;
|
uint8_t ledBrightness = 100;
|
||||||
bool ledOn = false;
|
bool ledOn = 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).
|
||||||
|
bool blnReleaseALLKeys = false; //Used to control when 'ALL Keyboard Keys should be released'.... OR NOT, where (in some cases) 'Multi-button combinations are required' (eg. 'Hold-Key' actions like Ctr+Alt+Del).
|
||||||
|
//If 'blnReleaseALLKeys' is set to false (in the running code), then you must also implicitly state what keys should be released (and when).
|
||||||
|
|
||||||
//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);
|
||||||
EasyButton button3(BUTTON3, 35, false, false);
|
EasyButton button3(BUTTON3, 35, false, false);
|
||||||
@ -36,7 +44,9 @@ EasyButton button4(BUTTON4, 35, false, false);
|
|||||||
|
|
||||||
//Standard Arduino setup function. Code that only needs to run once goes here
|
//Standard Arduino setup function. Code that only needs to run once goes here
|
||||||
void setup() {
|
void setup() {
|
||||||
|
// Send a clean report to the host. This is important on any Arduino type.
|
||||||
Keyboard.begin();
|
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.
|
//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);
|
pinMode(LED1, OUTPUT);
|
||||||
@ -69,55 +79,113 @@ void loop() {
|
|||||||
|
|
||||||
|
|
||||||
//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.
|
||||||
|
//Note1: 'Keyboard.press' code options (for reference)
|
||||||
|
// Keyboard.press(KEY_LEFT_CTRL)
|
||||||
|
// Keyboard.press(KEY_LEFT_ALT)
|
||||||
|
// Keyboard.press(KEY_LEFT_SHIFT)
|
||||||
|
//Note2: 'Keyboard.release' code options (for use when blnReleaseALLKeys = false)
|
||||||
|
// Keyboard.release(KEY_SPACE)
|
||||||
|
// Keyboard.release(KEY_LEFT_CTRL)
|
||||||
|
|
||||||
if(button1.isPressed())
|
if(button1.isPressed())
|
||||||
{
|
{
|
||||||
Keyboard.press(KEY_LEFT_ALT);
|
// PASTE COMMAND (Ctrl+V)
|
||||||
|
Keyboard.press(KEY_LEFT_CTRL);
|
||||||
|
Keyboard.write('v');
|
||||||
lastPressTime = millis();
|
lastPressTime = millis();
|
||||||
|
blnDelayActions = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(button1.wasReleased())
|
else if(button1.wasReleased())
|
||||||
{
|
{
|
||||||
Keyboard.release(KEY_LEFT_ALT);
|
|
||||||
lastPressTime = millis();
|
lastPressTime = millis();
|
||||||
|
blnDelayActions = false;
|
||||||
|
blnReleaseALLKeys = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(button2.isPressed())
|
if(button2.isPressed())
|
||||||
{
|
{
|
||||||
|
// COPY COMMAND (Ctrl+C)
|
||||||
Keyboard.press(KEY_LEFT_CTRL);
|
Keyboard.press(KEY_LEFT_CTRL);
|
||||||
|
Keyboard.write('c');
|
||||||
lastPressTime = millis();
|
lastPressTime = millis();
|
||||||
|
blnDelayActions = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(button2.wasReleased())
|
else if(button2.wasReleased())
|
||||||
{
|
{
|
||||||
Keyboard.release(KEY_LEFT_CTRL);
|
|
||||||
lastPressTime = millis();
|
lastPressTime = millis();
|
||||||
|
blnDelayActions = false;
|
||||||
|
blnReleaseALLKeys = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(button3.isPressed())
|
if(button3.isPressed())
|
||||||
{
|
{
|
||||||
Keyboard.press(KEY_LEFT_SHIFT);
|
//CUSTOM TEXT (Message)
|
||||||
|
Keyboard.println("Hi there");
|
||||||
|
Keyboard.println();
|
||||||
|
Keyboard.println("Just confirming that your item is in the mail... 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 ;)");
|
||||||
lastPressTime = millis();
|
lastPressTime = millis();
|
||||||
|
blnDelayActions = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(button3.wasReleased())
|
else if(button3.wasReleased())
|
||||||
{
|
{
|
||||||
Keyboard.release(KEY_LEFT_SHIFT);
|
|
||||||
lastPressTime = millis();
|
lastPressTime = millis();
|
||||||
|
blnDelayActions = false;
|
||||||
|
blnReleaseALLKeys = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(button4.isPressed())
|
if(button4.isPressed())
|
||||||
{
|
{
|
||||||
Keyboard.press(KEY_SPACE);
|
// 'CTRL' KEY (Only)
|
||||||
|
Keyboard.press(KEY_LEFT_CTRL);
|
||||||
lastPressTime = millis();
|
lastPressTime = millis();
|
||||||
|
blnDelayActions = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(button4.wasReleased())
|
else if(button4.wasReleased())
|
||||||
{
|
{
|
||||||
Keyboard.release(KEY_SPACE);
|
|
||||||
lastPressTime = millis();
|
lastPressTime = millis();
|
||||||
|
blnDelayActions = false;
|
||||||
|
blnReleaseALLKeys = false; //When FALSE - you must implicidly release Keys (below)
|
||||||
|
Keyboard.release(KEY_LEFT_CTRL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if((millis() - lastPressTime) > 10000)
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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:
|
||||||
|
// Release ALL Keyboard Keys (this should almost always be the case)
|
||||||
|
Keyboard.releaseAll();
|
||||||
|
blnReleaseALLKeys = false;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// Do NOT Release Keys (IMPORTANT: If here not by default, then you should have already implicidly set what Keys have been (or are to be) released.)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if((millis() - lastPressTime) > cintLedOffTime)
|
||||||
{
|
{
|
||||||
ledOn = false;
|
ledOn = false;
|
||||||
}
|
}
|
||||||
@ -126,6 +194,7 @@ void loop() {
|
|||||||
ledOn = true;
|
ledOn = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ((millis() - ledTickTime) > 10)
|
if ((millis() - ledTickTime) > 10)
|
||||||
{
|
{
|
||||||
ledTickTime = millis();
|
ledTickTime = millis();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user