lunes, 10 de febrero de 2020

Proyecto Colegio Juan de salinas

#include "BluetoothSerial.h"

#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif

BluetoothSerial SerialBT;
int received;// received value will be stored in this variable
char receivedChar;// received value will be stored as CHAR in this variable

const char Front ='F';
const char Stopp ='S';
const char Right ='R';
const char Left ='L';
const char Back ='B';

const int PF = 23;
const int PR = 22;
const int PB= 19;
const int PL =18;

void setup() {
  Serial.begin(115200);
  SerialBT.begin("Polsin"); //Bluetooth device name
  Serial.println("The device started, now you can pair it with bluetooth!");
  pinMode(PF, OUTPUT);
  pinMode(PR, OUTPUT);
  pinMode(PB, OUTPUT);
  pinMode(PL, OUTPUT);

}

void loop() {
    receivedChar =(char)SerialBT.read();

  if (Serial.available()) {
    SerialBT.write(Serial.read());
 
  }
  if (SerialBT.available()) {
     
    /////////////////////////////////////////////////////////////////////////

    if(receivedChar == Front)
    {
     digitalWrite(PF, HIGH);// turn the LED ON 
    }
    /////////////////////////////////////////////////////////////////////////

    if(receivedChar == Back)
    {
     digitalWrite(PB, HIGH);// turn the LED ON 
    }
    /////////////////////////////////////////////////////////////////////////
    if(receivedChar == Left)
    {
     digitalWrite(PL, HIGH);// turn the LED ON 
    }
//////////////////////////////////////////////////////////////////
    if(receivedChar == Right)
    {
     digitalWrite(PR, HIGH);// turn the LED ON 
    }
    /////////////////////////////////////////////////////////////////////////


    if(receivedChar == 'G')
    {
     digitalWrite(PF, HIGH);// turn the LED ON 
     digitalWrite(PL, HIGH);// turn the LED ON
    }


    if(receivedChar == 'I')
    {
     digitalWrite(PF, HIGH);// turn the LED ON 
     digitalWrite(PR, HIGH);// turn the LED ON
    }

    if(receivedChar == 'H')
    {
     digitalWrite(PB, HIGH);// turn the LED ON 
     digitalWrite(PL, HIGH);// turn the LED ON
    }
   
    if(receivedChar == 'J')
    {
     digitalWrite(PB, HIGH);// turn the LED ON 
     digitalWrite(PR, HIGH);// turn the LED ON
    }
   
    if(receivedChar == Stopp)
    {
      digitalWrite(PF, LOW);// turn the LED off
      digitalWrite(PB, LOW);// turn the LED off
      digitalWrite(PR, LOW);// turn the LED off
      digitalWrite(PL, LOW);// turn the LED off
    }   
   
 

  }
  delay(20);
}

No hay comentarios:

Publicar un comentario