1

I'm using my Arduino to make a speaker-like device. Instead of sound, it receives the beat of the song, thus the data comes in an array of floats. Each item in the array is a timestamp, an LED is turned on based on that value.

For example, [0.01,0.53] means sleep 0.01s, turn on LED, pop off 0.01, sleep 0.53 seconds, turn on LED.

I have two questions:

1)How can I receive data and pop off data at the same time? I'm thinking I can send maybe 10 items for the Arduino to buffer at one time, and repeat that until the whole action is done. The popping off action is time sensitive, so I can't do it sequentially. How can I run both functions at once? Are arduinos capable of multithreading?

2)I'm using an arduino with BLE and sending over the data using serial.read() from an iPhone. and the device only allows 18 bytes to be sent over at one time and it is very slow. What other methods can I use? I need to send 18 bytes from my iPhone, wait 2 seconds, then send it again otherwise the arduino treats it as one single send and the other values are not sent over.

3)Is there a better way of doing all of this that I'm missing?

Thank you very much.

asked Apr 28, 2020 at 3:46
16
  • The arduino keeps time in microseconds. You can't have fractional microseconds. It only lets you have integer microseconds. floats are inherently inaccurate. They simply cannot hold many values exactly, they're just approximations. Using floats here is not good. You should be using unsigned long variables instead and keeping time in milliseconds instead of seconds. That will greatly improve performance once you get it done and also make your work easier. Commented Apr 28, 2020 at 4:01
  • Arduino can't multithread, but you can certainly have code that is constantly switching back and forth checking each thing once every few microseconds. You just have to write your code to do things in short chunks. It's called "non-blocking" code. Look that up. Commented Apr 28, 2020 at 4:02
  • Answer to #2: It really depends on what exactly you're using. That doesn't sound like a normal limitation. It has to be an issue with either the module you have or the software you're using somewhere. You have to share all those kinds of details if you really want help. Commented Apr 28, 2020 at 4:04
  • Answer #3. You haven't really explained the end goal or what you want to actually accomplish. Are you blinking lights to the beat or something? Either way, there is probably a better way to do it. Commented Apr 28, 2020 at 4:04
  • 1
    What exactly do you mean when you say "pop off"? Commented Apr 28, 2020 at 4:06

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.