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_5a_LED_on_uC.ino 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* keybrd_5a_LED_on_uC.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 | x = |
  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_LayeredKeys.h>
  18. #include <Row.h>
  19. #include <Scanner_uC.h>
  20. #include <ScanDelay.h>
  21. #include <LED_uC.h>
  22. // ============ SPEED CONFIGURATION ============
  23. ScanDelay scanDelay(9000);
  24. // ================== SCANNER ==================
  25. uint8_t readPins[] = {14, 15};
  26. uint8_t readPinCount = sizeof(readPins)/sizeof(*readPins);
  27. Scanner_uC scanner(LOW, readPins, readPinCount);
  28. /* ==================== LEDs ===================
  29. The LED_uC constructor parameter is for an Aduino pin number that is connected to an LED.
  30. In this example, the LED_uC objects are named after the states they indicate.
  31. */
  32. LED_uC LED_normal(16);
  33. LED_uC LED_fn(17);
  34. LED_uC LED_capsLck(21);
  35. // =================== CODES ===================
  36. /* ---------------- LAYER CODE -----------------
  37. LayerState_LED is similar to LayerState introduced in keybrd_3a_multi-layerHold.ino, but with LEDs.
  38. The LayerState_LED turns on the LED of the active layer.
  39. The prtsLayerLEDs[] array contains one LED per layer.
  40. The active layerId is used as an index to dereference the prtsLayerLEDs[] array.
  41. */
  42. enum layerIds { NORMAL, FN };
  43. LEDInterface* prtsLayerLEDs[] = { &LED_normal, &LED_fn }; //enum layerIds align with array index
  44. LayerState_LED layerState(prtsLayerLEDs);
  45. Code_LayerHold l_fn(FN, layerState);
  46. /* ----------------- SCANCODES -----------------
  47. When a Code_LEDLock object is pressed, it sends its scancode and updates the its LED.
  48. Scancodes can be one of: KEY_CAPS_LOCK, KEY_SCROLL_LOCK, or KEY_NUM_LOCK.
  49. For example, when o_capsLock is pressed, it sends KEY_CAPS_LOCK scancode and updates LED_capsLck.
  50. */
  51. Code_LEDLock o_capsLock(KEY_CAPS_LOCK, LED_capsLck);
  52. Code_Sc s_a(KEY_A);
  53. Code_Sc s_x(KEY_X);
  54. Code_Sc s_1(KEY_1);
  55. Code_Sc s_equal(KEY_EQUAL);
  56. // =================== KEYS ====================
  57. Key* const ptrsKeys_01[] = { &s_a, &s_1 };
  58. Key_LayeredKeys k_01(ptrsKeys_01);
  59. Key* const ptrsKeys_11[] = { &s_x, &s_equal };
  60. Key_LayeredKeys k_11(ptrsKeys_11);
  61. LayerStateInterface& Key_LayeredKeys::refLayerState = layerState;
  62. // =================== ROWS ====================
  63. Key* const ptrsKeys_0[] = { &o_capsLock, &k_01 };
  64. uint8_t keyCount_0 = sizeof(ptrsKeys_0)/sizeof(*ptrsKeys_0);
  65. Row row_0(scanner, 0, ptrsKeys_0, keyCount_0);
  66. Key* const ptrsKeys_1[] = { &l_fn, &k_11 };
  67. uint8_t keyCount_1 = sizeof(ptrsKeys_1)/sizeof(*ptrsKeys_1);
  68. Row row_1(scanner, 1, ptrsKeys_1, keyCount_1);
  69. /* ################### MAIN ####################
  70. layerState.begin() turns on the LED of the default layer.
  71. */
  72. void setup()
  73. {
  74. layerState.begin();
  75. }
  76. void loop()
  77. {
  78. row_0.process();
  79. row_1.process();
  80. scanDelay.delay();
  81. }