当前位置:文档之家› arduino小程序

arduino小程序

arduino小程序
arduino小程序

点亮LED

constint LED=9;

void setup() {

pinMode(LED,OUTPUT);

digitalWrite(LED,HIGH);

// put your setup code here, to run once:

}

void loop() {

// put your main code here, to run repeatedly:

}

LED闪烁可变

constint LED=9;

void setup() {

pinMode(LED,OUTPUT);

// put your setup code here, to run once:

}

void loop()

{

for(inti=100;i<=1000;i=i+100)

{

digitalWrite(LED,HIGH);

delay(i);

digitalWrite(LED,LOW);

delay(i);}

// put your main code here, to run repeatedly:

}

呼吸灯逐渐变亮逐渐熄灭

constint LED=9;

void setup() {

pinMode(LED,OUTPUT);

// put your setup code here, to run once:

}

void loop()

{

for(inti=0;i<256;i++)

{

analogWrite(LED,i);

delay(10);}

for(inti=255;i>=0;i--)

{

analogWrite(LED,i);

delay(10);}

}

按键数字控制

constint LED=9;

constint BUTTON=2;

void setup() {

pinMode(LED,OUTPUT);

pinMode(LED,INPUT);

// put your setup code here, to run once: }

void loop()

{

if(digitalRead(BUTTON)==LOW) {digitalWrite(LED,LOW);

}

else

{digitalWrite(LED,HIGH);} }

相关主题
文本预览
相关文档 最新文档