Arduino Code

This was the code used for arduino programming:

#include <SoftwareSerial.h>

SoftwareSerial BT(10, 11); // TX, RX
String state;

void setup() {
  // put your setup code here, to run once:
  BT.begin(9600);
  Serial.begin(9600);
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(2, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  while (BT.available()){
    delay(10);
    char c = BT.read();
    state += c;
  }
  if (state.length() > 0){
    Serial.println(state);

    if(state == "acende vermelho")
    {
      digitalWrite(13, HIGH);
    }
    else if(state == "apaga vermelho")
    {
      digitalWrite(13, LOW);
    }
    else if(state == "acende Verde")
    {
      digitalWrite(12, HIGH);
    }
   else if(state == "apaga Verde")
    {
      digitalWrite(12, LOW);
    }
    else if(state == "acende Amarelo")
    {
      digitalWrite(6, HIGH);
    }
   else if(state == "apaga Amarelo")
    {
      digitalWrite(6, LOW);
    }
    else if(state == "acende azul")
    {
      digitalWrite(2, HIGH);
    }
   else if(state == "apaga azul")
    {
      digitalWrite(2, LOW);
    }
    else if(state == "acende todas")
    {
      digitalWrite(13, HIGH);
      digitalWrite(12, HIGH);
      digitalWrite(2, HIGH);
      digitalWrite(6, HIGH);
    }   
    else if(state == "apaga todas")
    {
      digitalWrite(13, LOW);
      digitalWrite(12, LOW);
      digitalWrite(2, LOW);
      digitalWrite(6, LOW);
    }

    state = "";
  }
}

Popular posts from this blog

About | Project & Team