Hello,
I am currently working with a example code from Nordic for a BLE shield that I am using with the Arduino UNO. I can't seem to figure out how to modify the code so that after a button is pressed, an ascii code (0x04) will be sent from the arduino to the paired device. I understand that the example code repeats the letter a (which is 0x04) every 4 seconds.
I tried to remove the timer, which was fine. But when it comes to trying to make the letter 'a' appear by having a switch input, it would just constantly spam the letter 'a' even after releasing the switch. Can someone please give me some guidance and help clarify which aspects of the code is controlling the sending of the ascii code?
Thank you so much in advanced! I have attached the library files and everything that is needed. The example is called: ble_HID_keyboard_template
twinkies.
P.S I had to chop off most of the code so that it fits in the 9500 character limit. The rest of the code should be available in the attachment I provided!
void setup(void)
{
Serial.begin(115200);
Serial.println(F("Arduino setup"));
/**
Point ACI data structures to the the setup data that the nRFgo studio generated for the nRF8001
*/
if (NULL != services_pipe_type_mapping)
{
aci_state.aci_setup_info.services_pipe_type_mapping = &services_pipe_type_mapping[0];
}
else
{
aci_state.aci_setup_info.services_pipe_type_mapping = NULL;
}
aci_state.aci_setup_info.number_of_pipes = NUMBER_OF_PIPES;
aci_state.aci_setup_info.setup_msgs = setup_msgs;
aci_state.aci_setup_info.num_setup_msgs = NB_SETUP_MESSAGES;
//Tell the ACI library, the MCU to nRF8001 pin connections
aci_state.aci_pins.board_name = REDBEARLAB_SHIELD_V1_1; //REDBEARLAB_SHIELD_V1_1 See board.h for details
aci_state.aci_pins.reqn_pin = 9;
aci_state.aci_pins.rdyn_pin = 8;
aci_state.aci_pins.mosi_pin = MOSI;
aci_state.aci_pins.miso_pin = MISO;
aci_state.aci_pins.sck_pin = SCK;
aci_state.aci_pins.spi_clock_divider = SPI_CLOCK_DIV8;
aci_state.aci_pins.reset_pin = UNUSED;
aci_state.aci_pins.active_pin = UNUSED;
aci_state.aci_pins.optional_chip_sel_pin = UNUSED;
aci_state.aci_pins.interface_is_interrupt = false;
aci_state.aci_pins.interrupt_number = UNUSED;
/** We reset the nRF8001 here by toggling the RESET line connected to the nRF8001
* and initialize the data structures required to setup the nRF8001
*/
lib_aci_init(&aci_state);
pinMode(6, INPUT); //Pin #6 on Arduino -> PAIRING CLEAR pin: Connect to 3.3v to clear the pairing
if (0x01 == digitalRead(6))
{
//Clear the pairing
Serial.println(F("Pairing cleared. Remove the wire on Pin 6 and reset the board for normal operation."));
//Address. Value
EEPROM.write(0, 0);
while(1) {};
}
//Initialize the state of the bond
aci_state.bonded = ACI_BOND_STATUS_FAILED;
}
/* This is like a main() { while(1) { loop() } }
*/
void loop(void)
{
aci_loop();
/*
Method for sending HID Reports
*/
if (lib_aci_is_pipe_available(&aci_state, PIPE_HID_SERVICE_HID_REPORT_TX)
&& (aci_state.data_credit_available == 2)
&& (1 == timer1_f) )
{
timer1_f = 0;
keypressA[2] = 0x04;
lib_aci_send_data(PIPE_HID_SERVICE_HID_REPORT_TX, &keypressA[0], 8);
aci_state.data_credit_available--;
keypressA[2] = 0x00;
lib_aci_send_data(PIPE_HID_SERVICE_HID_REPORT_TX, &keypressA[0], 8);
aci_state.data_credit_available--;
}
}
BLE.zip (532 KB)