You will make a literary arduino

Hello everyone I'm your friend JamesBin, this text allows you to learn from arduino 0 and 1, let's start learning!

First, know arduino

  Arduino The name comes from the Italian, which was intended as a "strong friend", was born in Italy in 2005, the Interaction Design Institute Ivrea (Interaction Design Institute Ivrea), one of the main founders of the leading project named Massimo Banzi.

  Arduino projects created original intention was to reduce the threshold of Interaction Design Institute in the creation of interactive works of students. Which in addition to reducing student costs, it also takes into account the difficulty of learning. In other words, as long as it takes very little money, with very little programming knowledge, you can abstract ideas, create different works.

  The spirit of openness, so that more fans to benefit, at the beginning of Arduino project created to comply with the open-source hardware protocol, anyone can get free hardware design drawings Arduino board, and according to their own design process mass production.
In recent years with the rise of intelligent hardware, the rise of the world called maker culture of fashion, they use Arduino and its surrounding various hardware modules to quickly build all kinds of fun products. For example, you can quickly create personalized air quality detectors, fire alarms, and even cat friends make intelligent feed the cat, a small robot can even make all kinds of strange, flight enthusiasts have designed a variety of aircraft and ultimately complete a variety of thrilling aerial.
  Since Arduino can make so many interesting things, then let us know about her! Here Insert Picture Description
Source: Arduino UNO board

Source: Arduino UNO board
shown above, Arduino the base circuit board called Arduino UNO. The board was originally September 25, 2011 issued by the General Assembly in New York on maker culture (New York Maker Faire), the model name "UNO", is the Italian "a" means.
Brief summary, the circuit board consists of three parts:

  • processor
  • Power Interface
  • Expansion Slots

The processor used is produced by Atmel processor.
  There are three power supply mode, the first one is directly powered directly through the USB interface, the second is powered by a cylindrical external power interface, the last one is powered by extending pins 3V or 5V on the socket.
  Expansion slots are divided into analog and digital signal pin and signal pin ground pin. As the name suggests, a digital signal or an output pin can be introduced directly into a digital signal, an analog signal or output pin is introduced into an analog signal. When the complex circuit design time can access the extended expansion slot plate, according to different needs, the entire board be extended to enhance the scalability of the base circuit board. FIG Reset button can restart the operation of the entire circuit board.

Second, the lighting program

Hardware
Here Insert Picture Description
Source: Arduino-UNO-LED

Specifically includes the following:

Arduino UNO circuit board (1)
Mini breadboard (1)
220 ohm resistor (1)
the LED lamp (1)
Bread line (2)

Software only official Arduino IDE can be provided.
When you are ready to the above, as long as the next circuit connected, knocking a few simple lines of code, you can let the lamp flashes up!
Connecting circuit
Here Insert Picture Description

Code:

int led = 13;  


void setup() {

  pinMode(led, OUTPUT);
}

void loop() {

  digitalWrite(led, HIGH);


}

Code explanation:

int led = 13;  // 定义针脚号,数字类型为整型

// 对Arduino电路板或相关状态进行初始化方法
pinMode(led, OUTPUT);
// 设定13号针脚为输出状态,pinMode()方法是Arduino类库提供的系统方法,调用的时候需要传入两个参数。一个是针脚号,另一个是针脚号的状态。

Third, the flashing LED lights

Hardware
Here Insert Picture Description
Source: Arduino-UNO-LED

Specifically includes the following:

Arduino UNO circuit board (1)
Mini breadboard (1)
220 ohm resistor (1)
the LED lamp (1)
Bread line (2)

Software only official Arduino IDE can be provided.
When you are ready to the above, as long as the next circuit connected, knocking a few simple lines of code, you can let the lamp flashes up!
Connecting circuit
Here Insert Picture Description

int led = 13;  // 定义针脚号,数字类型为整型


void setup() {

  pinMode(led, OUTPUT);
}
// 系统调用,无限循环方法
void loop() {

  digitalWrite(led, HIGH);

  delay(1000);
  // 此处向Arduino的13针脚发送低电压状态,
  // 此状态可以让LED神灯熄灭
  digitalWrite(led, LOW);
  // 再次延迟1000毫秒,也即1秒钟,
  delay(1000);

}

Fourth, breathing light

Hardware
Here Insert Picture Description
Source: Arduino-UNO-LED
software
only official Arduino IDE can provide.
When you are ready to the above, as long as the next circuit connected, knocking a few simple lines of code, you can let the lamp flashes up!
Connecting circuit
Here Insert Picture Description
code is as follows:

void setup ()
{
  pinMode(13,OUTPUT);
}
 
void loop()
{
  //循环语句,控制PWM亮度的增加
  for (int a=0; a<=255;a++)
  {
    analogWrite(11,a);
    delay(8);//当前亮度级别维持的时间,单位毫秒
  }
  //循环语句,控制PWM亮度减小 
  for (int a=255; a>=0;a--)
  {
    analogWrite(11,a);
    delay(10);//当前亮度的维持的时间,单位毫秒  
  }
  delay(800);//完成一个循环后等待的时间,单位毫秒
}

Five keys

Hardware
Here Insert Picture Description
Source: Arduino circuit accessories

Specifically includes the following:

Arduino UNO circuit board (1)
Breadboard (1)
10K resistor (1)
a key switch (1)
bread line (3)

Software
Arduino official provide the IDE, as before.
Here Insert Picture Description
code show as below


const int buttonPin = 2;

const int ledPin =  13;
// 定义按键状态变量初始值为0
int buttonState = 0;


void setup() {
  // 设置ledPin端口为输出端口
  pinMode(ledPin, OUTPUT);
  // 设置buttonPin端口为输入端口
  pinMode(buttonPin, INPUT);
}


void loop() {
  // 读取按键状态
  buttonState = digitalRead(buttonPin);

  if (buttonState == HIGH) {
    // 点亮LED神灯
    digitalWrite(ledPin, HIGH);
  } else {
    // 熄灭LED神灯
    digitalWrite(ledPin, LOW);
  }
}

Six key debounce

Connection:
Here Insert Picture Description

  • Arduino UNO circuit board (1)
  • Breadboard (1)
  • 10k resistor (1)
  • Pushbuttons (1)
  • Bread line (3)

Code

// 定义按键输入针脚号常量,
// 并初始化为2号针脚。
const int buttonPin = 2;
// 定义LED输入针脚号常量,
// 并初始化为13号针脚。
// 注:此处我们使用的LED神灯是Arduino UNO电路板自带,
// 此神灯对应的针脚号默认为13,此数值不得随意更改,
// 所以这里定义的数值13是为了和默认值相对应。
const int ledPin = 13;
// 定义记录LED神灯当前状态的变量,
// 并初始化状态为HIGH。
int ledState = HIGH;
// 定义记录按键当前状态的变量
int buttonState;
// 定义记录按键最近一次状态变化的变量,
// 并初始化状态为LOW。
int lastButtonState = LOW;
// 定义记录最近一次抖动的时间变量,
// 并初始化时间为0毫秒。
long lastDebounceTime = 0;
// 定义延迟抖动的时间变量,
// 并初始化为50毫秒。
long debounceDelay = 50;

// 对Arduino电路板或相关状态进行初始化方法
void setup() {
  // 设置按键的针脚为输入状态
  pinMode(buttonPin, INPUT);
  // 设置电路板上LED神灯的针脚状态为输出状态
  pinMode(ledPin, OUTPUT);
  // 设置电路板上LED神灯的初始状态,
  // 此处因为变量ledState的初始状态为HIGH,
  // 所以LED神灯的初始状态为亮。
  digitalWrite(ledPin, ledState);
}

// 系统调用,无限循环方法
void loop() {
  // 读取按键的状态
  int reading = digitalRead(buttonPin);
  // 判断当前的按键状态是否和之前有所变化
  if (reading != lastButtonState) {
    // 如果按键发生了变化,
    // 则重新设置最近一次抖动的时间。
    lastDebounceTime = millis();
  }
  // 判断按键按下或抬起的状态时间间隔是否大于延迟抖动的时间长度。
  // 方法millis()可以获取当前时间,单位统一为毫秒。
  if ((millis() - lastDebounceTime) > debounceDelay) {
    // 判断当前的按键状态是否和之前有所变化
    if (reading != buttonState) {
      // 如果发生了变化,
      // 则更新按键状态变量。
      buttonState = reading;
      // 判断按键的状态是否为按下,
      // 只有在按键按下的时候,
      // 才改变LED神灯的状态。
      if (buttonState == HIGH) {
        // 如果LED神灯当前为亮度,
        // 则变为灭。如果为灭,
        // 则变为亮。
        ledState = !ledState;
      }
    }
  }
  // 最终改变电路板上LED神灯的状态
  digitalWrite(ledPin, ledState);
  // 更新按键最近一次状态变化的变量
  lastButtonState = reading;
}

Continuous update

Published 111 original articles · won praise 177 · views 210 000 +

Guess you like

Origin blog.csdn.net/qq_45172832/article/details/105155678