Arduino 發射和接收紅外線

來源:互聯網
上載者:User
//學號後兩位26#define com_hear 2#define com_sound 3#define com_speak 4void setup() {  pinMode(com_sound, OUTPUT);  pinMode(com_speak, OUTPUT);  pinMode(com_hear, INPUT);  Serial.begin(9600);}void loop() {  int i, j, k;  int hear_sta[12] = {0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0};  int speak[12] = {0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1};  int hear[12] = {0};  i = 0;  int judge = 0;  int count = 0;  // while(judge != 1)  // {  for (k = 0; k < 12; k++)  {    if (speak[k] == 0)    {      for (i = 0; i < 30; i++)      {        digitalWrite(com_speak, HIGH);        delayMicroseconds(13);        digitalWrite(com_speak, LOW);        delayMicroseconds(13);      }    }    else if (speak[k] == 1)    {      digitalWrite(com_speak, LOW);      delayMicroseconds(1100);    }  }  for ( i = 0; i < 1000; i++)  {    hear[0] = digitalRead(com_hear);    delayMicroseconds(550);    if (hear[0] == 0)    {      for (j = 1; j < 12; j++)      {        delayMicroseconds(1100);        hear[j] = digitalRead(com_hear);      }      for (j = 0; j < 12; j++)      {        if (hear[j] == hear_sta[j])          count++;      }      if (count == 12)      {        for (int x = 0; x < 1000; x++)        {          digitalWrite(com_sound, HIGH);          delayMicroseconds(250);          digitalWrite(com_sound, LOW);          delayMicroseconds(250);        }      }    }    delayMicroseconds(100);    count = 0;  }  for (i = 0; i < 12; i++)    Serial.print(hear[i]);  Serial.println();}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.