2016-09-20 03:59:05 +00:00
|
|
|
/* keybrd_3b_multi-layerLock.ino
|
2016-05-09 14:05:08 +00:00
|
|
|
|
|
|
|
This sketch:
|
2016-07-18 02:03:03 +00:00
|
|
|
is firmware for a simple 2-layer keyboard
|
2016-05-09 14:05:08 +00:00
|
|
|
runs on the first two rows and columns of a breadboard keyboard
|
|
|
|
|
|
|
|
| Layout | **0** | **1** |
|
2016-09-20 01:46:03 +00:00
|
|
|
|:------:|:-----:|:-----:|
|
2016-09-21 02:24:22 +00:00
|
|
|
| **0** | a - | b = |
|
2016-09-22 02:29:40 +00:00
|
|
|
| **1** | Alpha | Sym |
|
2016-09-21 02:24:22 +00:00
|
|
|
|
2016-09-22 02:29:40 +00:00
|
|
|
Pressing the "Alpha" layer key locks the Alpha layer.
|
|
|
|
Letters 'a' 'b' are on the Alpha layer.
|
2016-09-21 02:24:22 +00:00
|
|
|
|
|
|
|
Pressing the "Sym" layer key locks the Sym layer.
|
|
|
|
Symbols '-' '=' are on the Sym layer.
|
2016-05-09 14:05:08 +00:00
|
|
|
*/
|
|
|
|
// ################## GLOBAL ###################
|
|
|
|
// ================= INCLUDES ==================
|
2016-07-18 02:03:03 +00:00
|
|
|
//Keys
|
2016-05-09 14:05:08 +00:00
|
|
|
#include <Code_Sc.h>
|
2016-05-28 21:16:32 +00:00
|
|
|
#include <LayerState.h>
|
2016-09-20 01:46:03 +00:00
|
|
|
#include <Code_LayerLock.h>
|
2016-09-18 06:42:21 +00:00
|
|
|
#include <Key_LayeredKeys.h>
|
2016-05-09 14:05:08 +00:00
|
|
|
|
|
|
|
//Matrix
|
2016-09-17 05:45:12 +00:00
|
|
|
#include <Row.h>
|
|
|
|
#include <Scanner_uC.h>
|
2016-07-18 02:03:03 +00:00
|
|
|
#include <ScanDelay.h>
|
2016-05-09 14:05:08 +00:00
|
|
|
|
2016-07-18 02:03:03 +00:00
|
|
|
// ============ SPEED CONFIGURATION ============
|
|
|
|
ScanDelay scanDelay(9000);
|
2016-05-09 14:05:08 +00:00
|
|
|
|
2016-09-17 05:45:12 +00:00
|
|
|
// ================== SCANNER ==================
|
2016-07-18 02:03:03 +00:00
|
|
|
uint8_t readPins[] = {14, 15};
|
2016-09-17 05:45:12 +00:00
|
|
|
uint8_t readPinCount = sizeof(readPins)/sizeof(*readPins);
|
|
|
|
|
|
|
|
Scanner_uC scanner(LOW, readPins, readPinCount);
|
2016-05-09 14:05:08 +00:00
|
|
|
|
2016-09-21 02:24:22 +00:00
|
|
|
// =================== CODES ===================
|
|
|
|
// ---------------- LAYER CODE -----------------
|
2016-09-22 13:46:50 +00:00
|
|
|
enum layerIds { ALPHA, SYM };
|
2016-07-18 02:03:03 +00:00
|
|
|
|
2016-05-28 21:16:32 +00:00
|
|
|
LayerState layerState;
|
2016-07-18 02:03:03 +00:00
|
|
|
|
2016-05-09 14:05:08 +00:00
|
|
|
/*
|
2016-09-28 19:56:10 +00:00
|
|
|
Code_LayerLock constructor parameters are: layerId, LayerState.
|
|
|
|
layerId becomes the active layer when the key is pressed.
|
|
|
|
LayerState keeps track of the active layer.
|
|
|
|
In this example, when l_normal is pressed, ALPHA becomes the active layer.
|
2016-09-21 02:24:22 +00:00
|
|
|
When l_sym is pressed, SYM becomes the active layer.
|
2016-05-09 14:05:08 +00:00
|
|
|
*/
|
2016-09-22 02:29:40 +00:00
|
|
|
Code_LayerLock l_normal(ALPHA, layerState);
|
2016-09-20 01:46:03 +00:00
|
|
|
Code_LayerLock l_sym(SYM, layerState);
|
2016-05-09 14:05:08 +00:00
|
|
|
|
2016-11-21 13:13:44 +00:00
|
|
|
// ----------------- SCANCODES -----------------
|
2016-05-09 14:05:08 +00:00
|
|
|
Code_Sc s_a(KEY_A);
|
|
|
|
Code_Sc s_b(KEY_B);
|
2016-09-21 02:24:22 +00:00
|
|
|
Code_Sc s_minus(KEY_MINUS);
|
|
|
|
Code_Sc s_equal(KEY_EQUAL);
|
2016-09-20 01:46:03 +00:00
|
|
|
|
2016-09-21 02:24:22 +00:00
|
|
|
// =================== KEYS ====================
|
2016-09-22 02:29:40 +00:00
|
|
|
Key* const ptrsKeys_00[] = { &s_a, &s_minus };
|
|
|
|
Key_LayeredKeys k_00(ptrsKeys_00);
|
2016-05-09 14:05:08 +00:00
|
|
|
|
2016-09-22 02:29:40 +00:00
|
|
|
Key* const ptrsKeys_01[] = { &s_b, &s_equal };
|
|
|
|
Key_LayeredKeys k_01(ptrsKeys_01);
|
2016-07-18 02:03:03 +00:00
|
|
|
|
2016-09-18 06:42:21 +00:00
|
|
|
LayerStateInterface& Key_LayeredKeys::refLayerState = layerState;
|
2016-05-09 14:05:08 +00:00
|
|
|
|
2016-09-21 02:24:22 +00:00
|
|
|
// =================== ROWS ====================
|
2016-09-20 01:46:03 +00:00
|
|
|
Key* const ptrsKeys_0[] = { &k_00, &k_01 };
|
2016-09-17 05:45:12 +00:00
|
|
|
uint8_t keyCount_0 = sizeof(ptrsKeys_0)/sizeof(*ptrsKeys_0);
|
|
|
|
Row row_0(scanner, 0, ptrsKeys_0, keyCount_0);
|
2016-05-09 14:05:08 +00:00
|
|
|
|
2016-09-20 01:46:03 +00:00
|
|
|
Key* const ptrsKeys_1[] = { &l_normal, &l_sym };
|
2016-09-17 05:45:12 +00:00
|
|
|
uint8_t keyCount_1 = sizeof(ptrsKeys_1)/sizeof(*ptrsKeys_1);
|
|
|
|
Row row_1(scanner, 1, ptrsKeys_1, keyCount_1);
|
2016-05-09 14:05:08 +00:00
|
|
|
|
|
|
|
// ################### MAIN ####################
|
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void loop()
|
|
|
|
{
|
2016-07-18 02:03:03 +00:00
|
|
|
row_0.process();
|
|
|
|
row_1.process();
|
|
|
|
scanDelay.delay();
|
2016-05-09 14:05:08 +00:00
|
|
|
}
|