Arduino入门函数笔记
来源:互联网 发布:linux mv到当前目录 编辑:程序博客网 时间:2024/05/17 21:55
1、setup()
当Arduino开始的时候被调用。用它来初始化变量,设置引脚运行模式,启动库文件等。setup函数只运行一次,每次上电或者被重置时候调用。
int buttonPin = 3;void setup(){ Serial.begin(9600); pinMode(buttonPin, INPUT);}void loop(){ // ...}
2、loop()
创建setup()时,该函数设置初始值等一些初始化操作。该函数是Arduino运行控制的函数,所有的实时控制逻辑都在该方法内执行。
const int buttonPin = 3;// setup initializes serial and the button pinvoid setup(){ Serial.begin(9600); pinMode(buttonPin, INPUT);}// loop checks the button pin each time,// and will send serial if it is pressedvoid loop(){ if (digitalRead(buttonPin) == HIGH) Serial.write('H'); else Serial.write('L'); delay(1000);}
3、pinMode()
配置指定的引脚的输入或输出模式。
模式类型: INPUT, OUTPUT, or INPUT_PULLUP.
int ledPin= 13; // LED connected to digital pin 13
void setup()
{
pinMode(ledPin,OUTPUT); // sets the digital pin as output
}
void loop()
{
digitalWrite(ledPin,HIGH); // sets the LED on
delay(1000); // waits for a second
digitalWrite(ledPin,LOW); // sets the LED off
delay(1000); // waits for a second
}
4、digitalWrite()
向指定引脚输出控制信号HIGH或者LOW。
int ledPin = 13; // LED connected to digital pin 13void setup(){ pinMode(ledPin, OUTPUT); // sets the digital pin as output}void loop(){ digitalWrite(ledPin, HIGH); // sets the LED on delay(1000); // waits for a second digitalWrite(ledPin, LOW); // sets the LED off delay(1000); // waits for a second}
5、digitalRead()
读取指定引脚的值HIGH或者LOW。int ledPin= 13; // LED connected to digital pin 13
int inPin = 7; // pushbutton connected to digital pin 7
int val = 0; // variable to store the read value
void setup()
{
pinMode(ledPin,OUTPUT); // sets the digital pin 13 as output
pinMode(inPin,INPUT); // sets the digital pin 7 as input
}
void loop()
{
val = digitalRead(inPin); // read the input pin
digitalWrite(ledPin, val); // sets the LED to the button's value
}
- Arduino入门函数笔记
- arduino开发入门笔记
- Arduino入门笔记(1)
- Arduino入门笔记(2)
- Arduino入门笔记(3)
- Arduino入门,Arduino入门
- Arduino 开发入门 学习笔记 Arduino编程基础
- Arduino学习笔记 函数的秘密~~~
- Arduino 入门
- Arduino笔记
- Arduino 笔记
- Arduino笔记
- Arduino入门了解
- Arduino入门很简单
- Arduino入门很简单
- Arduino入门知识
- Arduino入门(一)
- Arduino入门(二)
- [置顶] Hadoop 常见问题分析
- linux下安装nginx教程
- poj3629 Card Stacking
- 准则
- 安卓屏幕适配
- Arduino入门函数笔记
- Unity UGUI优化
- 关于 验证码 Ajax,jQuery,Cookie与Session 总结
- mavn的安装与本地仓库的搭建
- 解决:angular js模板中无法使用ueditor的问题
- Beware of the stopwatch
- 10:数字组合
- 4.Django入门:教程-管理站点
- sonar常见错误以及处理方案