Arduino 精要

来自Jack's Lab
(版本间的差异)
跳转到: 导航, 搜索
(糖豆)
(糖豆)
第54行: 第54行:
  
 
<br><br>
 
<br><br>
 +
 +
=== AT CMD ===
 +
 +
SerialEvent() is called after a loop(), if there is serial data in the buffer.
 +
 +
<source lang=java>
 +
String input_str = "";              // a string to hold incoming data
 +
boolean str_over = false;          // whether the string is complete
 +
 +
void setup() {
 +
  Serial.begin(9600);
 +
  input_str.reserve(200);          // reserve 200 bytes for the inputString:
 +
}
 +
 +
void loop() {
 +
  // print the string when a newline arrives:
 +
  if (str_over) {
 +
    Serial.println(input_str);
 +
    input_str = "";                // clear the string:
 +
    str_over = false;
 +
  }
 +
}
 +
 +
/*
 +
  SerialEvent occurs whenever a new data comes in the
 +
hardware serial RX.  This routine is run between each
 +
time loop() runs, so using delay inside loop can delay
 +
response.  Multiple bytes of data may be available.
 +
*/
 +
void serialEvent() {
 +
  while (Serial.available()) {
 +
 +
    char in = (char)Serial.read();
 +
    input_str += in;
 +
    // if the incoming character is a newline, set a flag
 +
    // so the main loop can do something about it:
 +
    if (in == '\n') {
 +
      str_over = true;
 +
    }
 +
  }
 +
}
 +
</source>
 
<br><br>
 
<br><br>
 
<br><br>
 
<br><br>

2014年11月9日 (日) 01:24的版本

目录

1 总览

Arduino I/O 之数字输入输出

Arduino I/O 之模拟输出

Arduino memory

深入 PWM

撰写自己的 Arduino 库


阻抗和阻抗匹配



2 扩展

Arduino Ethernet 的另一性价比选择

DHT21/AM2301 数字温湿度传感器



3 应用

Arduino 监控客厅温度湿度



4 精华

Arduino bootloader 的烧写

面包板上的至简 Arduino

动手焊一个自己的 Arduino



5 糖豆

5.1 float2str

String(NUMBER, SCALE);
String(3.141592,5);        # "3.14159"



5.2 Software Serial



5.3 AT CMD

SerialEvent() is called after a loop(), if there is serial data in the buffer.

String input_str = "";               // a string to hold incoming data
boolean str_over = false;           // whether the string is complete

void setup() {
  Serial.begin(9600);
  input_str.reserve(200);           // reserve 200 bytes for the inputString:
}

void loop() {
  // print the string when a newline arrives:
  if (str_over) {
    Serial.println(input_str); 
    input_str = "";                 // clear the string:
    str_over = false;
  }
}

/*
  SerialEvent occurs whenever a new data comes in the
 hardware serial RX.  This routine is run between each
 time loop() runs, so using delay inside loop can delay
 response.  Multiple bytes of data may be available.
 */
void serialEvent() {
  while (Serial.available()) {

    char in = (char)Serial.read(); 
    input_str += in;
    // if the incoming character is a newline, set a flag
    // so the main loop can do something about it:
    if (in == '\n') {
      str_over = true;
    } 
  }
}

















个人工具
名字空间

变换
操作
导航
工具箱