keybrd library is an open source library for creating custom-keyboard firmware.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

keybrd_5_LEDs.ino 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* keybrd_5_LEDs.ino
  2. This sketch:
  3. is firmware for a simple 2-layer keyboard with three LEDs
  4. runs on the first two rows and columns of a breadboard keyboard
  5. | Layout | **0** | **1** |
  6. |:------:|-------|-------|
  7. | **0** |CapsLck| a 1 |
  8. | **1** | fn | b 2 |
  9. */
  10. // ################## GLOBAL ###################
  11. // ================= INCLUDES ==================
  12. //Keys
  13. #include <Code_Sc.h>
  14. #include <Code_LEDLock.h>
  15. #include <LayerState_LED.h>
  16. #include <Code_LayerHold.h>
  17. #include <Key_LayeredKeysArray.h>
  18. #include <Row_uC.h>
  19. #include <ScanDelay.h>
  20. #include <LED_uC.h>
  21. // ============ SPEED CONFIGURATION ============
  22. ScanDelay scanDelay(9000);
  23. // ================ ACTIVE STATE ===============
  24. const bool Scanner_uC::STROBE_ON = LOW;
  25. const bool Scanner_uC::STROBE_OFF = HIGH;
  26. // ================= PINS =================
  27. uint8_t readPins[] = {14, 15};
  28. uint8_t READ_PIN_COUNT = sizeof(readPins)/sizeof(*readPins);
  29. /* ==================== LEDs ===================
  30. The LED_uC constructor parameter is for an Aduino pin that is connected to an LED.
  31. LED_uC objects are passed to other objects that want to turn the LED on or off.
  32. In this example, the LED_uC objects are named after the states they indicate.
  33. The prtsLayerLEDs[] array contains one LED per layer, it is used to indicate the current layer.
  34. */
  35. LED_uC LED_normal(16);
  36. LED_uC LED_fn(17);
  37. LED_uC LED_CapsLck(21);
  38. LED* prtsLayerLEDs[] = { &LED_normal, &LED_fn };
  39. // =================== CODES ===================
  40. /* ---------------- LAYER CODE -----------------
  41. LayerState_LED is similar to LayerState, introduced in keybrd_3a_multi-layer.ino, but with LEDs.
  42. The LayerState_LED turns on the LED of the current layer.
  43. The active layer is used as an index to dereference the prtsLayerLEDs[] array.
  44. */
  45. enum layers { NORMAL, FN };
  46. LayerState_LED layerState(prtsLayerLEDs);
  47. Code_LayerHold l_fn(FN, layerState);
  48. /* ---------------- SCAN CODES -----------------
  49. When a Code_LEDLock object is pressed, it sends a scancodes and updates the its LED.
  50. Scancodes can be one of KEY_CAPS_LOCK, KEY_SCROLL_LOCK, or KEY_NUM_LOCK.
  51. For example, when o_capsLock is pressed, it sends KEY_CAPS_LOCK scancode and updates LED_CapsLck.
  52. */
  53. Code_LEDLock o_capsLock(KEY_CAPS_LOCK, LED_CapsLck);
  54. Code_Sc s_a(KEY_A);
  55. Code_Sc s_b(KEY_B);
  56. Code_Sc s_1(KEY_1);
  57. Code_Sc s_2(KEY_2);
  58. // =================== KEYS ====================
  59. Key* const ptrsCodes_01[] = { &s_a, &s_1 };
  60. Key_LayeredKeysArray k_01(ptrsCodes_01);
  61. Key* const ptrsCodes_11[] = { &s_b, &s_2 };
  62. Key_LayeredKeysArray k_11(ptrsCodes_11);
  63. LayerStateInterface& Key_LayeredKeysArray::refLayerState = layerState;
  64. // =================== ROWS ====================
  65. Key* const ptrsKeys_0[] = { &o_capsLock, &k_01 };
  66. Row_uC row_0(0, readPins, READ_PIN_COUNT, ptrsKeys_0);
  67. Key* const ptrsKeys_1[] = { &l_fn, &k_11 };
  68. Row_uC row_1(1, readPins, READ_PIN_COUNT, ptrsKeys_1);
  69. /* ################### MAIN ####################
  70. layerState.begin() turns on the LED of the initial active layer.
  71. */
  72. void setup()
  73. {
  74. Keyboard.begin();
  75. layerState.begin();
  76. }
  77. void loop()
  78. {
  79. row_0.process();
  80. row_1.process();
  81. scanDelay.delay();
  82. }