diff --git a/code/JCPM-json/JCPM-json.ino b/code/JCPM-json/JCPM-json.ino new file mode 100644 index 0000000..a495e91 --- /dev/null +++ b/code/JCPM-json/JCPM-json.ino @@ -0,0 +1,92 @@ +#include // For keyboard and mouse HID functionality +#include // For storing configurations +#include // For parsing JSON configurations +#include // For NeoPixel LED control +#include + +// Structure to represent a button's configuration +struct ButtonConfig { + char action[6]; + char keys[10]; + char modifiers[5]; + int x, y; + int color[3]; + int colorOnPress[3]; +}; + +// Structure to represent an encoder configuration +struct EncoderConfig { + char action[6]; // Action type: "key", etc. + char keys[10]; // Keys to be pressed (like "UpArrow" or "DownArrow") + char modifiers[5]; // Modifiers (e.g., "Ctrl", "Shift") +}; + +EncoderConfig encoderConfigs[2]; // [0] for increment, [1] for decrement +ButtonConfig buttonConfigs[9]; // 9 configurable buttons + +// General device settings +struct GeneralConfig { + int defaultColor[3]; // Default color for all buttons if none specified +}; + +GeneralConfig generalConfig; // Single global profile + +void setup() { + pinMode(4, INPUT_PULLUP); //SW1 pushbutton (encoder button) + pinMode(15, INPUT_PULLUP); //SW2 pushbutton + pinMode(A0, INPUT_PULLUP); //SW3 pushbutton + pinMode(A1, INPUT_PULLUP); //SW4 pushbutton + pinMode(A2, INPUT_PULLUP); //SW5 pushbutton + pinMode(A3, INPUT_PULLUP); //SW6 pushbutton + pinMode(14, INPUT_PULLUP); //SW7 pushbutton + pinMode(16, INPUT_PULLUP); //SW8 pushbutton + pinMode(10, INPUT_PULLUP); //SW9 pushbutton + pinMode(8, INPUT_PULLUP); //SW10 pushbutton - acts as mode switch + + // Initialize serial, HID, and NeoPixel + Serial.begin(9600); + while (!Serial) { /* wait for serial to initialize */ } + + Serial.print("{\"status\":\"Free memory: "); + Serial.print(freeMemory()); + Serial.println("\"}"); + + Keyboard.begin(); + Mouse.begin(); + setupNeoPixels(); + + // Load initial configuration from EEPROM. multiple profile support removed + loadConfigFromEEPROM(); + + Serial.println("{\"status\":\"System boot OK\"}"); +} + +void loop() { + // Handle serial input + handleSerialInput(); + + // Multiple profile support, mode button switch profile + // Ran out of RAM on a Leonardo, all multiple profile code removed + + // Check button presses for actions + checkEncoderActions(); + + // Check button presses for actions + checkButtonActions(); +} + +extern unsigned int __heap_start, *__brkval; +extern unsigned int __bss_end; +extern unsigned int __data_end; + +int freeMemory() { + int free_memory; + + if ((int)__brkval == 0) { + free_memory = ((int)&free_memory) - ((int)&__bss_end); + } else { + free_memory = ((int)&free_memory) - ((int)__brkval); + } + + return free_memory; +} \ No newline at end of file diff --git a/code/JCPM-json/buttons.ino b/code/JCPM-json/buttons.ino new file mode 100644 index 0000000..de7e200 --- /dev/null +++ b/code/JCPM-json/buttons.ino @@ -0,0 +1,102 @@ +// Define button states (inverted logic for LOW = pressed) +bool SW1 = HIGH, SW2 = HIGH, SW3 = HIGH, SW4 = HIGH, SW5 = HIGH, SW6 = HIGH, SW7 = HIGH, SW8 = HIGH, SW9 = HIGH; +bool buttonHeld[9] = {false, false, false, false, false, false, false, false, false}; // Track button hold states + +// Encoder variables +int16_t encoderPosition = 0; +Encoder myEnc(1, 0); // Pins 1 and 0 for the encoder + +int buttonPins[9] = {4, 15, A0, A1, A2, A3, 14, 16, 10}; // Button pin assignments + +void checkButtonActions() { + for (int i = 0; i < 9; i++) { + int currentState = digitalRead(buttonPins[i]); + + // When button is pressed + if (currentState == LOW && !buttonHeld[i]) { + buttonHeld[i] = true; + Serial.print("{\"button\":"); + Serial.print(i + 1); + Serial.println(", \"event\":\"pressed\"}"); + setPixelColor(i - 1, buttonConfigs[i].colorOnPress[0], buttonConfigs[i].colorOnPress[1], buttonConfigs[i].colorOnPress[2]); + executeButtonAction(i); // Execute the button action + } + + // When button is released + if (currentState == HIGH && buttonHeld[i]) { + buttonHeld[i] = false; + Serial.print("{\"button\":"); + Serial.print(i + 1); + Serial.println(", \"event\":\"released\"}"); + setPixelColor(i - 1, buttonConfigs[i].color[0], buttonConfigs[i].color[1], buttonConfigs[i].color[2]); + } + } +} + +void checkEncoderActions() { + int16_t newPosition = myEnc.read(); + if (newPosition > encoderPosition) { + Serial.println("{\"encoder\":\"increment\"}"); // JSON output for increment action + executeEncoderAction(encoderConfigs[0]); + encoderPosition = newPosition; + } + if (newPosition < encoderPosition) { + Serial.println("{\"encoder\":\"decrement\"}"); // JSON output for decrement action + executeEncoderAction(encoderConfigs[1]); + encoderPosition = newPosition; + } + delay(50); +} + +void executeHIDAction(const char* action, const char* keys, const char* modifiers, int x = 0, int y = 0, bool hasMouseAction = false) { + // Check if the action type is "constant" and map string to HID keycode + if (strcmp(action, "const") == 0) { + if (strcmp(keys, "UpArrow") == 0) { + Keyboard.press(HID_KEYBOARD_UPARROW); + } else if (strcmp(keys, "DownArrow") == 0) { + Keyboard.press(HID_KEYBOARD_DOWNARROW); + } else if (strcmp(keys, "LeftArrow") == 0) { + Keyboard.press(HID_KEYBOARD_LEFTARROW); + } else if (strcmp(keys, "RightArrow") == 0) { + Keyboard.press(HID_KEYBOARD_RIGHTARROW); + } else if (strcmp(keys, "Enter") == 0) { + Keyboard.press(KEY_ENTER); + } else { + Serial.print("{\"error\":\"Invalid constant: "); + Serial.print(keys); + Serial.println("\"}"); + return; + } + delay(100); // Short delay for key press + Keyboard.releaseAll(); + } + // Handle "key" action to press any key provided in the config + else if (strcmp(action, "key") == 0) { + // Handle modifiers if any + if (strstr(modifiers, "Ctrl")) Keyboard.press(KEY_LEFT_CTRL); + if (strstr(modifiers, "Shift")) Keyboard.press(KEY_LEFT_SHIFT); + if (strstr(modifiers, "Alt")) Keyboard.press(KEY_LEFT_ALT); + + // Directly press the specified key as a character + // Loop over each character in keys and press it + for (int i = 0; i < strlen(keys); i++) { + Keyboard.press(keys[i]); // Press each character in the string + delay(50); // Optional small delay between each key press + } + delay(100); // Short delay for key press + Keyboard.releaseAll(); + } + // Handle mouse actions if needed + else if (hasMouseAction && strcmp(action, "mouse") == 0) { + Mouse.move(x, y); + } +} + +void executeButtonAction(int buttonIndex) { + ButtonConfig config = buttonConfigs[buttonIndex]; + executeHIDAction(config.action, config.keys, config.modifiers, config.x, config.y, true); +} + +void executeEncoderAction(const EncoderConfig &config) { + executeHIDAction(config.action, config.keys, config.modifiers); +} diff --git a/code/JCPM-json/neopixels.ino b/code/JCPM-json/neopixels.ino new file mode 100644 index 0000000..ad3f546 --- /dev/null +++ b/code/JCPM-json/neopixels.ino @@ -0,0 +1,23 @@ +#include + +#define PIN 5 // NeoPixel data pin +#define NUMPIXELS 11 // Total number of NeoPixel LEDs +Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); + +void setupNeoPixels() { + pixels.begin(); + resetAllPixels(); // Set all pixels to off initially +} + +void setPixelColor(int pixel, int r, int g, int b) { + if (pixel >= 0 && pixel < pixels.numPixels()) { + pixels.setPixelColor(pixel, pixels.Color(r, g, b)); + pixels.show(); // Update to show the change + } +} + +void resetAllPixels() { + for (int i = 0; i < NUMPIXELS; i++) { + setPixelColor(i, 0, 0, 0); // Turn off all LEDs + } +} diff --git a/code/JCPM-json/profiles.ino b/code/JCPM-json/profiles.ino new file mode 100644 index 0000000..3aa05f1 --- /dev/null +++ b/code/JCPM-json/profiles.ino @@ -0,0 +1,86 @@ +#include +#include + +// Load configuration from EEPROM +void loadConfigFromEEPROM() { + int configOffset = 0; + + // Load general configuration + EEPROM.get(configOffset, generalConfig); + configOffset += sizeof(GeneralConfig); + + // Load button configurations + EEPROM.get(configOffset, buttonConfigs); + configOffset += sizeof(buttonConfigs); + + // Load encoder configurations + EEPROM.get(configOffset, encoderConfigs); + + // Output loaded configuration for debugging + Serial.println("{\"status\":\"Loaded configuration from EEPROM.\"}"); + + Serial.print("{\"buttons\":["); + for (int i = 0; i < 9; i++) { + Serial.print("{\"button\":"); + Serial.print(i); + Serial.print(",\"action\":\""); + Serial.print(buttonConfigs[i].action); + Serial.print("\"}"); + + // Set the button's color if it has a color configured + setPixelColor(i - 1, buttonConfigs[i].color[0], buttonConfigs[i].color[1], buttonConfigs[i].color[2]); + + + if (i < 8) { + Serial.print(","); // Add a comma after each button except the last one + } + } + + Serial.println("]}"); // Close the JSON array and object + + // Print encoder configurations + Serial.print("{\"encoder\":{\"increment\":{"); + Serial.print("\"action\":\""); + Serial.print(encoderConfigs[0].action); + Serial.print("\",\"keys\":\""); + Serial.print(encoderConfigs[0].keys); + Serial.print("\",\"modifiers\":\""); + Serial.print(encoderConfigs[0].modifiers); + Serial.print("\"},\"decrement\":{"); + + Serial.print("\"action\":\""); + Serial.print(encoderConfigs[1].action); + Serial.print("\",\"keys\":\""); + Serial.print(encoderConfigs[1].keys); + Serial.print("\",\"modifiers\":\""); + Serial.print(encoderConfigs[1].modifiers); + Serial.println("\"}}}"); +} + +// Save configuration to EEPROM +void saveConfigToEEPROM() { + int configOffset = 0; + + // Save general configuration + EEPROM.put(configOffset, generalConfig); + configOffset += sizeof(GeneralConfig); + + // Save button configurations + EEPROM.put(configOffset, buttonConfigs); + configOffset += sizeof(buttonConfigs); + + // Save encoder configurations + EEPROM.put(configOffset, encoderConfigs); + + Serial.println("{\"response\":\"Configuration saved to EEPROM.\"}"); +} + +void resetEEPROM() { + int eepromSize = EEPROM.length(); + + for (int i = 0; i < eepromSize; i++) { + EEPROM.write(i, 0); // Write zeros to the entire EEPROM + } + + Serial.println("{\"response\":\"EEPROM reset completed\"}"); +} diff --git a/code/JCPM-json/serial.ino b/code/JCPM-json/serial.ino new file mode 100644 index 0000000..18479c7 --- /dev/null +++ b/code/JCPM-json/serial.ino @@ -0,0 +1,228 @@ +#include +#include + +// Handle the serial commands +void handleSerialInput() { + if (Serial.available()) { + String input = Serial.readStringUntil('\n'); // Read input from serial + input.trim(); // Remove any leading/trailing whitespaces or newlines + + if (input.length() == 0) { + // Manually create JSON error response + Serial.println("{\"error\":\"Empty input\"}"); + return; + } + + // Debug message to show the input received + //Serial.print("{\"debug\":\"Received input: "); + //Serial.print(input); + //Serial.println("\"}"); + + // Create a JSON document for parsing + StaticJsonDocument<256> doc; // Define a smaller, fixed-size JSON document + //Serial.print("{\"status\":\"Free memory: "); + //Serial.print(freeMemory()); + //Serial.println("\"}"); + + DeserializationError error = deserializeJson(doc, input); + + if (error) { + // Output the specific deserialization error in JSON format + Serial.print("{\"error\":\"Deserialization error: "); + Serial.print(error.c_str()); + Serial.println("\"}"); + return; + } + + // Handle "HELLO" command + if (doc["command"] == "HELLO") { + Serial.println("{\"response\":\"ok\"}"); + } + + // Handle "RESET_EEPROM" command + else if (doc["command"] == "RESET_EEPROM") { + resetEEPROM(); // Call the reset function + // Send confirmation message + Serial.println("{\"response\":\"success\"}"); + } + + // Handle "SET_COLOR" command for NeoPixels + else if (doc["command"] == "SET_COLOR") { + int pixel = doc["pixel"].as(); // Extract the pixel index + JsonArray color = doc["color"]; // Extract the color array + + if (color.size() == 3) { // Ensure we have an RGB color + int r = color[0]; + int g = color[1]; + int b = color[2]; + + // Set the NeoPixel color + setPixelColor(pixel, r, g, b); + + // Send confirmation message + Serial.print("{\"response\":\"success"); + Serial.print(pixel); + Serial.println("\"}"); + } else { + // Send error if color array is invalid + Serial.println("{\"error\":\"Invalid color array\"}"); + } + } + + // Handle "SET" command for general configuration, buttons, and encoder + else if (doc["command"] == "SET") { + // General Config + JsonObject generalConfig = doc["generalConfig"]; + buttonConfigs[0].color[0] = generalConfig["defaultColor"][0]; + buttonConfigs[0].color[1] = generalConfig["defaultColor"][1]; + buttonConfigs[0].color[2] = generalConfig["defaultColor"][2]; + + // Button Configurations + JsonObject buttons = doc["buttons"]; + for (int i = 0; i < 9; i++) { + JsonObject button = buttons[String(i)]; + strcpy(buttonConfigs[i].action, button["action"]); + strcpy(buttonConfigs[i].keys, button["keys"]); + strcpy(buttonConfigs[i].modifiers, button["modifiers"]); + buttonConfigs[i].x = button["x"]; + buttonConfigs[i].y = button["y"]; + buttonConfigs[i].color[0] = button["color"][0]; + buttonConfigs[i].color[1] = button["color"][1]; + buttonConfigs[i].color[2] = button["color"][2]; + + // Only set colorOnPress if it exists in the JSON + if (button.containsKey("colorOnPress")) { + buttonConfigs[i].colorOnPress[0] = button["colorOnPress"][0]; + buttonConfigs[i].colorOnPress[1] = button["colorOnPress"][1]; + buttonConfigs[i].colorOnPress[2] = button["colorOnPress"][2]; + } else { + buttonConfigs[i].colorOnPress[0] = buttonConfigs[i].color[0]; // Fallback to normal color + buttonConfigs[i].colorOnPress[1] = buttonConfigs[i].color[1]; + buttonConfigs[i].colorOnPress[2] = buttonConfigs[i].color[2]; + } + } + + // Encoder Config + JsonObject encoderConfig = doc["encoder"]; + strcpy(encoderConfigs[0].action, encoderConfig["increment"]["action"]); + strcpy(encoderConfigs[0].keys, encoderConfig["increment"]["keys"]); + strcpy(encoderConfigs[0].modifiers, encoderConfig["increment"]["modifiers"]); + + strcpy(encoderConfigs[1].action, encoderConfig["decrement"]["action"]); + strcpy(encoderConfigs[1].keys, encoderConfig["decrement"]["keys"]); + strcpy(encoderConfigs[1].modifiers, encoderConfig["decrement"]["modifiers"]); + + saveConfigToEEPROM(); + + Serial.println("{\"response\":\"success\"}"); + } + + else if (doc["command"] == "DEBUG") { + // Set encoder debug actions + strcpy(encoderConfigs[0].action, "const"); + strcpy(encoderConfigs[0].keys, "UpArrow"); + strcpy(encoderConfigs[0].modifiers, ""); + strcpy(encoderConfigs[1].action, "const"); + strcpy(encoderConfigs[1].keys, "DownArrow"); + strcpy(encoderConfigs[1].modifiers, ""); + + // Configure specific settings for buttons 1 to 4 + strcpy(buttonConfigs[0].action, "const"); + strcpy(buttonConfigs[0].keys, "Enter"); + + strcpy(buttonConfigs[1].action, "key"); + strcpy(buttonConfigs[1].keys, "A"); + buttonConfigs[1].color[0] = 255; // Red + buttonConfigs[1].color[1] = 0; + buttonConfigs[1].color[2] = 0; + buttonConfigs[1].colorOnPress[0] = 0; // Teal + buttonConfigs[1].colorOnPress[1] = 128; + buttonConfigs[1].colorOnPress[2] = 128; + + strcpy(buttonConfigs[2].action, "key"); + strcpy(buttonConfigs[2].keys, "B"); + buttonConfigs[2].color[0] = 0; // Green + buttonConfigs[2].color[1] = 255; + buttonConfigs[2].color[2] = 0; + buttonConfigs[2].colorOnPress[0] = 0; // Teal + buttonConfigs[2].colorOnPress[1] = 128; + buttonConfigs[2].colorOnPress[2] = 128; + + strcpy(buttonConfigs[3].action, "key"); + strcpy(buttonConfigs[3].keys, "C"); + buttonConfigs[3].color[0] = 0; // Blue + buttonConfigs[3].color[1] = 0; + buttonConfigs[3].color[2] = 255; + buttonConfigs[3].colorOnPress[0] = 0; // Teal + buttonConfigs[3].colorOnPress[1] = 128; + buttonConfigs[3].colorOnPress[2] = 128; + + // Randomly assign actions and colors to remaining buttons + for (int i = 4; i < 9; i++) { + strcpy(buttonConfigs[i].action, "key"); + buttonConfigs[i].keys[0] = 'A' + i; // Sets keys as 'D' to 'I' + buttonConfigs[i].keys[1] = '\0'; // Null terminate the string + buttonConfigs[i].modifiers[0] = '\0'; // No modifiers + buttonConfigs[i].color[0] = random(0, 256); // Random red + buttonConfigs[i].color[1] = random(0, 256); // Random green + buttonConfigs[i].color[2] = random(0, 256); // Random blue + buttonConfigs[i].colorOnPress[0] = random(0, 256); // Random red on press + buttonConfigs[i].colorOnPress[1] = random(0, 256); // Random green on press + buttonConfigs[i].colorOnPress[2] = random(0, 256); // Random blue on press + } + + saveConfigToEEPROM(); // Save the debug config to EEPROM + Serial.println("{\"response\":\"debug config set\"}"); +} + + + // Handle "GET" command for button configuration + else if (doc["command"] == "GET") { + int buttonIndex = doc["button"].as(); // Button index + + if (buttonIndex >= 0 && buttonIndex < 9) { + // Manually create JSON response for GET + Serial.print("{\"button\":"); + Serial.print(buttonIndex); + + ButtonConfig config = buttonConfigs[buttonIndex]; + + Serial.print(",\"config\":{\"action\":\""); + Serial.print(config.action); + Serial.print("\",\"keys\":\""); + Serial.print(config.keys); + Serial.print("\",\"modifiers\":\""); + Serial.print(config.modifiers); + Serial.print("\",\"x\":"); + Serial.print(config.x); + Serial.print(",\"y\":"); + Serial.print(config.y); + + Serial.print(",\"color\":["); + Serial.print(config.color[0]); + Serial.print(","); + Serial.print(config.color[1]); + Serial.print(","); + Serial.print(config.color[2]); + Serial.print("],\"colorOnPress\":["); + + Serial.print(config.colorOnPress[0]); + Serial.print(","); + Serial.print(config.colorOnPress[1]); + Serial.print(","); + Serial.print(config.colorOnPress[2]); + Serial.println("]}}"); + + } else { + // Manually create JSON error response for invalid button index + Serial.println("{\"error\":\"Invalid button index\"}"); + } + } + + // Unknown command + else { + // Manually create JSON error response for unknown command + Serial.println("{\"error\":\"Unknown command\"}"); + } + } +} \ No newline at end of file diff --git a/code/JCPM2-experimental.ino b/code/JCPM2-experimental.ino index 2c0c657..952093c 100644 --- a/code/JCPM2-experimental.ino +++ b/code/JCPM2-experimental.ino @@ -47,7 +47,7 @@ long oldPulseTime = 0; int fanRPM = 0; char toneNote; -int modeArray[] = {0, 1, 3, 7}; //adjust this array to modify sequence of modes - as written, change to {0, 1, 2, 3, 4, 5} to access all modes +int modeArray[] = {0, 1, 3, 7, 8}; //adjust this array to modify sequence of modes - as written, change to {0, 1, 2, 3, 4, 5} to access all modes int inputModeIndex = 0; int modeArrayLength = (sizeof(modeArray) / sizeof(modeArray[0])); @@ -224,6 +224,10 @@ if (inputMode == 7) { KiCad(); } +if (inputMode == 8) { // AHK Mode + ahkMode(); +} + //Serial.println(inputMode); } @@ -716,6 +720,133 @@ void KiCad(){ screenKiCad(); } +void ahkMode() { + setLightsGreen(); + // Handle encoder movement for increment/decrement + if (increment == 1) { + Keyboard.press(KEY_LEFT_CTRL); + Keyboard.press(KEY_LEFT_ALT); + Keyboard.press(KEY_LEFT_SHIFT); + Keyboard.press(KEY_F1); + Keyboard.releaseAll(); + increment = 0; + setLightsGreen(); // Reset all lights to green after releasing + } + + if (decrement == 1) { + Keyboard.press(KEY_LEFT_CTRL); + Keyboard.press(KEY_LEFT_ALT); + Keyboard.press(KEY_LEFT_SHIFT); + Keyboard.press(KEY_F2); + Keyboard.releaseAll(); + decrement = 0; + setLightsGreen(); // Reset all lights to green after releasing + } + + // Handle button presses for SW1 to SW9 + if (SW1 == 0) { + setLightsRed(0); // Turn the first LED red when pressed + Keyboard.press(KEY_LEFT_CTRL); + Keyboard.press(KEY_LEFT_ALT); + Keyboard.press(KEY_LEFT_SHIFT); + Keyboard.press(KEY_F3); + Keyboard.releaseAll(); + delay(100); + setLightsGreen(); // Reset all lights to green after releasing + } + + if (SW2 == 0) { + setLightsRed(0); + Keyboard.press(KEY_LEFT_CTRL); + Keyboard.press(KEY_LEFT_ALT); + Keyboard.press(KEY_LEFT_SHIFT); + Keyboard.press(KEY_F4); + Keyboard.releaseAll(); + delay(100); + setLightsGreen(); // Reset all lights to green after releasing + } + + if (SW3 == 0) { + setLightsRed(1); + Keyboard.press(KEY_LEFT_CTRL); + Keyboard.press(KEY_LEFT_ALT); + Keyboard.press(KEY_LEFT_SHIFT); + Keyboard.press(KEY_F5); + Keyboard.releaseAll(); + delay(100); + setLightsGreen(); // Reset all lights to green after releasing + } + + if (SW4 == 0) { + setLightsRed(2); + Keyboard.press(KEY_LEFT_CTRL); + Keyboard.press(KEY_LEFT_ALT); + Keyboard.press(KEY_LEFT_SHIFT); + Keyboard.press(KEY_F6); + Keyboard.releaseAll(); + delay(100); + setLightsGreen(); // Reset all lights to green after releasing + } + + if (SW5 == 0) { + setLightsRed(3); + Keyboard.press(KEY_LEFT_CTRL); + Keyboard.press(KEY_LEFT_ALT); + Keyboard.press(KEY_LEFT_SHIFT); + Keyboard.press(KEY_F7); + Keyboard.releaseAll(); + delay(100); + setLightsGreen(); // Reset all lights to green after releasing + } + + if (SW6 == 0) { + setLightsRed(4); + Keyboard.press(KEY_LEFT_CTRL); + Keyboard.press(KEY_LEFT_ALT); + Keyboard.press(KEY_LEFT_SHIFT); + Keyboard.press(KEY_F8); + Keyboard.releaseAll(); + delay(100); + setLightsGreen(); // Reset all lights to green after releasing + } + + if (SW7 == 0) { + setLightsRed(5); + Keyboard.press(KEY_LEFT_CTRL); + Keyboard.press(KEY_LEFT_ALT); + Keyboard.press(KEY_LEFT_SHIFT); + Keyboard.press(KEY_F9); + Keyboard.releaseAll(); + delay(100); + setLightsGreen(); // Reset all lights to green after releasing + } + + if (SW8 == 0) { + setLightsRed(6); + Keyboard.press(KEY_LEFT_CTRL); + Keyboard.press(KEY_LEFT_ALT); + Keyboard.press(KEY_LEFT_SHIFT); + Keyboard.press(KEY_F10); + Keyboard.releaseAll(); + delay(100); + setLightsGreen(); // Reset all lights to green after releasing + } + + + + if (SW9 == 0) { + setLightsRed(7); // Turn the ninth LED red when pressed + Keyboard.press(KEY_LEFT_CTRL); + Keyboard.press(KEY_LEFT_ALT); + Keyboard.press(KEY_LEFT_SHIFT); + Keyboard.press(KEY_F11); + Keyboard.releaseAll(); + delay(100); + setLightsGreen(); // Reset all lights to green after releasing + } +} + + //======================.96" oled screen======================= void screenVolume(){ @@ -853,3 +984,17 @@ void topPixelsClear(){ } pixels.show(); // Show results } + +// Function to set all lights to green +void setLightsGreen() { + for (int i = 0; i < NUMPIXELS; i++) { + pixels.setPixelColor(i, pixels.Color(0, 255, 0)); // Set green color + } + pixels.show(); +} + +// Function to set a specific light red when a button is pressed +void setLightsRed(int index) { + pixels.setPixelColor(index, pixels.Color(255, 0, 0)); // Set red color + pixels.show(); +} \ No newline at end of file