1個LED燈閃爍的Arduino控制


控制任務和要求

讓一個LED燈閃爍

接線  

程序設計

 1 int half_cycle=1000;   // define the cycle time of LED blink
 2 int LED_pin=13;      // define the LED pin
 3 
 4 // the setup function runs once when you press reset or power the board
 5 void setup() 
 6 {
 7   pinMode(LED_pin, OUTPUT);    // initialize digital pin 13 as an output.
 8 }
 9 
10 // the loop function runs over and over again forever
11 void loop() 
12 {
13   digitalWrite(LED_pin, HIGH);     // turn the LED on (HIGH is the voltage level)
14   delay(half_cycle);              // wait for half_cycle time
15   digitalWrite(LED_pin, LOW);     // turn the LED off by making the voltage LOW
16   delay(half_cycle);              // wait for half_cycle time
17 }

注解

改變LED_pin的值可以改變LED的聯接引腳,改變half_cycle的值可以改變閃爍周期。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM