Help me figure this out

Darts register with finger press but not with a dart throw


#include <Keypad.h>
#include <BLEDevice.h>
#include <BLE2902.h>
#include "MultiMap.h"
BLEServer* pServer = NULL;

BLECharacteristic* pCharacteristic = NULL;

bool deviceConnected = false;
bool oldDeviceConnected = false;
int32_t value = 0;
int txValue = 0;
//int customKey = 0;
char customKey = 0;
int compare_value =0;

#define SERVICE_UUID        "4400000-8a00-9a28-cbe1-e1d4212d53eb"
#define CHARACTERISTIC_UUID "44200000-8a00-9a28-cbe1-e1d4212d53eb"
//#define CHARACTERISTIC_UUID2 "44200000-8a00-9a28-cbe1-e1d4212d53eb"


class MyServerCallbacks: public BLEServerCallbacks {
    void onConnect(BLEServer* pServer) {
      deviceConnected = true;
      BLEDevice::startAdvertising();
    };

    void onDisconnect(BLEServer* pServer) {
      deviceConnected = false;
    }
};

const byte ROWS = 8;
const byte COLS = 11;
const int debounceTime = 7;//20 works better than great !
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,                                                 //x, y, z, {, }
};

char *results[] = { 
  "0.2@", "5.4@", "5.3@", "5.2@", "3.4@", "6.5@", "11.4@", "11.6@", "11.5@", "XXXX", "4.5@", "XXXX",  "5.6@", "3.6@",
  "7.2@", "XXXX", "0.4@", "0.5@", "1.5@", "4.4@", "2.5@", "4.3@", "4.2@", "5.5@", "9.5@", "9.6@", "8.5@", "4.6@",
  "0.4@", "9.4@", "2.0@", "3.0@", "9.1@", "10.1@", "7.1@", "BTN@", "0.0@", "0.1@", "1.2@", "1.0@", "2.3@", "2.1@",
  "3.1@", "9.0@", "10.0@", "7.0@", "XXXX", "0.2@", "3.2@", "1.4@", "1.1@", "2.4@", "2.2@", "0.3@", "9.2@", "10.2@",
  "3.5@", "XXXX", "6.6@", "7.5@", "8.6@", "8.2@", "8.3@", "8.4@", "XXXX", "4.5@", "0.6@", "1.6@", "4.4@", "2.6@",
  "7.3@", "6.2@", "11.0@", "11.1@", "6.1@", "4.0@", "0.0@", "9.3@", "5.0@", "5.1@", "3.3@", "7.4@", "6.4@", "11.3@",
  "11.2@", "6.0@", "8.0@", "7.6@", "11.6@",         
};

int results_ind[89];
int len = sizeof(Keys)/sizeof(Keys[0]);

byte colPins[COLS] = {12, 13, 14, 15, 18, 23, 25, 26, 27, 32, 33,};
byte rowPins[ROWS] =  {0, 2, 3, 4, 5, 19, 21, 22,};

Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

String inputString;
long inputInt;
//BluetoothSerial SerialBT;

void setup()
{
  Serial.begin(115200);
  inputString.reserve(10); // maximum number of digit for a number is 10, change if needed

  // Create the BLE Device
  BLEDevice::init("BOARD");

  // Create the BLE Server
  pServer = BLEDevice::createServer();
  pServer->setCallbacks(new MyServerCallbacks());

  // Create the BLE Service
  BLEService *pService = pServer->createService(SERVICE_UUID);
  // Create a BLE Characteristic
  pCharacteristic = pService->createCharacteristic(
                      CHARACTERISTIC_UUID,
                      BLECharacteristic::PROPERTY_READ   |
                      BLECharacteristic::PROPERTY_NOTIFY
                    );

  // Create a BLE Descriptor
  pCharacteristic->addDescriptor(new BLE2902());

  // Start the service
  pService->start();

  // Start advertising
  BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
  pAdvertising->addServiceUUID(SERVICE_UUID);
  pAdvertising->setScanResponse(false);
  pAdvertising->setMinPreferred(0x00);  // set value to 0x00 to not advertise this parameter
  BLEDevice::startAdvertising();

  //Initialize the indexing array
  for(int i= 0; i<89; i++) { results_ind[i] = i; }
  
  Serial.println("Waiting a client connection to notify...");
}
void loop() {

  while (deviceConnected) {
    customKey = customKeypad.getKey();
    compare_value = int(customKey);
    delay(100);
    if (customKey!= NO_KEY)
    {
    pCharacteristic->setValue(results[multiMap(compare_value, Keys, results_ind, len)]);
    }
    pCharacteristic->notify();
    value++;
    delay(100);
    pCharacteristic->setValue("");
    customKey = NULL;
    compare_value = 0;
    break;
   // delay(6);
  }
}

Why are you wasting so much memory here with Strings?

Please remember to use code tags when posting code.
And please post the actual error messages.
All of them..

I thought I did use code tags I hit the </> button. I guess I dont know what Im doing. lol what did I do wrong

Apart from using inappropriate Strings?

C:\Users\panic\OneDrive\Desktop\arduino working code\granboardtestvals2\granboardtestvals2.ino: In function 'void loop()':
granboardtestvals2:133:80: error: no matching function for call to 'BLECharacteristic::setValue(String&)'
pCharacteristic->setValue(results[multiMap(value, Keys, results_ind, 89)]);
^
In file included from C:\Users\panic\OneDrive\Documents\Arduino\libraries\ESP32_BLE_Arduino\src/BLEServer.h:20:0,
from C:\Users\panic\OneDrive\Documents\Arduino\libraries\ESP32_BLE_Arduino\src/BLEDevice.h:18,
from C:\Users\panic\OneDrive\Desktop\arduino working code\granboardtestvals2\granboardtestvals2.ino:2:
C:\Users\panic\OneDrive\Documents\Arduino\libraries\ESP32_BLE_Arduino\src/BLECharacteristic.h:73:7: note: candidate: void BLECharacteristic::setValue(uint8_t*, size_t)
void setValue(uint8_t* data, size_t size);
^
C:\Users\panic\OneDrive\Documents\Arduino\libraries\ESP32_BLE_Arduino\src/BLECharacteristic.h:73:7: note: candidate expects 2 arguments, 1 provided
C:\Users\panic\OneDrive\Documents\Arduino\libraries\ESP32_BLE_Arduino\src/BLECharacteristic.h:74:7: note: candidate: void BLECharacteristic::setValue(std::__cxx11::string)
void setValue(std::string value);
^
C:\Users\panic\OneDrive\Documents\Arduino\libraries\ESP32_BLE_Arduino\src/BLECharacteristic.h:74:7: note: no known conversion for argument 1 from 'String' to 'std::__cxx11::string {aka std::__cxx11::basic_string}'
C:\Users\panic\OneDrive\Documents\Arduino\libraries\ESP32_BLE_Arduino\src/BLECharacteristic.h:75:7: note: candidate: void BLECharacteristic::setValue(uint16_t&)
void setValue(uint16_t& data16);
^
C:\Users\panic\OneDrive\Documents\Arduino\libraries\ESP32_BLE_Arduino\src/BLECharacteristic.h:75:7: note: no known conversion for argument 1 from 'String' to 'uint16_t& {aka short unsigned int&}'
C:\Users\panic\OneDrive\Documents\Arduino\libraries\ESP32_BLE_Arduino\src/BLECharacteristic.h:76:7: note: candidate: void BLECharacteristic::setValue(uint32_t&)
void setValue(uint32_t& data32);
^
C:\Users\panic\OneDrive\Documents\Arduino\libraries\ESP32_BLE_Arduino\src/BLECharacteristic.h:76:7: note: no known conversion for argument 1 from 'String' to 'uint32_t& {aka unsigned int&}'
C:\Users\panic\OneDrive\Documents\Arduino\libraries\ESP32_BLE_Arduino\src/BLECharacteristic.h:77:7: note: candidate: void BLECharacteristic::setValue(int&)
void setValue(int& data32);
^
C:\Users\panic\OneDrive\Documents\Arduino\libraries\ESP32_BLE_Arduino\src/BLECharacteristic.h:77:7: note: no known conversion for argument 1 from 'String' to 'int&'
C:\Users\panic\OneDrive\Documents\Arduino\libraries\ESP32_BLE_Arduino\src/BLECharacteristic.h:78:7: note: candidate: void BLECharacteristic::setValue(float&)
void setValue(float& data32);
^
C:\Users\panic\OneDrive\Documents\Arduino\libraries\ESP32_BLE_Arduino\src/BLECharacteristic.h:78:7: note: no known conversion for argument 1 from 'String' to 'float&'
C:\Users\panic\OneDrive\Documents\Arduino\libraries\ESP32_BLE_Arduino\src/BLECharacteristic.h:79:7: note: candidate: void BLECharacteristic::setValue(double&)
void setValue(double& data64);
^
C:\Users\panic\OneDrive\Documents\Arduino\libraries\ESP32_BLE_Arduino\src/BLECharacteristic.h:79:7: note: no known conversion for argument 1 from 'String' to 'double&'
Multiple libraries were found for "BLEDevice.h"
Used: C:\Users\panic\OneDrive\Documents\Arduino\libraries\ESP32_BLE_Arduino
Not used: C:\Users\panic\OneDrive\Documents\Arduino\libraries\ArduinoBLE
Not used: C:\Users\panic\OneDrive\Documents\ArduinoData\packages\esp32\hardware\esp32\1.0.6\libraries\BLE
Not used: C:\Users\panic\OneDrive\Documents\Arduino\libraries\Seeed_Arduino_rpcBLE
exit status 1
no matching function for call to 'BLECharacteristic::setValue(String&)

I meant code tags but yes that as well Im doing my best with this code but I doesnt seem to be good enough

Look in the docs to find what data type that the BLECharacteristic::setValue() function of the BLEDevice.h libraty takes as an argument. I'll bet that Strings is not one of them.

Post error codes in code tags, too, please.

You can go back and fix your original post by highlighting the code and/or error messages and clicking the </> in the menu bar.
code tags new

ok I edited it

how would I do it without strings

I said to do it without Strings, not without strings.

There are Strings (members of the String class) and there are strings (null terminated character arrays). The terms are not interchangeable.

The compiler is happy with this

//String results[] = {
const char* results[] = {

The code is fixed and works. I replaced the code with the working code at the top. It is for a dartboard. if i just hit the segments with my finger it works but if I throw a dart at it nothing registers. I played with the delays alot making them less and more with no luck. do you have any suggestions

Post your code.

("alot" is not a word)

new code is at the top

That makes all the subsequent comments look stupid.

Welcome to my ignore-list.

I am sorry about that I am new to this.

I think that you should link to the lengthy thread from a few days ago so suggestions are not repeated.

I still think that the duration of the hit event is too short to be reliably sensed, but maybe I misunderstand how is supposed to work.

Hi,

Write some code that JUST detects the dart throw/finger press and see if the basics work.

So much code and now you find this problem, did you write it in stages?

Thanks.. Tom... :grinning: :+1: :coffee: :australia: