Está en la página 1de 5

CODIGO FUENTE EN ARDUINO DE LA CASITA

#include <Wire.h>
//#include <Adafruit_MotorShield.h>
//#include "utility/Adafruit_PWMServoDriver.h"
#include <SoftwareSerial.h>
int bluetoothTx = 2;
int bluetoothRx = 3;
//int motorPins[] = {12, 10, 9};
//int arma[]={7,6,5};
int salidas [] = {13, 12, 11, 10, 9, 8};
int luz13=0;
int luz12=0;
int luz11=0;
int luz10=0;
int tv9=0;
int sonido8=0;
int switchPin = 5;
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
/*Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_DCMotor *backMotor = AFMS.getMotor(1);
Adafruit_DCMotor *frontMotor = AfterMS.getMotor(3);
*/
void setup()
{
//Setup usb serial connection to computer
Serial.begin(9600);
//Setup Bluetooth serial connection to android
bluetooth.begin(115200);
bluetooth.print("$$$");
delay(100);
bluetooth.println("U,9600,N");
bluetooth.begin(9600);
for (int count = 0; count < 8; count++) {
pinMode(salidas[count], OUTPUT);
}
//pinMode(13,OUTPUT);
pinMode(switchPin, INPUT);
}

void loop()
{
luz_13(luz13);
luz_12(luz12);
luz_11(luz11);
luz_10(luz10);
tv_9(tv9);
sonido_8(sonido8);
//apagar();
//encender();
Serial.print("Read switch input: ");
Serial.println(digitalRead(switchPin)); // Read the pin and display the value
delay(100);
//Read from bluetooth and write to usb serial
if(bluetooth.available())
{
char toSend = (char)bluetooth.read();
Serial.print(toSend);

if (toSend == 'A'){
if(luz13==0){
luz13=1;
}else if(luz13==1){
luz13=0;
}
}

if (toSend == 'B'){
if(luz12==0){
luz12=1;
}else if(luz12==1){
luz12=0;
}
}

if (toSend == 'C'){
if(luz11==0){
luz11=1;
}else if(luz11==1){
luz11=0;
}
}

if (toSend == 'D'){
if(luz10==0){
luz10=1;
}else if(luz10==1){
luz10=0;
}
}

if (toSend == 'E'){
if(tv9==0){
tv9=1;
}else if(tv9==1){
tv9=0;
}
}

if (toSend == 'F'){
if(sonido8==0){
sonido8=1;
}else if(sonido8==1){
sonido8=0;
}
}

if (toSend == 'G'){
luz13=1;
luz12=1;
luz11=1;
luz10=1;
tv9=1;
sonido8=1;
}

if (toSend == 'H'){
luz13=0;
luz12=0;
luz11=0;
luz10=0;
tv9=0;
sonido8=0;
}
}

// This was for reading to serial during the testing phase


// //Read from usb serial to bluetooth
if(Serial.available())
{
char toSend = (char)Serial.read();
bluetooth.print(toSend);
}
}

//APAGA_ENCIENDE LUZ 1 (Luz Garage)


void luz_13(int e){
if (e==1){
digitalWrite(13, HIGH);
}
if (e==0){
digitalWrite(13, LOW);
}
}
//APAGA_ENCIENDE LUZ 2 (Luz Segundo Nivel)
void luz_12(int e){
if (e==1){
digitalWrite(12, HIGH);
}
if (e==0){
digitalWrite(12, LOW);
}
}

//APAGA_ENCIENDE LUZ 3 (Luz Tercer Nivel Frente)


void luz_11(int e){
if (e==1){
digitalWrite(11, HIGH);
}
if (e==0){
digitalWrite(11, LOW);
}
}

//APAGA_ENCIENDE LUZ 4 (Luz Tercer Nivel Atras)


void luz_10(int e){
if (e==1){
digitalWrite(10, HIGH);
}
if (e==0){
digitalWrite(10, LOW);

}
}

//APAGA_ENCIENDE TELEVISOR
void tv_9(int e){
if (e==1){
digitalWrite(9, HIGH);
}
if (e==0){
digitalWrite(9, LOW);
}
}

//APAGA_ENCIENDE SONIDO
void sonido_8(int e){
if (e==1){
digitalWrite(8, HIGH);
}
if (e==0){
digitalWrite(8, LOW);
}
}
//APAGAR TODO
void apagar(){
digitalWrite(13, LOW);
digitalWrite(12, LOW);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
digitalWrite(8, LOW);
}
//APAGAR TODO
void encender(){
digitalWrite(13, HIGH);
digitalWrite(12, HIGH);
digitalWrite(11, HIGH);
digitalWrite(10, HIGH);
digitalWrite(9, HIGH);
digitalWrite(8, HIGH);
}

También podría gustarte