avatar
Untitled

Thành 51 14th Mar, 2019

MARKUP 3.32 KB
                                           
                         #include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); 
#define Lamp1 2
#define Lamp2 3
#define Lamp3 4
#define Lamp4 5
#define Lamp5 6
#define Lamp6 7
#define Lamp7 8
#define Lamp8 9
char val;
String statusLamp1,statusLamp2,statusLamp3,statusLamp4,statusLamp5,statusLamp6,statusLamp7,statusLamp8;
void setup() {
  pinMode(Lamp1,OUTPUT);
  pinMode(Lamp2,OUTPUT);
  pinMode(Lamp3,OUTPUT);
  pinMode(Lamp4,OUTPUT);
  pinMode(Lamp5,OUTPUT);
  pinMode(Lamp6,OUTPUT);
  pinMode(Lamp7,OUTPUT);
  pinMode(Lamp8,OUTPUT);
  mySerial.begin(9600);
  Serial.begin(9600);
}

void loop() {
//cek data serial from bluetooth android App
if( mySerial.available() >0 ) {
    val = mySerial.read();
    Serial.println(val); 
}
  if( val == '1' ) {
    digitalWrite(Lamp1,HIGH); statusLamp1="1"; }
  else if( val == '2' ) {
    digitalWrite(Lamp2,HIGH); statusLamp2="2"; }
  else if( val == '3' ) {
    digitalWrite(Lamp3,HIGH); statusLamp3="3"; }
  else if( val == '4' ) {
    digitalWrite(Lamp4,HIGH); statusLamp4="4"; }
  else if( val == '5' ) {
    digitalWrite(Lamp5,HIGH); statusLamp5="5";}
  else if( val == '6' ) {
    digitalWrite(Lamp6,HIGH); statusLamp6="6";}
  else if( val == '7' ) {
    digitalWrite(Lamp7,HIGH); statusLamp7="7";}
  else if( val == '8' ) {
    digitalWrite(Lamp8,HIGH); statusLamp8="8";}
  else if( val == '9' ) {
    digitalWrite(Lamp1,HIGH); statusLamp1="1";
    digitalWrite(Lamp2,HIGH); statusLamp2="2";
    digitalWrite(Lamp3,HIGH); statusLamp3="3";
    digitalWrite(Lamp4,HIGH); statusLamp4="4";
    digitalWrite(Lamp5,HIGH); statusLamp5="5";
    digitalWrite(Lamp6,HIGH); statusLamp6="6";
    digitalWrite(Lamp7,HIGH); statusLamp7="7";
    digitalWrite(Lamp8,HIGH); statusLamp8="8";
 }
  else if( val == 'A' ) {
    digitalWrite(Lamp1,LOW); statusLamp1="A"; }
  else if( val == 'B' ) {
    digitalWrite(Lamp2,LOW); statusLamp2="B"; }
  else if( val == 'C' ) {
    digitalWrite(Lamp3,LOW); statusLamp3="C"; }
  else if( val == 'D' ) {
    digitalWrite(Lamp4,LOW); statusLamp4="D"; }
  else if( val == 'E' ) {
    digitalWrite(Lamp5,LOW); statusLamp5="E";}
  else if( val == 'F' ) {
    digitalWrite(Lamp6,LOW); statusLamp6="F";}
  else if( val == 'G' ) {
    digitalWrite(Lamp7,LOW); statusLamp7="G";}
  else if( val == 'H' ) {
    digitalWrite(Lamp8,LOW); statusLamp8="H";}
  else if( val == 'I' ) {
    digitalWrite(Lamp1,LOW); statusLamp1="A";
    digitalWrite(Lamp2,LOW); statusLamp2="B";
    digitalWrite(Lamp3,LOW); statusLamp3="C";
    digitalWrite(Lamp4,LOW); statusLamp4="D";
    digitalWrite(Lamp5,LOW); statusLamp5="E";
    digitalWrite(Lamp6,LOW); statusLamp6="F";
    digitalWrite(Lamp7,LOW); statusLamp7="G";
    digitalWrite(Lamp8,LOW); statusLamp8="H";
 }

 else if( val == 'S' ) {
    delay(500);    
    mySerial.println(statusLamp1+statusLamp2+statusLamp3+statusLamp4+statusLamp5+statusLamp6+statusLamp7+statusLamp8+"J"); //delay(500);
    val=' ';
 }
}
                      
                                       
To share this paste please copy this url and send to your friends
RAW Paste Data
Recent Pastes