What’s this Arduino code doing?

Asked

Viewed 71 times

0

I need a description of what he does.

if( ! digitalRead(sensor1)) {
    speed1 = frente;
    speedv1=0;
} else {
    speed1 = 0;
    speedv1 = voltar;
}
  • Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful for you. You can also vote on any question or answer you find useful on the entire site (when you have 15 points).

2 answers

2

The ideal would be to see the context, but reading it you can say:

  • Calls a function called digitalRead() passing as argument the value of the variable sensor1. What she does we have no way of knowing.
  • This function must return a boolean value, or at least 0 for false or another value that will be treated as true. If it is false, that is, if you see a 0, then the first block between keys will be executed, if any other value comes the second block after the command else shall be executed. The if is a decision command.
  • In the first block the variable speed1 to validate the value that is in the variable frente at this point in time and the variable speedv1 becomes 0.
  • If it goes to the second block speed1 will be worth 0 and speedv1 will be worth the same as voltar at this time.

0

If the sensor reading returns any information it arrow the variable speed1 with "front" and speedv1 with 0 if nothing returns, the variable speedv1 gets the value "back" and speed1 also with 0 "Zero".

Browser other questions tagged

You are not signed in. Login or sign up in order to post.