Arduino learning——Digital IO

pinMode()

arduino pins can provide current or absorb current up to 40 mA of current to other devices/circuits.

Descrpition

Choose a pin to be in input mode or in output mode or in INPUT_PULLUP. it will return nothing.

syntax

pinMode(pin, mode);//pin number and the mode should be setted
//pin:the pin number of the pin on your arduino
//mode:INPUT, OUTPUT, or INPUT_PULLUP

INPUT

the INPUT mode in pinMode().

definition

It is just like putting a very large series resistor. in this way, the pin will be perfect to be used for reading a sensor.

pinMode(pin, INPUT);

INPUT_PULLUP

the INPUT_PULLUP mode in pinMode().

definition

there is really a very large series resistor in some of the arduino pins. By setting the mode in INPUT_PULLUP, you don’t need to add a external pull-up resistors in your electrical network for safety.

pinMode(pin, INPUT_PULLUP);

OUTPUT

the OUTPUT mode in pinMode()

definition

when the pin is setted unto this mode, it can provide a substantial amount of current to other circuits.

pinMode(pin, OUTPUT);

digitalWrite()

Description

Read the value of a digital pin, and it will return HIGH or LOW.

Syntax

digitalRead(pin);//pin number should be setted

Warning

digitalRead() will return randomly if the pin isn’t connected to anything

HIGH

the meaning of HIGH is different depending on the pin is set to an INPUT or OUTPUT.

when the pin is in INPUT mode
  • the voltage is larger than a certain number, then it will return HIGH by using digitRead().
  • when it is written to be HIGH by digitalWrite(), the internal resistor will be pull up.
when the pi is in OUTPUT mode
  • when the pin in in OUTPUT mode, and is set to be in high volts.

LOW

The meaning of LOW also has a different meaning depending on whether a pin is set to INPUT or OUTPUT.

when the pin is in INPUT mode
  • when the pin is set in INPUT mode and the voltage is lower than a certain number, it will return LOW by using digitalRead().
when the pin is in OUTPUT mode
  • when the pin is set in OUYPUT and it is set to LOW using digitalWrite(), the pin can sink current.

digitalWrite()

description

Write a HIGH or a LOW value to a digital pin
If the pin has been configured as an OUTPUT with pinMode(), its voltage will be set to a certain value.
If the pin is configured as an INPUT, digitalWrite() will enable (HIGH) or disable (LOW) the internal pullup on the input pin.

it will return nothing

syntax

digitalWrite(pin, value);//the pin number and the value should be set.

reference: arduino language reference

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值