This demo is a countdown for 5 seconds, that is followed by a buzzer.
For every second, an LED lights up, and by the fifth second the buzzer goes off.
Video Player
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | //define the outputs const int LED2 = 2; const int LED3 = 3; const int LED4 = 4; const int LED5 = 5; const int LED6 = 6; const int buzOutPin = 12; //****************************<wbr />******************************<wbr />********************** //set the starting point for alll LEDs to be turned off void setup() { digitalWrite(LED2, LOW); digitalWrite(LED3, LOW); digitalWrite(LED4, LOW); digitalWrite(LED5, LOW); digitalWrite(LED6, LOW); } //****************************<wbr />******************************<wbr />********************** //create a loop that alternates the LEDs down a row, and at the end of the loop the buzzer goes off. void loop() { for ( int i = 0; i < 4; i++) { digitalWrite(LED2, HIGH); delay(500); digitalWrite(LED2, LOW); delay(500); digitalWrite(LED3, HIGH); delay(500); digitalWrite(LED3, LOW); delay(500); digitalWrite(LED4, HIGH); delay(500); digitalWrite(LED4, LOW); delay(500); digitalWrite(LED5, HIGH); delay(500); digitalWrite(LED5, LOW); delay(500); digitalWrite(LED6, HIGH); delay(500); digitalWrite(LED6, LOW); tone(buzOutPin, HIGH); delay(1000); noTone(buzOutPin); } } <pre> |
Leave a Reply
You must be logged in to post a comment.