[問題] ARDUINO程式問題
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
"C"
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
我要再A0銜接一個輸出給電流量測,想要利用紅外線感應到就給他觸發訊號量測0.1秒的"
平均電流值",要在serial monitor顯示,請問要怎麼改寫?
非常謝謝!
電流程式:
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A0); //A0類比輸入
Serial.println((514 - sensorValue) * 49.49 / 1023);
//49.99=50=resolution ; 5(V)/0.1(V/A)=50=resolution
delay(20);
}
紅外線程式:
const int IR_rec = 4; // 紅外線接收器
const int IR_send = 7; // 紅外線發射器
const int LED = 13; // 紅外線指示燈
const unsigned int frequency = 38000; // 發射頻率(單位: Hz)
void setup() {
Serial.begin(9600); // 開啟 Serial port, 通訊速率為 9600 bps
pinMode(IR_rec, INPUT); // 把 irReceiver 接腳設置為 INPUT
pinMode(IR_send, OUTPUT); // 把 irLed 接腳設置為 INPUT
pinMode(LED, OUTPUT); // 把 ledPin 設置為 OUTPUT
tone(IR_send, frequency); // 產生指定頻率的脈波 (Pulses)
delay(1000);
}
void loop() {
int IR_status = digitalRead(IR_rec); // 讀取 irReceiver 的狀態
Serial.println(IR_status); // 把 irReceiver 的狀態印到 Serial Port
// 檢查 irReceiver 是否有收到紅外線訊號
// 有的話,ir_status 會是 0
if (IR_status == 0) {
digitalWrite (LED, HIGH);
}
else {
digitalWrite (LED, LOW);
}
}
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 120.108.10.197
※ 文章網址: http://www.ptt.cc/bbs/C_and_CPP/M.1404977276.A.92C.html
噓
07/10 17:13, , 1F
07/10 17:13, 1F
→
07/10 23:14, , 2F
07/10 23:14, 2F
→
07/11 02:52, , 3F
07/11 02:52, 3F
※ 編輯: s4A111039 (120.108.10.197), 07/11/2014 09:50:57
→
07/11 16:18, , 4F
07/11 16:18, 4F
→
07/11 16:18, , 5F
07/11 16:18, 5F
推
07/12 17:16, , 6F
07/12 17:16, 6F
→
07/12 17:17, , 7F
07/12 17:17, 7F
→
07/12 17:18, , 8F
07/12 17:18, 8F
→
07/12 17:18, , 9F
07/12 17:18, 9F
→
07/12 17:19, , 10F
07/12 17:19, 10F
→
07/12 17:20, , 11F
07/12 17:20, 11F
討論串 (同標題文章)
完整討論串 (本文為第 1 之 2 篇):
0
11
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章