Professional Documents
Culture Documents
Led Blinking
Led Blinking
Using delay() function for blinking LED causes the microcontroller to stop the program for a
specific amount in milliseconds specified in the parameter. To make the programme more
efficient we can use the millis() function which will return number of milliseconds that have
passed since the microcontroller started running the program. millis() function will allow the
programme to run without breaking or stopping the programme unlike delay() function and
hence is more effective and efficient.
void setup() {
pinMode(13,OUTPUT); // Selected pin for output
pinMode(12,OUTPUT);
Time1 = Time2 = millis();
Period1 = 500;
Period2 = 500;
}
void loop() {
if(millis()-Time1>=Period1){
Led1=!Led1;
digitalWrite(13,Led1);
Time1=millis();
}
if(millis()-Time2>=Period2){
Led2=!Led2;
digitalWrite(12,Led2);
Time2=millis();
}
}