![]() As usually during the optimizing it picks up the value right out of memory, where as a variable, the quickest way is to load a pointer to the variable, then load it or do whatever the item is via indirection. In C it usually requires more code to manipulate a byte constant rather than to make it a declared value to be preprocessed, basically quicker and using less memory.Įquivalent from digitalRead(pinButton) to digitalRead(8), after preprocessing. Declared in line 1, used in lines 4 and 9. Sometimes there is an advantage to a constant (pinButton), used in this manner. Actually I will post an article that shows how you can add an LED and a relay. ![]() You can use other pin if you want to and you can even add extra circuitry to turn ON an LED or use a relay to power up different equipments. You can read the if() instruction like this “if stateButton is 1 do print the line PRESSED in the serial monitor, else print the line RELEASED”. Int stateButton = digitalRead(pinButton) Īs you can see using this code Arduino will display PRESSED when the button is pressed or RELEASE otherwise. A problem with the delay might be that if you press the button exactly when the delay happens (20ms in our case) then it will display the action in the windows, that why is better to use a lower value or else you might lose some clicks. There is also the delay() that ensures that we can actually read the value. Then it displays its state in the Serial Monitor window as 0 or 1. ![]() In the loop() we declare variable stateButton with the value obtained using the digitalRead() function that reads the state of pin 8. Then in the void() function we set the pin 8 as INPUT and initialize the serial port. On the first line we set a variable pinButton with an integer value of 8 (the pin number on Arduino Board where we connect the button or switch).
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |