Blink based on a file a transferred over Bluetooth

Hi I have a BLE 33 and I would like to ask my device blink based on selection in an iOS app.

Here are things I already know how to do:

  1. Connect to the BLE 33 in iPhone and write characteristics
  2. How to blink an LED in a program that transfer through USB to BLE 33

Here are things I need some pointers:
Instead of writing:

void loop() {
digitalWrite(D11, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(D11, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

How do I ask D11 to blink based on a file on Arduino e.g. Json or binary? My assumption is some pseudo code like this:

load_json_library
load_json_file
parse_json_file and get PORT and TIME
void loop() {
digitalWrite(PORT, HIGH); // turn the LED on (HIGH is the voltage level)
delay(TIME); // wait for a second
digitalWrite(PORT, LOW); // turn the LED off by making the voltage LOW
delay(TIME); // wait for a second
}
Am I on the right track? Could you please share some links of similar examples that I could follow? Thank you!

you got it except all this has to be in the loop and the blinking needs to be a state machine based on what command you received

void loop() {
  if (I_got_a_new_request()) {
    parse_new_request(activeCommand); // for example update the activeCommand if parse successful 
  } 
  if (there_is_an_active_command()) {
    execute_comand_without_delay();
  }
}

You need to make sure the blinking (or whatever the command does) is non blocking as you want to check for requests as often as possible . For extra information and examples look at Using millis() for timing. A beginners guide and Several things at the same time

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.