Created
April 30, 2017 18:21
-
-
Save anonymous/b87f849bc94fcea3e59a1cc70ed85168 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Servo.h> | |
Servo sun_meter; | |
String dataIn = ""; //Variable que almacena el string enviado desde el PI | |
boolean dataIn_done = false; //Bandera que indica que se acabó la rx | |
int S1 = 2; //LED SCIENCE | |
int S2 = 3; //LED SCIENCE | |
int S3 = 4; //LED SCIENCE | |
int C1 = 5; //LED COOKING | |
int C2 = 6; //LED COOKING | |
int C3 = 7; //LED COOKING | |
int E1 = 8; //LED EXCERCISE | |
int E2 = 9; //LED EXCERCISE | |
int E3 = 10; //LED EXCERCISE | |
int T1 = 11; //LED TELECOM | |
int T2 = 12; //LED TELECOM | |
int T3 = 13; //LED TELECOM | |
int ANALOG_IN = A0; //LECTURA DEL POT | |
int LED_BAR; | |
int LED_CONT = 10; | |
int ledPins[] = {31, 33, 35, 37, 39, 41, 43, 45, 47, 49}; | |
int i = 0; | |
int potpin = A2; | |
String sun_rad = ""; | |
int meter_delay = 1; | |
void setup() { | |
// put your setup code here, to run once: | |
Serial.begin(9600); | |
dataIn.reserve(200); | |
pinMode(S1, OUTPUT); | |
pinMode(S2, OUTPUT); | |
pinMode(S3, OUTPUT); | |
pinMode(C1, OUTPUT); | |
pinMode(C2, OUTPUT); | |
pinMode(C3, OUTPUT); | |
pinMode(E1, OUTPUT); | |
pinMode(E2, OUTPUT); | |
pinMode(E3, OUTPUT); | |
pinMode(T1, OUTPUT); | |
pinMode(T2, OUTPUT); | |
pinMode(T3, OUTPUT); | |
sun_meter.attach(52); | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
//LECTURA DEL POTENCIOMETRO QUE CONTROLA EL BAR-LED | |
// LED_BAR = analogRead(ANALOG_IN); | |
// int ledLevel = map(LED_BAR, 0, 1023, 0, LED_CONT); | |
for (int thisLed = 0; thisLed < 10; thisLed++) { | |
// if the array element's index is less than ledLevel, | |
// turn the pin for this element on: | |
digitalWrite(ledPins[thisLed], HIGH); | |
delay(500); | |
// turn off all pins higher than the ledLevel: | |
} | |
delay(2000); | |
for (int thisLed = 10; thisLed > 0; thisLed--) { | |
// if the array element's index is less than ledLevel, | |
// turn the pin for this element on: | |
digitalWrite(ledPins[thisLed], LOW); | |
// turn off all pins higher than the ledLevel: | |
} | |
// digitalWrite(S1, HIGH); | |
// digitalWrite(C2, HIGH); | |
// digitalWrite(E1, HIGH); | |
// digitalWrite(T3, HIGH); | |
// sun_meter.write(0); | |
// delay(3000); | |
// sun_meter.write(60); | |
// delay(1000); | |
// sun_meter.write(180); | |
if (dataIn_done) | |
{ | |
//Empezar a enceder los leds | |
//Buscar por las intrucciones | |
//BAR LED | |
// if (dataIn=="a\n") | |
// { | |
// digitalWrite(ledPins[0], HIGH); | |
// } | |
// | |
// else if (dataIn=="b\n") | |
// { | |
// digitalWrite(ledPins[1], HIGH); | |
// } | |
// else if (dataIn=="c\n") | |
// { | |
// digitalWrite(ledPins[2], HIGH); | |
// } | |
// else if (dataIn=="d\n") | |
// { | |
// digitalWrite(ledPins[3], HIGH); | |
// } | |
// else if (dataIn=="e\n") | |
// { | |
// digitalWrite(ledPins[4], HIGH); | |
// } | |
// else if (dataIn=="f\n") | |
// { | |
// digitalWrite(ledPins[5], HIGH); | |
// } | |
// else if (dataIn=="g\n") | |
// { | |
// digitalWrite(ledPins[6], HIGH); | |
// } | |
// else if (dataIn=="h\n") | |
// { | |
// digitalWrite(ledPins[7], HIGH); | |
// } | |
// else if (dataIn=="i\n") | |
// { | |
// digitalWrite(ledPins[8], HIGH); | |
// } | |
// else if (dataIn=="j\n") | |
// { | |
// digitalWrite(ledPins[9], HIGH); | |
// } | |
//Serial.println(dataIn); | |
//SCIENCE 1 | |
if (dataIn=="S11\n") | |
{ | |
digitalWrite(S1, HIGH); | |
} | |
else if(dataIn=="S10\n") | |
{ | |
digitalWrite(S1, LOW); | |
} | |
//SCIENCE 2 | |
else if(dataIn=="S21\n") | |
{ | |
digitalWrite(S2, HIGH); | |
} | |
else if(dataIn=="S20\n") | |
{ | |
digitalWrite(S2, LOW); | |
} | |
//SCIENCE 3 | |
else if(dataIn=="S31\n") | |
{ | |
digitalWrite(S3, HIGH); | |
} | |
else if(dataIn=="S30\n") | |
{ | |
digitalWrite(S3, LOW); | |
} | |
//COOKING 1 | |
else if (dataIn=="C11\n") | |
{ | |
digitalWrite(C1, HIGH); | |
} | |
else if (dataIn=="C10\n") | |
{ | |
digitalWrite(C1, LOW); | |
} | |
else if(dataIn=="C20\n") | |
{ | |
digitalWrite(C2,LOW); | |
} | |
//COOKING 2 | |
else if(dataIn=="C21\n") | |
{ | |
digitalWrite(C2, HIGH); | |
} | |
else if(dataIn=="C20\n") | |
{ | |
digitalWrite(C2, LOW); | |
} | |
//COOKING 3 | |
else if(dataIn=="C31\n") | |
{ | |
digitalWrite(C3, HIGH); | |
} | |
else if(dataIn=="C30\n") | |
{ | |
digitalWrite(C3, LOW); | |
} | |
//EXERCICSE 1 | |
else if (dataIn=="E11\n") | |
{ | |
digitalWrite(E1, HIGH); | |
} | |
else if (dataIn=="E10\n") | |
{ | |
digitalWrite(E1, LOW); | |
} | |
//EXERCISE 2 | |
else if(dataIn=="E21\n") | |
{ | |
digitalWrite(E2, HIGH); | |
} | |
else if(dataIn=="E20\n") | |
{ | |
digitalWrite(E2, LOW); | |
} | |
//EXCERSICE 3 | |
else if(dataIn=="E31\n") | |
{ | |
digitalWrite(E3, HIGH); | |
} | |
else if(dataIn=="E30\n") | |
{ | |
digitalWrite(E3, LOW); | |
} | |
//TELECOM 1 | |
else if(dataIn=="T11\n") | |
{ | |
digitalWrite(T1, HIGH); | |
} | |
else if(dataIn=="T10\n") | |
{ | |
digitalWrite(T1, LOW); | |
} | |
//TELECOM 2 | |
else if(dataIn=="T21\n") | |
{ | |
digitalWrite(T2, HIGH); | |
} | |
else if(dataIn=="T20\n") | |
{ | |
digitalWrite(T2, LOW); | |
} | |
//TELECOM 3 | |
else if(dataIn=="T31\n") | |
{ | |
digitalWrite(T3, HIGH); | |
} | |
else if(dataIn=="T30\n") | |
{ | |
digitalWrite(T3, LOW); | |
} | |
//SUN METER-APLICAR LA DIRECCION | |
else if (dataIn=="0\n") | |
{ | |
sun_meter.write(dataIn.toInt()); | |
} | |
else if (dataIn=="30\n") | |
{ | |
sun_meter.write(dataIn.toInt()); | |
} | |
else if (dataIn=="60\n") | |
{ | |
sun_meter.write(dataIn.toInt()); | |
} | |
else if (dataIn=="90\n") | |
{ | |
sun_meter.write(dataIn.toInt()); | |
} | |
else if (dataIn=="120\n") | |
{ | |
sun_meter.write(dataIn.toInt()); | |
} | |
else if (dataIn=="150\n") | |
{ | |
sun_meter.write(dataIn.toInt()); | |
} | |
else if (dataIn=="180\n") | |
{ | |
sun_meter.write(dataIn.toInt()); | |
} | |
dataIn = ""; | |
dataIn_done = false; | |
// delay(5000); | |
// //APAGAR TODO | |
// digitalWrite(S1, LOW); | |
// digitalWrite(S2, LOW); | |
// digitalWrite(S3, LOW); | |
// digitalWrite(C1, LOW); | |
// digitalWrite(C2, LOW); | |
// digitalWrite(C3, LOW); | |
// digitalWrite(E1, LOW); | |
// digitalWrite(E2, LOW); | |
// digitalWrite(E3, LOW); | |
// digitalWrite(T1, LOW); | |
// digitalWrite(T2, LOW); | |
} | |
} | |
void serialEvent(){ | |
while (Serial.available()){ | |
//Cada vez que están disponibles datos en la línea se lee | |
char inChar = (char)Serial.read(); | |
dataIn += inChar; | |
if (inChar == '\n') | |
// Se finaliza la lectura con el caracter \n | |
dataIn_done = true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment