Arduino 入门

Arduino

arduino开发板

  1. 数字输入输出端口Dn,TX1,RX0

    输入输出数字信号0,1。

    TX1,RX0,用于与电脑进行数据传输。

    使用数字端口前要声明数字端口是输入还是输出。

  2. 模拟输入输出端口An

    pwm的应用

  3. 电源端口

Arduino程序介绍

1.基本程序框架
void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}
2.变量

变量类型

  1. int

    int a = 0;            //creates a variable integer called 'a'
    
    void setup() {
      Serial.begin(9600);       // use the serial port to print the number
    }
    
    void loop() {
      a++;                //Adds 1 to the a int on every loop
      Serial.println(a);  // prints out the current state of a
      delay(1000);
    }
    
  2. double

  3. float

    float myfloat;
    float sensorCalbrate = 1.117;
    
    int x;
    int y;
    float z;
    
    x = 1;
    y = x / 2;          // y now contains 0, ints can't hold fractions
    z = (float)x / 2.0; // z now contains .5 (you have to use 2.0, not 2)
    
  4. string

    char Str1[15];
    char Str2[8] = {'a', 'r', 'd', 'u', 'i', 'n', 'o'};
    char Str3[8] = {'a', 'r', 'd', 'u', 'i', 'n', 'o', '\0'};
    char Str4[] = "arduino";
    char Str5[8] = "arduino";
    char Str6[15] = "arduino";
    /************************************************************************************/
    char *myStrings[] = {"This is string 1", "This is string 2", "This is string 3",
                         "This is string 4", "This is string 5", "This is string 6"
                        };
    
    void setup() {
      Serial.begin(9600);
    }
    
    void loop() {
      for (int i = 0; i < 6; i++) {
        Serial.println(myStrings[i]);
        delay(500);
      }
    }
    
3.程序结构
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值