Learning Arduino in 1 hour[Preview]

Resume

It has been a long time that I wanna write an article for Arduino. So, let’s rock n roll.


Introduction

Arduino is a computer hardware and software company, project, and user community that designs and manufactures micro-controller kits for building digital devices and interactive objects that can sense and control objects in the physical world.
From Wiki-Arduino
So, we can actually affect our physical world by programming!


Connecting to Arduino

In this article, we will use Arduino Uno as our experimental platform.

First, start pining your Arduino Uno to your computer and open Arduino IDE.

In some situations, Arduino IDE cannot recognize what you’ve connected. Just click on Tools tab -> Board -> Arduino/Genuino Uno to select Arduino Uno. Then select connected Arduino Uno by clicking Tools tab -> Port -> The port that you've connected to.


Coding preparations

setup() & loop()

setup()runs once when we start our program. So that pre-configurations should be put here. Attention, as setup() is a function, so every variables defined here will be lost after setup() is finished.

loop() runs one after another. So that our main program should be written here including detecting data from sensors, controlling motors, etc.

Baud rate

When connecting to a physical device, we have to indicate its’ baud rate which means that bits (or symbols) transferred per second. If we have mis-set this value, data transferred will be weird.

We can set baud rate by the following codes:

const unsigned int BAUD_RATE = 9600;
void setup() {
  Serial.begin(BAUD_RATE); //Init serial
}

As we can see, Serial.begin(BAUD_RATE) has been written in setup(). It’s mainly because Arduino is a resource limited device, variables, assignments, function calls may cost additional resource in static area.


Reading data

Analog

Digital

Writing data

PWM

Analog

Digital

Example

Here’s an example of turning servo and lighting up a LED bulb.

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值