Arduino UNO输出高电平点亮LED(三)

该教程介绍了如何使用Arduino UNO通过输出高电平点亮LED灯。由于LED最大电压限制,需要串联一个约100-200欧姆的电阻。示例代码中原本是为了演示输入引脚的内部上拉电阻功能,但已修改为直接控制LED输出,通过轮流开关LED来展示输出功能。
摘要由CSDN通过智能技术生成

通过 Arduino UNO输出高电平点亮LED。
注意LED可承载的最大电压约为2V,10ma~15ma,需要串联一个电阻100R-200R左右的都可以。一端接GND或-,一端接输出端子。
/*
Input Pull-up Serial

This example demonstrates the use of pinMode(INPUT_PULLUP). It reads a digital
input on pin 2 and prints the results to the Serial Monitor.

The circuit:

  • momentary switch attached from pin 2 to ground
  • built-in LED on pin 13

Unlike pinMode(INPUT), there is no pull-down resistor necessary. An internal
20K-ohm resistor is pulled to 5V. This configuration causes the input to read
HIGH when the switch is open, and LOW when it is closed.

created 14 Mar 2012
by Scott Fitzgerald

This example code is in the public domain.

http://www.arduino.cc/en/Tutorial/InputPullupSerial
*/

void setup() {
//start serial connection
Serial.begin(115200);
//configure pin 2 as an input and enable the internal pull-up resistor
//pinMode(2, INPUT_PULLUP);
pinMode(8, OUTPUT);

}

void loop() {
//read the pushbutton value into a variable
//int sensorVal = digitalRead(2);
//print out the value of the pushbutton
//Serial.println(sensorVal);

// Keep in mind the pull-up means the pushbutton’s logic is inverted. It goes
// HIGH when it’s open, and LOW when it’s pressed. Turn on pin 13 when the
// button’s pressed, and off when it’s not:
//if (sensorVal == HIGH) {
// digitalWrite(13, LOW);
//} else {
digitalWrite(8, HIGH);
delay(500);
digitalWrite(8, LOW);
delay(500);
//}
}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值