How to write c code in arduino
So if one push button is pushed then the corresponding LED should glow for 2 seconds, similarly if second is pushed then LED should glow for 4 seconds. Consider we want to toggle two LEDs using two push buttons. The best example to explain the drawback of delay function is using two push buttons. This hampers the performance of the microcontroller in terms of speed and executing the instructions. Similarly if the delay is 10 seconds then program will stop for 10 seconds and processor will not allow to go for the next instructions until the 10 seconds passed. So if we are giving a delay of 1 second then the processor cannot go to next instruction until 1 second passed. Here comes the point, both functions pause the program for the amount of time passed in delay function. if we write delayMicroseconds(1000), then the delay will be of 1000 microseconds i.e. Similarly in delayMicroseconds() function, the parameter passed is in microseconds i.e. The only difference is that, in delay() function, the parameter integer passed is in milliseconds i.e if we write delay(1000) then the delay will be of 1000 milliseconds i.e. Both functions are identical in terms of generating delay. If the reference documentation of Arduino is considered then there is two type of delay functions, the first one is delay() and second is delayMicroseconds(). But before starting let's discuss that why we should not use delay() function in any project. Arduino also has a delay() function which is used widely. Since the Arduino runs in low frequency and RAM compare to Laptop/Mobile/PC so the time given to each task will also be different. The concept will be almost same for the Arduino Multitasking, except the time distribution will be a bit different. This is how the multitasking is done in most of the systems. Let’s discuss how OS manages multitasking.Īs seen in the picture, the CPU divides the time in the three equal parts and assign each part to each task/application. The end user use all these applications at the same time but OS takes this concept a bit different.
The good example of multitasking in computers are when users run the email application, internet browser, media player, games, at the same time and if users don’t want use the application it runs in the background if not closed.
#HOW TO WRITE C CODE IN ARDUINO PC#
The MOS can be mobile or desktop PC Operating System.
This kind of operating systems are known as MOS (multitasking operating system). Almost all operating systems feature multitasking. Multitasking simply means executing more than one task or program simultaneously at the same time.