What is this Arduino code doing?

0

I need a description of what it does.

if( ! digitalRead(sensor1)) {
    speed1 = frente;
    speedv1=0;
} else {
    speed1 = 0;
    speedv1 = voltar;
}
    
asked by anonymous 27.08.2018 / 21:56

1 answer

2

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

  • Calls a function called digitalRead() passing as an argument the value of the variable sensor1 . What she does we can not know.
  • This function should return a Boolean value, or at least a 0 for false or other value that will be treated as true. If it is false, that is, if a 0 comes, then the first block in braces will be executed, if any other value comes the second block after the else command will be executed. if is a decision command.
  • In the first block the variable speed1 to be worth the value that is in the variable frente at this moment and the variable speedv1 is worth 0.
  • If it is for the second block speed1 it will be worth 0 and speedv1 will be the same as voltar at this moment.
27.08.2018 / 22:03