close

1.  send 端 (發送)

左邊的板子,線接11(recv端的10),和接地的線




2.  recv (接收)

右邊的板子,10(send端的11)13(Led燈的長腳)








send端的程式:

#include <SoftwareSerial.h>
SoftwareSerial mySerial(10,11);
void setup() 
{
  // put your setup code here, to run once:
  mySerial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  delay(3000);
  mySerial.print('a');
}

recv端的程式:

#include <SoftwareSerial.h>
SoftwareSerial mySerial(10,11);

int ledFlag=0;

void setup() 
{
  // put your setup code here, to run once:
  mySerial.begin(9600);
  pinMode(13,OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  byte rxData;

  if(mySerial.available())
  {
    rxData=mySerial.read();
    if(rxData=='a')
    {
      if(ledFlag==0)
      {
        ledFlag=1;
        digitalWrite(13,HIGH);
          
      } 

         else
         {
           ledFlag=0;
           digitalWrite(13,LOW); 
         }
    }   
  }
}
arrow
arrow
    文章標籤
    Arduino
    全站熱搜
    創作者介紹
    創作者 布拉怡 的頭像
    布拉怡

    nini的部落格

    布拉怡 發表在 痞客邦 留言(0) 人氣()