From 800b692b7cb192b58bb17c067571d024f6d52877 Mon Sep 17 00:00:00 2001 From: Adam Wyatt Date: Mon, 13 Oct 2025 12:03:02 +0800 Subject: [PATCH 01/11] feat: Add option to configure thresholds for each square --- LiBoard.cpp | 10 +++++- LiBoard.h | 1 + README.md | 36 ++++++++++++++++++++ examples/serial_binboard/serial_binboard.ino | 26 +++++++++++++- 4 files changed, 71 insertions(+), 2 deletions(-) diff --git a/LiBoard.cpp b/LiBoard.cpp index 65658c0..76a689e 100644 --- a/LiBoard.cpp +++ b/LiBoard.cpp @@ -60,7 +60,7 @@ void LiBoard::getData() { unsigned char LiBoard::getIndex(unsigned char file, unsigned char rank) { //Little-endian Rank-File Mapping - return (rank * 8) + file; + return ((7 - rank) * 8) + (7 - file); } unsigned long long LiBoard::getBinaryBoard(unsigned short threshold) { @@ -71,6 +71,14 @@ unsigned long long LiBoard::getBinaryBoard(unsigned short threshold) { return binBoard; } +unsigned long long LiBoard::getBinaryBoard(unsigned short *thresholds) { + getData(); + unsigned long long binBoard = 0; + for (unsigned char i = 0; i<64; ++i) + binBoard |= (((unsigned long long) (values[i]<=thresholds[i])) << i); + return binBoard; +} + bool LiBoard::getSquareOccupancy(unsigned char file, unsigned char rank, long long binaryBoard) { return (bool)((binaryBoard>>getIndex(file, rank))&1); } diff --git a/LiBoard.h b/LiBoard.h index 2e618ab..608a9f5 100644 --- a/LiBoard.h +++ b/LiBoard.h @@ -30,6 +30,7 @@ class LiBoard { void getData(); unsigned char getIndex(unsigned char file, unsigned char rank); unsigned long long getBinaryBoard(unsigned short threshold); + unsigned long long getBinaryBoard(unsigned short *thresholds); bool getSquareOccupancy(unsigned char file, unsigned char rank, long long binaryBoard); private: void clockPulse(); diff --git a/README.md b/README.md index 806e741..981eda2 100644 --- a/README.md +++ b/README.md @@ -7,3 +7,39 @@ Clone this repo into `YOUR_ARDUINO_FOLDER/libraries/`. ## Usage If you're just interested in using the board with a script or the app, you'll want to run the `serial_binboard` sketch from the library's examples folder. + +## Thresholds +Each photoresistor requires a theshold value which triggers when each square is occupied or not. There are two options you can use to set the threshold values for each square. + +### Option 1 - Global Threshold +By default, a global threshold is set for every phtooresistor. If you need to change the sensitivity of the photoresistors, change the value of this variable: +```bash +// Option 1 - Global Threshold (Applies to all photoresistors) +const unsigned short THRESHOLD = 500; +``` + +### Option 2 - Per-square threshold +If you require each photoresistor to have its own threshold rather than a global threshold, comment out Option 1 and uncomment Option 2. + +You can adjust each square threshold individually by editing each number. +```bash +// Option 2 - Per-square threshold (Applies to each individual photoresistor) +unsigned short THRESHOLD[64] = { + // A1..H1 + 150, 150, 150, 150, 150, 150, 150, 150, + // A2..H2 + 150, 150, 150, 150, 150, 150, 150, 150, + // A3..H3 + 100, 100, 100, 100, 100, 100, 100, 100, + // A4..H4 + 100, 100, 100, 100, 100, 100, 100, 100, + // A5..H5 + 600, 600, 600, 600, 600, 600, 600, 600, + // A6..H6 + 600, 600, 600, 600, 600, 600, 600, 600, + // A7..H7 + 300, 300, 300, 300, 300, 300, 300, 300, + // A8..H8 + 300, 300, 300, 300, 300, 300, 300, 300 +}; +``` diff --git a/examples/serial_binboard/serial_binboard.ino b/examples/serial_binboard/serial_binboard.ino index 928c513..63948c8 100644 --- a/examples/serial_binboard/serial_binboard.ino +++ b/examples/serial_binboard/serial_binboard.ino @@ -15,7 +15,30 @@ #include "LiBoard.h" -const unsigned short THRESHOLD = 100; +// Option 1 - Global Threshold (Applies to all photoresistors) +const unsigned short THRESHOLD = 500; + +// Option 2 - Per-square threshold (Applies to each individual photoresistor) +/* +unsigned short THRESHOLD[64] = { + // A1..H1 + 150, 150, 150, 150, 150, 150, 150, 150, + // A2..H2 + 150, 150, 150, 150, 150, 150, 150, 150, + // A3..H3 + 100, 100, 100, 100, 100, 100, 100, 100, + // A4..H4 + 100, 100, 100, 100, 100, 100, 100, 100, + // A5..H5 + 600, 600, 600, 600, 600, 600, 600, 600, + // A6..H6 + 600, 600, 600, 600, 600, 600, 600, 600, + // A7..H7 + 300, 300, 300, 300, 300, 300, 300, 300, + // A8..H8 + 300, 300, 300, 300, 300, 300, 300, 300 +}; +*/ LiBoard board = LiBoard(); unsigned long long lastBinBoard = 0; @@ -32,6 +55,7 @@ void setup() { } void loop() { + currentBinBoard = board.getBinaryBoard(THRESHOLD); if (currentBinBoard != lastBinBoard) { writeBinaryBoard(currentBinBoard); From ded1a405b0459de7d36c95f8dcd5ec1742881ece Mon Sep 17 00:00:00 2001 From: Adam Wyatt Date: Mon, 13 Oct 2025 12:05:13 +0800 Subject: [PATCH 02/11] fix: typo --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 981eda2..c6a74db 100644 --- a/README.md +++ b/README.md @@ -9,11 +9,11 @@ If you're just interested in using the board with a script or the app, you'll wa to run the `serial_binboard` sketch from the library's examples folder. ## Thresholds -Each photoresistor requires a theshold value which triggers when each square is occupied or not. There are two options you can use to set the threshold values for each square. +Each photoresistor requires a threshold value which triggers when each square is occupied or not. There are two options you can use to set the threshold values for each square. ### Option 1 - Global Threshold By default, a global threshold is set for every phtooresistor. If you need to change the sensitivity of the photoresistors, change the value of this variable: -```bash +```C // Option 1 - Global Threshold (Applies to all photoresistors) const unsigned short THRESHOLD = 500; ``` @@ -22,7 +22,7 @@ const unsigned short THRESHOLD = 500; If you require each photoresistor to have its own threshold rather than a global threshold, comment out Option 1 and uncomment Option 2. You can adjust each square threshold individually by editing each number. -```bash +```C // Option 2 - Per-square threshold (Applies to each individual photoresistor) unsigned short THRESHOLD[64] = { // A1..H1 From 3886b70bfb78a12f5251bab788eac8bcb4039b95 Mon Sep 17 00:00:00 2001 From: Adam Wyatt Date: Mon, 13 Oct 2025 12:08:32 +0800 Subject: [PATCH 03/11] fix: Removed 180-reverse of board configuration --- LiBoard.cpp | 2 +- examples/serial_binboard/serial_binboard.ino | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/LiBoard.cpp b/LiBoard.cpp index 76a689e..12e62fd 100644 --- a/LiBoard.cpp +++ b/LiBoard.cpp @@ -60,7 +60,7 @@ void LiBoard::getData() { unsigned char LiBoard::getIndex(unsigned char file, unsigned char rank) { //Little-endian Rank-File Mapping - return ((7 - rank) * 8) + (7 - file); + return (rank * 8) + file; } unsigned long long LiBoard::getBinaryBoard(unsigned short threshold) { diff --git a/examples/serial_binboard/serial_binboard.ino b/examples/serial_binboard/serial_binboard.ino index 63948c8..44082e6 100644 --- a/examples/serial_binboard/serial_binboard.ino +++ b/examples/serial_binboard/serial_binboard.ino @@ -55,7 +55,6 @@ void setup() { } void loop() { - currentBinBoard = board.getBinaryBoard(THRESHOLD); if (currentBinBoard != lastBinBoard) { writeBinaryBoard(currentBinBoard); From 12e263c078afb0622f27dfc5e8a8bc734ea303a1 Mon Sep 17 00:00:00 2001 From: Adam Wyatt <110982014+Ay1tsMe@users.noreply.github.com> Date: Mon, 13 Oct 2025 12:33:08 +0800 Subject: [PATCH 04/11] fix: Revert Default Threshold back to 100 --- examples/serial_binboard/serial_binboard.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/serial_binboard/serial_binboard.ino b/examples/serial_binboard/serial_binboard.ino index 44082e6..591110c 100644 --- a/examples/serial_binboard/serial_binboard.ino +++ b/examples/serial_binboard/serial_binboard.ino @@ -16,7 +16,7 @@ #include "LiBoard.h" // Option 1 - Global Threshold (Applies to all photoresistors) -const unsigned short THRESHOLD = 500; +const unsigned short THRESHOLD = 100; // Option 2 - Per-square threshold (Applies to each individual photoresistor) /* From 702b6630d9b01e47663cd521fcc09bc574fecd7b Mon Sep 17 00:00:00 2001 From: Adam Wyatt Date: Sat, 18 Oct 2025 14:38:40 +0800 Subject: [PATCH 05/11] feat: Calibration Mode so liboard can receive and edit threshold values --- examples/serial_binboard/serial_binboard.ino | 82 +++++++++++++++----- 1 file changed, 61 insertions(+), 21 deletions(-) diff --git a/examples/serial_binboard/serial_binboard.ino b/examples/serial_binboard/serial_binboard.ino index 591110c..8336267 100644 --- a/examples/serial_binboard/serial_binboard.ino +++ b/examples/serial_binboard/serial_binboard.ino @@ -16,29 +16,29 @@ #include "LiBoard.h" // Option 1 - Global Threshold (Applies to all photoresistors) -const unsigned short THRESHOLD = 100; +unsigned short THRESHOLD = 100; // Option 2 - Per-square threshold (Applies to each individual photoresistor) -/* -unsigned short THRESHOLD[64] = { - // A1..H1 - 150, 150, 150, 150, 150, 150, 150, 150, - // A2..H2 - 150, 150, 150, 150, 150, 150, 150, 150, - // A3..H3 - 100, 100, 100, 100, 100, 100, 100, 100, - // A4..H4 - 100, 100, 100, 100, 100, 100, 100, 100, - // A5..H5 - 600, 600, 600, 600, 600, 600, 600, 600, - // A6..H6 - 600, 600, 600, 600, 600, 600, 600, 600, - // A7..H7 - 300, 300, 300, 300, 300, 300, 300, 300, - // A8..H8 - 300, 300, 300, 300, 300, 300, 300, 300 -}; -*/ +//unsigned short THRESHOLD[64] = { + // A1-A8 +// 387, 398, 424, 493, 361, 353, 501, 309, + // B1-B8 +// 416, 422, 412, 417, 483, 426, 353, 419, + // C1-C8 +// 288, 266, 297, 229, 298, 267, 269, 309, + // D1-D8 +// 311, 328, 287, 300, 290, 313, 255, 438, + // E1-E8 +// 675, 708, 724, 717, 706, 690, 783, 729, + // F1-F8 +// 708, 707, 707, 686, 719, 722, 710, 662, + // G1-G8 +// 555, 573, 590, 659, 581, 580, 643, 650, + // H1-H8 +// 504, 474, 490, 643, 623, 651, 526, 647, +//}; + +bool calibrating = false; LiBoard board = LiBoard(); unsigned long long lastBinBoard = 0; @@ -49,12 +49,52 @@ void writeBinaryBoard(unsigned long long binBoard) { Serial.write((unsigned char)(binBoard>>(8*(7-i)))); } +// print a single CSV snapshot of raw ADC values (A1..H8 in LiBoard order) +void printRawSnapshotCSV() { + board.getData(); // fills board.values[0..63] + for (int i = 0; i < 64; ++i) { + Serial.print(board.values[i]); + if (i < 63) Serial.print(','); + } + Serial.println(); +} + void setup() { delay(3000); Serial.begin(9600); } void loop() { + if (Serial.available()) { + int c = Serial.read(); + // if host sends '?', reply with one CSV line of raw ADC values + if (c == '?') { + printRawSnapshotCSV(); + } + + if (c == 'c') { + calibrating = true; + Serial.println("Calibration Mode Activated!"); + } + + while (calibrating) { + if (Serial.available()){ + int p = Serial.peek(); + if (isDigit(p)) { + int newValue = Serial.parseInt(); + THRESHOLD = newValue; + Serial.print("THRESHOLD is now: "); + Serial.println(THRESHOLD); + calibrating = false; + } + // eat non-numeric to avoid getting stuck + else { + Serial.read(); + } + } + } + } + currentBinBoard = board.getBinaryBoard(THRESHOLD); if (currentBinBoard != lastBinBoard) { writeBinaryBoard(currentBinBoard); From e16c8de34c77b5301c942c091b6058253b98d8db Mon Sep 17 00:00:00 2001 From: Adam Wyatt Date: Sun, 19 Oct 2025 08:39:38 +0800 Subject: [PATCH 06/11] feat: add calibration mode and correct wrong labels --- examples/serial_binboard/serial_binboard.ino | 78 +++++++++++++------- 1 file changed, 50 insertions(+), 28 deletions(-) diff --git a/examples/serial_binboard/serial_binboard.ino b/examples/serial_binboard/serial_binboard.ino index 8336267..d5bc9d5 100644 --- a/examples/serial_binboard/serial_binboard.ino +++ b/examples/serial_binboard/serial_binboard.ino @@ -14,29 +14,36 @@ * along with this program. If not, see . */ #include "LiBoard.h" +#include +// !!! choose mode: 1 = global single value, 0 = per-square array !!! +#define USE_GLOBAL_THRESHOLD 0 + +#if USE_GLOBAL_THRESHOLD // Option 1 - Global Threshold (Applies to all photoresistors) unsigned short THRESHOLD = 100; +#else // Option 2 - Per-square threshold (Applies to each individual photoresistor) -//unsigned short THRESHOLD[64] = { - // A1-A8 -// 387, 398, 424, 493, 361, 353, 501, 309, - // B1-B8 -// 416, 422, 412, 417, 483, 426, 353, 419, - // C1-C8 -// 288, 266, 297, 229, 298, 267, 269, 309, - // D1-D8 -// 311, 328, 287, 300, 290, 313, 255, 438, - // E1-E8 -// 675, 708, 724, 717, 706, 690, 783, 729, - // F1-F8 -// 708, 707, 707, 686, 719, 722, 710, 662, - // G1-G8 -// 555, 573, 590, 659, 581, 580, 643, 650, - // H1-H8 -// 504, 474, 490, 643, 623, 651, 526, 647, -//}; +unsigned short THRESHOLD[64] = { + // A1-H1 + 10, 10, 10, 10, 361, 353, 501, 309, + // A2-H2 + 416, 422, 412, 417, 483, 426, 353, 419, + // A3-H3 + 288, 266, 297, 229, 298, 267, 269, 309, + // A4-H4 + 311, 328, 287, 300, 290, 313, 255, 438, + // A5-H5 + 675, 708, 724, 717, 706, 690, 783, 729, + // A6-H6 + 708, 707, 707, 686, 719, 722, 710, 662, + // A7-H7 + 555, 573, 590, 659, 581, 580, 643, 650, + // A8-H8 + 504, 474, 490, 643, 623, 651, 526, 10, +}; +#endif bool calibrating = false; @@ -65,6 +72,7 @@ void setup() { } void loop() { + // Serial Monitor arguements if (Serial.available()) { int c = Serial.read(); // if host sends '?', reply with one CSV line of raw ADC values @@ -72,6 +80,7 @@ void loop() { printRawSnapshotCSV(); } + // Calibration Mode for editing THRESHOLD if (c == 'c') { calibrating = true; Serial.println("Calibration Mode Activated!"); @@ -79,22 +88,35 @@ void loop() { while (calibrating) { if (Serial.available()){ - int p = Serial.peek(); - if (isDigit(p)) { - int newValue = Serial.parseInt(); - THRESHOLD = newValue; - Serial.print("THRESHOLD is now: "); - Serial.println(THRESHOLD); - calibrating = false; + // read a whole line the user pasted + String line = Serial.readStringUntil('\n'); + line.trim(); + if (line.length() == 0) continue; + +#if USE_GLOBAL_THRESHOLD + // Global Threshold Calibration + long newThreshold = line.toInt(); + THRESHOLD = (unsigned short)newThreshold; +#else + // Per-Square Calibration + char buf[1024]; + line.toCharArray(buf, 1024); + char* tok = strtok(buf, ","); + + int i = 0; + while (tok && i < 64) { + THRESHOLD[i++] = (unsigned short)atoi(tok); + tok = strtok(nullptr, ","); } +#endif + calibrating = false; // eat non-numeric to avoid getting stuck - else { - Serial.read(); - } + while (Serial.available()) Serial.read(); } } } + // Bitboard logic for normal use currentBinBoard = board.getBinaryBoard(THRESHOLD); if (currentBinBoard != lastBinBoard) { writeBinaryBoard(currentBinBoard); From 953754845b6c806b1bde18af9061ab78e358012c Mon Sep 17 00:00:00 2001 From: Adam Wyatt <110982014+Ay1tsMe@users.noreply.github.com> Date: Sun, 19 Oct 2025 10:35:21 +0800 Subject: [PATCH 07/11] Update threshold values for photoresistors --- examples/serial_binboard/serial_binboard.ino | 32 ++++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/examples/serial_binboard/serial_binboard.ino b/examples/serial_binboard/serial_binboard.ino index d5bc9d5..4d7eeb6 100644 --- a/examples/serial_binboard/serial_binboard.ino +++ b/examples/serial_binboard/serial_binboard.ino @@ -26,22 +26,22 @@ unsigned short THRESHOLD = 100; #else // Option 2 - Per-square threshold (Applies to each individual photoresistor) unsigned short THRESHOLD[64] = { - // A1-H1 - 10, 10, 10, 10, 361, 353, 501, 309, - // A2-H2 - 416, 422, 412, 417, 483, 426, 353, 419, - // A3-H3 - 288, 266, 297, 229, 298, 267, 269, 309, - // A4-H4 - 311, 328, 287, 300, 290, 313, 255, 438, - // A5-H5 - 675, 708, 724, 717, 706, 690, 783, 729, - // A6-H6 - 708, 707, 707, 686, 719, 722, 710, 662, - // A7-H7 - 555, 573, 590, 659, 581, 580, 643, 650, - // A8-H8 - 504, 474, 490, 643, 623, 651, 526, 10, + // A1..H1 + 150, 150, 150, 150, 150, 150, 150, 150, + // A2..H2 + 150, 150, 150, 150, 150, 150, 150, 150, + // A3..H3 + 100, 100, 100, 100, 100, 100, 100, 100, + // A4..H4 + 100, 100, 100, 100, 100, 100, 100, 100, + // A5..H5 + 600, 600, 600, 600, 600, 600, 600, 600, + // A6..H6 + 600, 600, 600, 600, 600, 600, 600, 600, + // A7..H7 + 300, 300, 300, 300, 300, 300, 300, 300, + // A8..H8 + 300, 300, 300, 300, 300, 300, 300, 300, }; #endif From ff9ab19b6008dea92fa5ae5a108ca0ff5700e32d Mon Sep 17 00:00:00 2001 From: Adam Wyatt Date: Sun, 19 Oct 2025 11:51:55 +0800 Subject: [PATCH 08/11] feat: '!' command that prints out THRESHOLD variable value --- examples/serial_binboard/serial_binboard.ino | 22 +++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/examples/serial_binboard/serial_binboard.ino b/examples/serial_binboard/serial_binboard.ino index 4d7eeb6..a5d7ccf 100644 --- a/examples/serial_binboard/serial_binboard.ino +++ b/examples/serial_binboard/serial_binboard.ino @@ -17,7 +17,7 @@ #include // !!! choose mode: 1 = global single value, 0 = per-square array !!! -#define USE_GLOBAL_THRESHOLD 0 +#define USE_GLOBAL_THRESHOLD 1 #if USE_GLOBAL_THRESHOLD // Option 1 - Global Threshold (Applies to all photoresistors) @@ -66,6 +66,21 @@ void printRawSnapshotCSV() { Serial.println(); } +// print current threshold values as CSV +void printCurrentThreshold() { +#if USE_GLOBAL_THRESHOLD + // Global Threshold - print one value + Serial.println(THRESHOLD); +#else + // Individual Thresholds - print 64 values + for (int i = 0; i < 64; ++i) { + Serial.print(THRESHOLD[i]); + if (i < 63) Serial.print(','); + } + Serial.println(); +#endif +} + void setup() { delay(3000); Serial.begin(9600); @@ -80,6 +95,11 @@ void loop() { printRawSnapshotCSV(); } + // if host sends '!', reply with current threshold values + if (c == '!') { + printCurrentThreshold(); + } + // Calibration Mode for editing THRESHOLD if (c == 'c') { calibrating = true; From cfb9372bb58cb31d401674eeeb41569410001b01 Mon Sep 17 00:00:00 2001 From: Adam Wyatt Date: Sun, 19 Oct 2025 12:19:07 +0800 Subject: [PATCH 09/11] feat: Edit documentation to reflect current code --- README.md | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index c6a74db..cc20cdc 100644 --- a/README.md +++ b/README.md @@ -11,17 +11,23 @@ to run the `serial_binboard` sketch from the library's examples folder. ## Thresholds Each photoresistor requires a threshold value which triggers when each square is occupied or not. There are two options you can use to set the threshold values for each square. +### Setting Threshold Mode +By default, Liboard is configured to use the Global threshold mode. If you want to change it Per-Square thresholds, then edit the following variable: + +``` C +// !!! choose mode: 1 = global single value, 0 = per-square array !!! +#define USE_GLOBAL_THRESHOLD 1 +``` + ### Option 1 - Global Threshold -By default, a global threshold is set for every phtooresistor. If you need to change the sensitivity of the photoresistors, change the value of this variable: +Global Threshold mode applies the same threshold value to every photoresistor. If you need to change the sensitivity of the photoresistors, change the value of this variable: ```C // Option 1 - Global Threshold (Applies to all photoresistors) -const unsigned short THRESHOLD = 500; +const unsigned short THRESHOLD = 100; ``` -### Option 2 - Per-square threshold -If you require each photoresistor to have its own threshold rather than a global threshold, comment out Option 1 and uncomment Option 2. - -You can adjust each square threshold individually by editing each number. +### Option 2 - Per-square Thresholds +You can also set individual thresholds for each photoresisor. This is useful if not all your photoresistors are the same type. Per-square thresholds also has more accuracy. You can adjust each square threshold individually by editing each number. ```C // Option 2 - Per-square threshold (Applies to each individual photoresistor) unsigned short THRESHOLD[64] = { From 6113ee4b2fce3bbe158779e8152785bbc69eacb0 Mon Sep 17 00:00:00 2001 From: Adam Wyatt Date: Sun, 19 Oct 2025 12:21:13 +0800 Subject: [PATCH 10/11] fix: typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cc20cdc..0d6bce3 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ By default, Liboard is configured to use the Global threshold mode. If you want Global Threshold mode applies the same threshold value to every photoresistor. If you need to change the sensitivity of the photoresistors, change the value of this variable: ```C // Option 1 - Global Threshold (Applies to all photoresistors) -const unsigned short THRESHOLD = 100; +unsigned short THRESHOLD = 100; ``` ### Option 2 - Per-square Thresholds From de13f8f2b175882a375753a648c7b10557681b3a Mon Sep 17 00:00:00 2001 From: Adam Wyatt Date: Wed, 22 Oct 2025 18:31:22 +0800 Subject: [PATCH 11/11] feat: Quiet mode command to stop and resume bitboard output --- examples/serial_binboard/serial_binboard.ino | 27 +++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/examples/serial_binboard/serial_binboard.ino b/examples/serial_binboard/serial_binboard.ino index a5d7ccf..1e4c3ea 100644 --- a/examples/serial_binboard/serial_binboard.ino +++ b/examples/serial_binboard/serial_binboard.ino @@ -17,7 +17,7 @@ #include // !!! choose mode: 1 = global single value, 0 = per-square array !!! -#define USE_GLOBAL_THRESHOLD 1 +#define USE_GLOBAL_THRESHOLD 0 #if USE_GLOBAL_THRESHOLD // Option 1 - Global Threshold (Applies to all photoresistors) @@ -27,9 +27,9 @@ unsigned short THRESHOLD = 100; // Option 2 - Per-square threshold (Applies to each individual photoresistor) unsigned short THRESHOLD[64] = { // A1..H1 - 150, 150, 150, 150, 150, 150, 150, 150, + 300, 300, 300, 300, 300, 300, 300, 300, // A2..H2 - 150, 150, 150, 150, 150, 150, 150, 150, + 300, 300, 300, 300, 300, 300, 300, 300, // A3..H3 100, 100, 100, 100, 100, 100, 100, 100, // A4..H4 @@ -46,6 +46,7 @@ unsigned short THRESHOLD[64] = { #endif bool calibrating = false; +bool quiet = false; LiBoard board = LiBoard(); unsigned long long lastBinBoard = 0; @@ -100,6 +101,16 @@ void loop() { printCurrentThreshold(); } + // Toggle quiet mode (Used to silence bitboard output) + if (c == 'q' && quiet == false) { + quiet = true; + Serial.println("Quiet Mode Activated!"); + } + else if (c == 'q' && quiet == true) { + quiet = false; + Serial.println("Exited Quiet Mode!"); + } + // Calibration Mode for editing THRESHOLD if (c == 'c') { calibrating = true; @@ -137,9 +148,11 @@ void loop() { } // Bitboard logic for normal use - currentBinBoard = board.getBinaryBoard(THRESHOLD); - if (currentBinBoard != lastBinBoard) { - writeBinaryBoard(currentBinBoard); - lastBinBoard = currentBinBoard; + if (!quiet && !calibrating) { + currentBinBoard = board.getBinaryBoard(THRESHOLD); + if (currentBinBoard != lastBinBoard) { + writeBinaryBoard(currentBinBoard); + lastBinBoard = currentBinBoard; + } } }