Hi everyone. I wanted to ask you for help with my problem with a code for Dartslive home. The code seems to work fine and connects to bluetooth fine, but I can't find the 11 single sectors (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11). I found all the others, including the take out and button to switch rounds. I'm pasting the code hoping someone can help me. Thank you.
#include <Keypad.h>
#include <BLEDevice.h>
#include <BLE2902.h>
#include "MultiMap.h"
BLEServer* pServer = NULL;
BLECharacteristic* pCharacteristic = NULL;
BLECharacteristic* pCharacteristic2 = NULL;
bool deviceConnected = false;
bool oldDeviceConnected = false;
int32_t value = 0;
int txValue = 0;
char customKey = 0;
int compare_value = 0;
#define SERVICE_UUID "xxx"
#define CHARACTERISTIC_UUID "xxx"
#define CHARACTERISTIC_UUID2 "xxx"
class MyServerCallbacks: public BLEServerCallbacks {
void onConnect(BLEServer* pServer) {
deviceConnected = true;
BLEDevice::startAdvertising();
}
void onDisconnect(BLEServer* pServer) {
deviceConnected = false;
}
};
const byte ROWS = 4;
const byte COLS = 16;
char hexaKeys[] = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'X', 'T', 'U', 'V', 'W', 'S', 'Y', 'Z', '1', '2', '3', '4', '5', '6',
'7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '!', '@', '#',
};
int Keys[] = {
33, 34, 35, 36, 37, 38, 40, 41, 42, 43, 44, 45, 46, 47, // !, ", #, $, %, &, (, ), *, +, ,, -, ., /,
49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, //1, 2, 3, 4, 5, 6, 7, 8, 9, :, ;, <, =, >,
63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, //?, @, A, B, C, D, E, F, G, H, I, J, K, L,
77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, //M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z,
91, 92, 93, 94, 95, 97, 98, 99, 100, 101, 102, 103, 104, 105, //[, \, ], ^, _, a, b, c, d, e, f, g, h, i,
106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, //j, k, l, m, n, o, p, q, r, s, t, u, v, w,
120, 121, 122, 123, 125,
};
char *results[] = {
"0.0@", "A1", "0.2@", "A2", "A3", "A4", "A5", "A6", "A7", "A8", "A9", "B1", "B2", "B3",
"0.1@", "0.3@", "0.4@", "0.5@", "0.6@", "0.7@", "0.8@", "0.9@", "0.;@", "B5", "B6", "B7", "B8", "B9",
"C1", "0.B@", "0.C@", "0.D@", "0.E@", "0.F@", "0.G@", "0.H@", "0.I@", "0.Q@", "0.K@", "0.L@", "C2", "0.N@",
"0.O@", "0.J@", "0.P@", "0.R@", "0.S@", "0.T@", "0.A@", "0.M@", "0.!@", "0.(@", "0.$@", "0.%@", "0.&@", "0./@",
"C3", "C4", "C5", "C6", "C7", "0.)@", "0.=@", "0.?@", "0.-@", "0.@@", "0.,@", "0.+@", "BTN@", "0.*@",
"0..@", "0.:@", "0.#@", "0.<@", "0.>@", "0.'@", "0. @", "0.a@", "0.b@", "0.c@", "0.d@", "0.e@", "0.f@", "0.g@",
"0.h@", "0.i@", "0.j@", "0.q@", "0.l@",
};
int results_ind[89];
int len = sizeof(Keys) / sizeof(Keys[0]);
byte colPins[COLS] = {12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23, 25, 26, 27, 32, 33,};
byte rowPins[ROWS] = {34, 35, 36, 39,};
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
String inputString;
long inputInt;
void setup()
{
Serial.begin(115200);
for (int i = 0; i < ROWS; i++) {
pinMode(rowPins[i], INPUT_PULLUP);
}
for (int i = 0; i < COLS; i++) {
pinMode(colPins[i], OUTPUT);
digitalWrite(colPins[i], HIGH);
}
inputString.reserve(10); // maximum number of digit for a number is 10, change if needed
BLEDevice::init("xxxx");
pServer = BLEDevice::createServer();
pServer->setCallbacks(new MyServerCallbacks());
BLEService *pService = pServer->createService(SERVICE_UUID);
pCharacteristic = pService->createCharacteristic(
CHARACTERISTIC_UUID,
BLECharacteristic::PROPERTY_NOTIFY |
BLECharacteristic::PROPERTY_READ
);
pCharacteristic2 = pService->createCharacteristic(
CHARACTERISTIC_UUID2,
BLECharacteristic::PROPERTY_WRITE_NR
);
pCharacteristic->addDescriptor(new BLE2902());
pService->start();
BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
pAdvertising->addServiceUUID(SERVICE_UUID);
pAdvertising->setScanResponse(true);
pAdvertising->setMinPreferred(0x00); // functions that help with iPhone connections issue
BLEDevice::startAdvertising();
customKeypad.setHoldTime(50);
customKeypad.setDebounceTime(1);
for (int i = 0; i < 89; i++) {
results_ind[i] = i;
}
Serial.println("Waiting a client connection to notify...");
}
void loop() {
if (deviceConnected) {
customKey = customKeypad.waitForKey();
compare_value = int(customKey);
// delay(20); //delay is from time segment is hit till it reads in app
if (customKey != NO_KEY)
{
pCharacteristic->setValue(results[multiMap(compare_value, Keys, results_ind, len)]);
Serial.println(results[multiMap(compare_value, Keys, results_ind, len)]);
pCharacteristic->notify();
value++;
// delay(20);
// break;
}
pCharacteristic->setValue("");
customKey = NULL;
compare_value = 0;
// break;
// delay(20);
}
}
