Therefore when the counter value reaches 100000, we will turn ON led using the digitalWrite function. Now inside our loop function, we will increment the counter variable each time loop executes.Īfter that, we will check our counter value with a conditional statement like if. Code is nonblocking you can add your loop code after this ![]() If (counter = 100000) // Check if counter value reach to 100000Įlse if (counter = 200000) // Check if counter value reach to 200000Ĭounter = 0 // making counter value to 0 Using counters is the best method for beginners as it is simple as using the delay method and, this method will not block your code.Ĭounter++ // will increment counter by 1 So for 2 seconds, it will not detect any change in the button press therefore, the button press is skipped, and the controller takes no action. Think like this, if we want to glow LED when we press a button. As a result, our controller sits ideal and does nothing for that amount of time. But the delay function will block your code for that particular time. Why we should avoid using Delay in our code?Īs a beginner, using delay is fine as it’s simple to use and easy to understand. And after that, the code repeats from starting. Due to that, our LED will turn OFF.Īgain we will wait for 1 second. By doing this, we are sending 0V to pin-13. Then, turn OFF our LED by setting the pin state to LOW. We have used here delay(1000) because the delay function needs input in a millisecond. Due to that, our LED will turn ON.Īfter that, we will wait for 1-second to do so we will use the delay function. ![]() By doing this, we are sending +5V to pin-13. Firstly, we will make the LED pin state HIGH by using the digitalWrite function. We want to blink our LED in Arduino at an interval of 1 second. In the void loop, our code will run repeatedly: Put three values in the formula, and we will get the resistor R-value in ohms.ĭigitalWrite(LED, HIGH) // turn LED ON by writing HIGH (Sending 5v to pin 13)ĭigitalWrite(LED, LOW) // turn LED OFF by writing LOW (Sending 0v to pin 13) Let me simply divide in three-part Bright If=20mA, Medium If=15mA, Low If=10mA. Forward Current is directly proportional to LED brightness. Last we will require a forward current If of the LED.What is our supply voltage Vs? Most of the Arduino board works on 5V, So Vs=5V. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |