Aduino 序列繪圖家是在Arduino 1.6.6增加的功能,以往要將感測器收集到的資料化成圖時,往往都使用 Porcessing 來輔助,但Arduino 1.6.6以後的版本就可以直接使用序列繪圖家來呈現了。一起試試看畫底下的三角函數圖形吧。
硬體材料:
Arduino UNO x 1
語法說明:
單一資料輸出時
Serial.println(data1);
兩筆資料要同時輸出時
Serial.print(data1); Serial.print(" "); Serial.println(data2);
或是
Serial.print(data1); Serial.print("\t"); Serial.println(data2);
範例程式:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Math.h" | |
void setup() { | |
Serial.begin(9600); | |
} | |
void loop() { | |
float angle = 0; | |
float sineData; | |
float cosineData; | |
float sum; | |
for(angle = 0.0; angle <= 90; angle += 0.1) { | |
sineData = sin(angle); | |
cosineData = cos(angle); | |
sum = sineData + cosineData; | |
Serial.print(sineData); | |
Serial.print(" "); | |
Serial.print(cosineData); | |
Serial.print(" "); | |
Serial.print(sum); | |
Serial.println(); | |
delay(1); | |
} | |
} |
從Arduino IDE 開啟序列繪圖家
示範影片(Demo videos):
沒有留言:
張貼留言