第5章 Arduino IDE编程语言参考

第5章 Arduino IDE编程语言参考

一、Arduino IDE内置了编程语言参考,可以作为学习参考

二、系统提供的语言参考分为三个方面

  1. 结构Structure;
  2. 变量Variables;
  3. 函数Functions;

三、程序举例:我们可以参考程序提供的内置示例程序

 

练习读程序!

const int buttonPin = 2;     // the number of the pushbutton pin

const int ledPin =  13;      // the number of the LED pin

// variables will change:

int buttonState = 0;         // variable for reading the pushbutton status

void setup() {

  // initialize the LED pin as an output:

  pinMode(ledPin, OUTPUT);

  // initialize the pushbutton pin as an input:

  pinMode(buttonPin, INPUT);

}

void loop() {

  // read the state of the pushbutton value:

  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:

  if (buttonState == HIGH) {

    // turn LED on:

    digitalWrite(ledPin, HIGH);

  } else {

    // turn LED off:

    digitalWrite(ledPin, LOW);

  }

}

四、想和计算机进行交流,在Arduino开源平台上,展示创意,必须掌握的基本语法规则。

  1. 两个主函数setup(),loop()。
  2. 每句程序末尾加分号。
  3. 区分大小写。
  4. 区分全角半角。
  5. 函数和变量名以字母或下划线开头。
  6. 系统的关键字不能被用于其他途径。
  7. 最好每个语句都加上注释,这是一个良好的编程习惯、
开发计算机创智课程的实践研究
原文地址:https://www.cnblogs.com/ztg1/p/12554668.html