Robofun 機器人論壇

 找回密碼
 申請會員
搜索
熱搜: 活動 交友 discuz
查看: 2200|回復: 2
打印 上一主題 下一主題

請問酒精感測跟超音波的問題

[複製鏈接]
跳轉到指定樓層
1#
發表於 2018-9-4 18:34:29 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
本帖最後由 jihhy 於 2018-9-4 18:35 編輯

想請問 想要同時執行超音波感測跟酒精感測 要怎麼執行 感謝

這是 酒精程式

int SensorValue=0;
void setup() {
  Serial.begin(9600);}
void loop() {
  SensorValue=analogRead(0);
  Serial.print("Value:");
  Serial.print(SensorValue,DEC);

  delay(1000);
     if(SensorValue<200){
       Serial.print("    OK");}
     else{
       Serial.print("    NO Driving");}

   Serial.println("");
   }
  
這是超音波感測

int trigPin = 12;                  //Trig Pin
int echoPin = 11;                  //Echo Pin
long duration, cm, inches;

void setup() {
  Serial.begin (9600);             // Serial Port begin
  pinMode(trigPin, OUTPUT);        //Define inputs and outputs
  pinMode(echoPin, INPUT);
}

void loop()
{
  digitalWrite(trigPin, LOW);
  delayMicroseconds(5);
  digitalWrite(trigPin, HIGH);     // 給 Trig 高電位,持續 10微秒
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  pinMode(echoPin, INPUT);             // 讀取 echo 的電位
  duration = pulseIn(echoPin, HIGH);   // 收到高電位時的時間

  cm = (duration/2) / 29.1;         // 將時間換算成距離 cm 或 inch  
  inches = (duration/2) / 74;

  Serial.print("Distance : ");  
  Serial.print(inches);
  Serial.print("in,   ");
  Serial.print(cm);
  Serial.print("cm");
  Serial.println();
  
  delay(1000);
}
2#
發表於 2018-9-5 17:42:18 | 只看該作者
把 void setup { } 和 void loop{ }  括符中的東西合在一起
其他不在括符中的東西 就放在最前面即可, 如
******A 程式******
宣告用 A 程式
void setup {
SETUP_A 程式
}
void loop {
LOOP_A程式
}
******B 程式*******
宣告用 B程式
void setup {
SETUP_B程式
}
void loop {
LOOP_B程式
}
******合併程式*******
宣告用 A程式
宣告用 B 程式
void setup {
SETUP_A程式
SETUP_B程式
}
void loop {
LOOP_A程式
LOOP_B程式
}
3#
 樓主| 發表於 2018-9-7 16:27:33 | 只看該作者
超新手 發表於 2018-9-5 17:42
把 void setup { } 和 void loop{ }  括符中的東西合在一起
其他不在括符中的東西 就放在最前面即可, 如
* ...

收到!!

感ˋ謝你
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

小黑屋|手機版|Archiver|機器人論壇 from 2005.07

GMT+8, 2024-5-3 06:32 , Processed in 0.207454 second(s), 6 queries , Apc On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表