控制任务和要求
让一个LED灯闪烁
接线
程序设计
int half_cycle=1000; // define the cycle time of LED blink
int LED_pin=12; // define the LED pin
// the setup function runs once when you press resetor power the board
void setup()
{
pinMode(LED_pin, OUTPUT); //initialize digital pin 13 as an output.
}
// the loop function runs over and over again forever
void loop()
{
digitalWrite(LED_pin, HIGH); // turn the LED on (HIGH is the voltage level)
delay(half_cycle); //wait for half_cycle time
digitalWrite(LED_pin, LOW); //turn the LED off by making the voltage LOW
delay(half_cycle); //wait for half_cycle time
}
注解
改变LED_pin的值可以改变LED的联接引脚,改变half_cycle的值可以改变闪烁周期。