I'm working on a prototype which uses the RedBearLabs Blend Micro with the NSC's nrf8001 ble chip, but have ran into a problem that I'm not sure how to solve.
I have two tactile buttons connected to the input pins on the Blend Micro, which are used to increase or decrease counters (integers) in my sketch that is in turn displayed on a OLED screen. When I use these buttons to manipulate the counter in offline mode (meaning that the bluetooth is not connected) I can repeatedly press the buttons very quickly and the counter is increased with every push - but when I connect to my phone and try to push the buttons with high frequency (>1-2 per second) the program is not able to react to every button interaction, causing only every second or third click to be registered.
The only thing that I do differently when I am connected is that I'm sending 5 bytes using "ble_write" (part of the RBL nrf8001 library), which seem to cause this delay resulting in missed clicks. Even sending one byte using "ble_write(X)" seem to slow down the sketch so much that this phenomena occurs.
Do any of you had similar problems and possible ways to solve this? I've been considering batching clicks together until I reach a certain amount and then send them at all once - this however may risk that a button is being pressed at the same time as the ble_write is executed, causing missed click.
Offline click looks like this:
if(digitalRead(A4)) {
while (digitalRead(A4)) { }
offlineIn++;
localIn++;
totCount++;
sleepTimer = 0;
}
And the online like this:
if (digitalRead(A4)) {
while (digitalRead(A4)) { }
totCount++;
localIn++;
sleepTimer = 0;
ble_write('0');
ble_write('0');
ble_write('0');
ble_write('1');
ble_write('1');
}
Thanks!