Arduino学习(1)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/github_39611196/article/details/83417122

下载Arduino开发IDE并安装:https://www.arduino.cc/download_handler.php

控制LED灯亮:

将LED灯按照如下方式连接,一端接地,一端结5号端口:

输入如下代码:

//设定控制LED的数字IO脚
 
int ledPin4 = 5; 


void setup() {
  // put your setup code here, to run once:
 //设定IO口的模式,OUTPUT为输出
  pinMode(ledPin4,OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  //设定PIN脚为HIGH=5V左右
  digitalWrite(ledPin4, HIGH);
  delay(2000);//设定延时时间,2000=2s
  //设定PIN脚为LOW=OV左右
  digitalWrite(ledPin4, LOW);
  delay(2000);
}

编译:

写入Arduino:

结果:

可以看到小灯管闪烁。

猜你喜欢

转载自blog.csdn.net/github_39611196/article/details/83417122