0

The messages received by the Arduino take the form: $ Ba, Pb, Rc #

Where $ represents the beginning of the message, # represents m, and B, P, and R are characters representing B button, P period and R repetition.

  1. `a 'designates the button to be read, which can be 1, 2 or 3.
  2. `b 'designates the time (in seconds) that the button should be expected to be pressed.
  3. `c 'designates the number of times the button is expected to be pressed during the indicated period.

For example, with the message: $ B2, P4, R2 # you want to know if button 2 has been pressed twice for four seconds. If condition is verified, then the Arduino must send the message $ MSG, TRUE # where MSG represents the message received without the start and m message characters. Otherwise, you must send the message $ MSG, FALSE #.

Incoming messages must respect the format presented. If not, the condition is not checked and the message $ NOK, MSG, KON # must be sent as a response.

I have no idea how to do this since im new to arduino

  • 2
    Hasn't your teacher given some information on how to start? In how to use Serial, how to parse strings? These things can also be found online via google – chrisl Jun 23 at 18:36
  • There are examples of how to parse a comma separated list of data on our network: arduino.stackexchange.com/search?q=parse+comma The website cplusplus.com has a good description of C++ functions: cplusplus.com/reference/cstring/strtok – VE7JRO Jun 23 at 19:01
  • do the project on paper first ... pretend that you are the Arduino ... think about what you would do as the message is arriving – jsotola Jun 23 at 20:17
2

To begin, forget the Arduino for a moment and assume the task of determining true or false from $....# message. Think about what you would have to do, step by step, to accomplish this. (e.g.: Read the buttons; Record the time and the button states. Is there a message from the Serial port beginning with '$'? Then read the rest of the message. etc.) Then, for each of those steps, do the same thing again: write down the smaller steps to accomplish what that step requires. Do that until you can't break it down any further.

Those small steps should each look like something you could do in C++ code (sometimes called "Arduino" code, but it's really C++). Start replacing each English (or your language) steps with the C++ equivalent. Do this until all of the human-language steps are written in C++.

There will inevitably be mistakes. Fix one or a few at a time. When you're stuck, ask here, something like "Here is my (well formatted) code. I tried [this]. I expected to see [that]. But what happened instead was [something else]. How can I fix it?"; or: "I am getting this error message [with its complete text including any line numbers, please] from the compiler. What does it mean, and how could I have found that out on my own?"

Small steps....

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.