arduino 蓝牙控制LED

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
char data='0';
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(7, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  if(Serial.available()!=0){
    data=Serial.read();
    if(data=='0'){
      digitalWrite(7, LOW);
      Serial.println("LED will off.");
    }else if(data=='1'){
      digitalWrite(7, HIGH);
      Serial.println("LED will on.");
    }
  }
}