yes sounds about right.
I managed to get help from a reddit user i contacted for help and he came up with this code i can modify for my own.
im very happy right now because i can study the code and learn from it much more affectively than trying to put the code together from scratch.
/* This is not tested code, debug it thoroughly.
* ---
* If you try to run this code without modyfying it, a bunch of errors will pop up!
* It's alright, I added these to remind you that you need to fill some code sections.
* If you want to run a single mode without finishing the rest, just delete these error statements (#error)
* ---
* I added constants for each button pin, button index, and modes of operation.
* Additionally, I created the skeleton for the mode-choosing buttons,
* but the buttons weren't added, it's your task!
* ---
* Read the comments carefully! Good luck!
*/
#include "Keyboard.h"
#define MAX8BUTTONS // only to save storage space if not using more than 8 buttons
#include <MobaTools.h>
/* -------------------------------------------------------------------------------------- */
/* These are the modes of the buttons, you can change
* them to have more indicative names (expl: MINIMALIST_MODE ..)
*/
enum{MODE_1 = 0, MODE_2, MODE_3}; // Create three constants having the values 0, 1, 2
/* Buttons' indexes are better when put into constants,
* also it's better to give buttons meaningful names like
* KILL_SWITCH, ESCAPE, CHANGE_MODE, ...
*/
enum{BUTTON_0 = 0, BUTTON_1, BUTTON_2, BUTTON_3, BUTTON_4};
/* Buttons' pins are better when put into constants.
* enum counts up from the first value, if you want to define the values yourself,
* you can make :: expl: BUTTON_3_PIN = 13
*/
enum{BUTTON_0_PIN = 2, BUTTON_1_PIN, BUTTON_2_PIN, BUTTON_3_PIN, BUTTON_4_PIN};
/* This is the varibale that would hold the mode (and you'll update it
* according to which button of the remaining 3 is pressed.
*/
byte which_mode = MODE_1; // Default mode is MODE_1
/* -------------------------------------------------------------------------------------- */
/* Buttons variables */
const byte buttonPin[] = {BUTTON_0_PIN, BUTTON_1_PIN, BUTTON_2_PIN, BUTTON_3_PIN, BUTTON_4_PIN};
const byte buttonCount = sizeof( buttonPin ); // buttonPin must be declared as byte to work correctly
MoToButtons buttons( buttonPin, buttonCount, 20, 800 ); // 20ms debounce time, 500ms longpress ( not used here )
void setup() {
Keyboard.begin();
}
void loop() {
buttons.processButtons();
/* -------------------------------------------------------------------------------------- */
/* Here you choose the mode and update the value of which_mode according to the pressed button */
/*
THIS IS PSEUDO CODE, THE BUTTONS HAVEN'T BEEN ADDED .. It's your task !
if(buttons.shortPress(MODE_1_BUTTON){ // Or maybe longPress()
which_mode = MODE_1;
}
if(buttons.shortPress(MODE_2_BUTTON){ // Or maybe longPress()
which_mode = MODE_2;
}
if(buttons.shortPress(MODE_3_BUTTON){ // Or maybe longPress()
which_mode = MODE_3;
}
*/
/* -------------------------------------------------------------------------------------- */
if (buttons.longPress(BUTTON_0) ) {
/* Depending on the value of which_mode, we either execute the code under MODE_1, MODE_2 or MODE_3 */
switch(which_mode){
case MODE_1: /* Default mode */
// sleep pc ( pin 2 )
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_LEFT_ALT);
Keyboard.press('k');
break;
case MODE_2: /* Second mode (you fill it) */
/* Added these error messages so that the code would only run
* when you remove all of these and replace them with code
*/
#error "You still didn't finish this"
break;
case MODE_3: /* Third mode (you fill it) */
/* Added these error messages so that the code would only run
* when you remove all of these and replace them with code
*/
#error "You still didn't finish this"
break;
}
/* Since no matter what presses are performed these are mandatory, we keep them out of the switch block */
delay(100);
Keyboard.releaseAll();
}
if (buttons.shortPress(BUTTON_0) ) {
/* Depending on the value of which_mode, we either execute the code under MODE_1, MODE_2 or MODE_3 */
switch(which_mode){
case MODE_1: /* Default mode */
// kill internet ( pin 2 )
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_LEFT_ALT);
Keyboard.press('m');
break;
case MODE_2: /* Second mode (you fill it) */
/* Added these error messages so that the code would only run
* when you remove all of these and replace them with code
*/
#error "You still didn't finish this"
break;
case MODE_3: /* Third mode (you fill it) */
/* Added these error messages so that the code would only run
* when you remove all of these and replace them with code
*/
#error "You still didn't finish this"
break;
}
/* Since no matter what presses are performed these are mandatory, we keep them out of the switch block */
delay(100);
Keyboard.releaseAll();
}
if (buttons.longPress(BUTTON_1) ) {
/* Depending on the value of which_mode, we either execute the code under MODE_1, MODE_2 or MODE_3 */
switch(which_mode){
case MODE_1: /* Default mode */
// show monitor profile dropdown( pin 3 )
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_LEFT_SHIFT);
Keyboard.press(KEY_F4);
break;
case MODE_2: /* Second mode (you fill it) */
/* Added these error messages so that the code would only run
* when you remove all of these and replace them with code
*/
#error "You still didn't finish this"
break;
case MODE_3: /* Third mode (you fill it) */
/* Added these error messages so that the code would only run
* when you remove all of these and replace them with code
*/
#error "You still didn't finish this"
break;
}
/* Since no matter what presses are performed these are mandatory, we keep them out of the switch block */
delay(100);
Keyboard.releaseAll();
}
if (buttons.shortPress(BUTTON_1) ) {
/* Depending on the value of which_mode, we either execute the code under MODE_1, MODE_2 or MODE_3 */
switch(which_mode){
case MODE_1: /* Default mode */
// toggle monitor profile three and one ( pin 3 )
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_LEFT_ALT);
Keyboard.press('y');
break;
case MODE_2: /* Second mode (you fill it) */
/* Added these error messages so that the code would only run
* when you remove all of these and replace them with code
*/
#error "You still didn't finish this"
break;
case MODE_3: /* Third mode (you fill it) */
/* Added these error messages so that the code would only run
* when you remove all of these and replace them with code
*/
#error "You still didn't finish this"
break;
}
/* Since no matter what presses are performed these are mandatory, we keep them out of the switch block */
delay(100);
Keyboard.releaseAll();
}
if (buttons.longPress(BUTTON_2) ) {
/* Depending on the value of which_mode, we either execute the code under MODE_1, MODE_2 or MODE_3 */
switch(which_mode){
case MODE_1: /* Default mode */
// turn on led( pin 4 )
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_F5);
break;
case MODE_2: /* Second mode (you fill it) */
/* Added these error messages so that the code would only run
* when you remove all of these and replace them with code
*/
#error "You still didn't finish this"
break;
case MODE_3: /* Third mode (you fill it) */
/* Added these error messages so that the code would only run
* when you remove all of these and replace them with code
*/
#error "You still didn't finish this"
break;
}
/* Since no matter what presses are performed these are mandatory, we keep them out of the switch block */
delay(100);
Keyboard.releaseAll();
}
if (buttons.shortPress(BUTTON_2) ) {
/* Depending on the value of which_mode, we either execute the code under MODE_1, MODE_2 or MODE_3 */
switch(which_mode){
case MODE_1: /* Default mode */
// change LED Profile ( pin 4 )
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_LEFT_ALT);
Keyboard.press('p');
break;
case MODE_2: /* Second mode (you fill it) */
/* Added these error messages so that the code would only run
* when you remove all of these and replace them with code
*/
#error "You still didn't finish this"
break;
case MODE_3: /* Third mode (you fill it) */
/* Added these error messages so that the code would only run
* when you remove all of these and replace them with code
*/
#error "You still didn't finish this"
break;
}
/* Since no matter what presses are performed these are mandatory, we keep them out of the switch block */
delay(100);
Keyboard.releaseAll();
}
if (buttons.longPress(BUTTON_3) ) {
/* Depending on the value of which_mode, we either execute the code under MODE_1, MODE_2 or MODE_3 */
switch(which_mode){
case MODE_1: /* Default mode */
// record last 5min ( pin 5 )
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_LEFT_ALT);
Keyboard.press(KEY_F9);
break;
case MODE_2: /* Second mode (you fill it) */
/* Added these error messages so that the code would only run
* when you remove all of these and replace them with code
*/
#error "You still didn't finish this"
break;
case MODE_3: /* Third mode (you fill it) */
/* Added these error messages so that the code would only run
* when you remove all of these and replace them with code
*/
#error "You still didn't finish this"
break;
}
/* Since no matter what presses are performed these are mandatory, we keep them out of the switch block */
delay(100);
Keyboard.releaseAll();
}
if (buttons.shortPress(BUTTON_3) ) {
/* Depending on the value of which_mode, we either execute the code under MODE_1, MODE_2 or MODE_3 */
switch(which_mode){
case MODE_1: /* Default mode */
// record on/off( pin 5 )
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_LEFT_ALT);
Keyboard.press(KEY_F10);
break;
case MODE_2: /* Second mode (you fill it) */
/* Added these error messages so that the code would only run
* when you remove all of these and replace them with code
*/
#error "You still didn't finish this"
break;
case MODE_3: /* Third mode (you fill it) */
/* Added these error messages so that the code would only run
* when you remove all of these and replace them with code
*/
#error "You still didn't finish this"
break;
}
/* Since no matter what presses are performed these are mandatory, we keep them out of the switch block */
delay(100);
Keyboard.releaseAll();
} // <-- I added this after removing the one down
if (buttons.longPress(BUTTON_4) ) {
/* Depending on the value of which_mode, we either execute the code under MODE_1, MODE_2 or MODE_3 */
switch(which_mode){
case MODE_1: /* Default mode */
// 5th button ( pin 6 ) pressed
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_LEFT_ALT);
Keyboard.press('d');
break;
case MODE_2: /* Second mode (you fill it) */
/* Added these error messages so that the code would only run
* when you remove all of these and replace them with code
*/
#error "You still didn't finish this"
break;
case MODE_3: /* Third mode (you fill it) */
/* Added these error messages so that the code would only run
* when you remove all of these and replace them with code
*/
#error "You still didn't finish this"
break;
}
/* Since no matter what presses are performed these are mandatory, we keep them out of the switch block */
delay(100);
Keyboard.releaseAll();
}
if (buttons.shortPress(BUTTON_4) ) {
/* Depending on the value of which_mode, we either execute the code under MODE_1, MODE_2 or MODE_3 */
switch(which_mode){
case MODE_1: /* Default mode */
// 5th button ( pin 6 ) pressed
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_LEFT_ALT);
Keyboard.press('d');
break;
case MODE_2: /* Second mode (you fill it) */
/* Added these error messages so that the code would only run
* when you remove all of these and replace them with code
*/
#error "You still didn't finish this"
break;
case MODE_3: /* Third mode (you fill it) */
/* Added these error messages so that the code would only run
* when you remove all of these and replace them with code
*/
#error "You still didn't finish this"
break;
}
/* Since no matter what presses are performed these are mandatory, we keep them out of the switch block */
delay(100);
Keyboard.releaseAll();
}
//} <-- I commented this and moved it to close the button 3 _ if statement
}
thank you for your time.