Created
June 21, 2017 08:02
-
-
Save aldajo92/62e91551cf15e24178259c910c647de7 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 <SoftwareSerial.h> | |
SoftwareSerial BTserial(2, 3); // RX | TX | |
String ANALOG1 = "analog1"; | |
String ANALOG2 = "analog2"; | |
String ANALOG3 = "analog3"; | |
String OUT1 = "out1"; | |
String OUT2 = "out2"; | |
String OUT3 = "out3"; | |
String OUT4 = "out4"; | |
String CTEMP = "ctemp"; | |
const int AnIncurrent = A0; // sensor de corriete | |
const int AnInpressure = A1; // sensor de presion aire | |
const int AnIntemperature = A2; // Sensor de temperatura | |
const int AnOuttemperature = 5; // salida PWM control de temperatura | |
const int DiOuttermonufla = 7; // salida digital control de la temperatura mufla | |
const int DiOutPHpistonA = 8; // salida digital puente H piston | |
const int DiOutPHpistonB = 9; // salida digital puente H piston | |
const int DiOutPHmotorA = 10; // salida digital puente H motor mufla | |
const int DiOutPHmotorB = 11; // salida digital puente H motor mufla | |
char c; | |
String comando; | |
int value; | |
int sensorValue; | |
void setup() { | |
Serial.begin(115200); | |
Serial.println("Arduino is ready"); | |
Serial.println("Remember to select Both NL & CR in the serial monitor"); | |
BTserial.begin(9600); | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
BTserialEvent(); | |
} | |
void BTserialEvent(){ | |
if (BTserial.available()) { | |
c = BTserial.read(); | |
if (c == '\n') { | |
parseCommand(comando); | |
comando = ""; | |
} | |
else { | |
comando += c; | |
} | |
} | |
} | |
void parseCommand(String com) { | |
String part1; | |
String part2; | |
part1 = com.substring(0, com.indexOf("-")); | |
part2 = com.substring(com.indexOf("-") + 1); | |
if(part1 == "echo"){ | |
echo(part2); | |
}else | |
if(part1 == ANALOG1){ | |
// Entrada Analogica temperatura - control calentador capsula | |
operacion5(); | |
} | |
} | |
void sendFormatData(int value){ | |
BTserial.print("E"); | |
BTserial.print("-"); | |
BTserial.print("value"); | |
BTserial.print("-"); | |
BTserial.print(value); | |
BTserial.print("-"); | |
BTserial.println("R"); | |
} | |
void sendFormatData(int value, String type){ | |
BTserial.print("E"); | |
BTserial.print("-"); | |
BTserial.print(type); | |
BTserial.print("-"); | |
BTserial.print(value); | |
BTserial.print("-"); | |
BTserial.println("R"); | |
} | |
void echo(String valor){ | |
BTserial.print("responding-to-"); | |
BTserial.println(valor); | |
} | |
// salida PWM - control calentador capsula | |
void operacion1(String valor){ | |
value = valor.toInt(); | |
analogWrite(AnOuttemperature, value); | |
} | |
// salida digital - control calentador mufla | |
void operacion2(String valor){ | |
value = valor.toInt(); | |
if (value==1) { | |
digitalWrite(DiOuttermonufla, HIGH); | |
} | |
else { | |
digitalWrite(DiOuttermonufla, LOW); | |
} | |
} | |
// salida digital - control puente H piston | |
void operacion3(String valor){ | |
value = valor.toInt(); | |
if (value==1) { | |
digitalWrite(DiOutPHpistonA , HIGH); | |
digitalWrite(DiOutPHpistonB , LOW); | |
} | |
else if (value==2) { | |
digitalWrite(DiOutPHpistonA , LOW); | |
digitalWrite(DiOutPHpistonB , HIGH); | |
} else { | |
digitalWrite(DiOutPHpistonA , LOW); | |
digitalWrite(DiOutPHpistonB , LOW); | |
} | |
} | |
// salida digital - control puente H motor mufla. | |
void operacion4(String valor){ | |
value = valor.toInt(); | |
if (value==1) { | |
digitalWrite(DiOutPHmotorA , HIGH); | |
digitalWrite(DiOutPHmotorB , LOW); | |
} | |
else if (value==2) { | |
digitalWrite(DiOutPHmotorA , LOW); | |
digitalWrite(DiOutPHmotorB , HIGH); | |
} else { | |
digitalWrite(DiOutPHmotorA , LOW); | |
digitalWrite(DiOutPHmotorB , LOW); | |
} | |
} | |
////////////OPERACIONES DE SENSADO ANALOGICO /////////////////////////////////// | |
// Entrada Analogica temperatura - control calentador capsula | |
void operacion5(){ | |
sensorValue = analogRead(AnIntemperature); | |
sendFormatData(sensorValue, ANALOG1); | |
} | |
// Entrada Analogica corriente - monitor de consumo de potencia | |
void operacion6(){ | |
sensorValue = analogRead(AnIncurrent); | |
sendFormatData(sensorValue, ANALOG2); | |
} | |
// Entrada Analogica presion - monitor de presion del piston neumatico | |
void operacion7(){ | |
sensorValue = analogRead(AnInpressure); | |
sendFormatData(sensorValue, ANALOG3); | |
} | |
/* | |
void cTemp(){ | |
Serial.print("E"); | |
Serial.print("-"); | |
Serial.print("value"); | |
Serial.print("-"); | |
Serial.print(thermocouple.readCelsius()); | |
Serial.print("-"); | |
Serial.println("R"); | |
} | |
void fTemp(){ | |
Serial.print("E"); | |
Serial.print("-"); | |
Serial.print("value"); | |
Serial.print("-"); | |
Serial.print(thermocouple.readFahrenheit()); | |
Serial.print("-"); | |
Serial.println("R"); | |
}*/ | |
//////////////INTERRUPCIONES FIN DE CARRERA DE LA MUFLA /////////////////////// | |
// Interrupcion pinA detiene el piston | |
void doPinA(){ | |
Serial.print("E"); | |
Serial.print("-"); | |
Serial.print("interrupt"); | |
Serial.print("-"); | |
Serial.println("R"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment