Last active
June 18, 2020 01:00
-
-
Save chepecarlos/1cbb902248b9c8660da0c7567fe3c0ca to your computer and use it in GitHub Desktop.
Codigo Colaboracion con Ing Gomes
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
boolean EstadoRele[6] = {false, false, false, false, false, false}; | |
int PinRele[6] = {3, 4, 5, 6, 7, 8}; | |
void setup() { | |
Serial.begin(9600); | |
for (int i = 0; i < 6; i++) { | |
pinMode(PinRele[i], OUTPUT); | |
digitalWrite(PinRele[i], 0); | |
} | |
} | |
void loop() { | |
if (Serial.available()) { | |
DecodificarSerial(); | |
} | |
for (int i = 0; i < 6; i++) { | |
if (EstadoRele[i]) { | |
digitalWrite(PinRele[i], 1); | |
} | |
else { | |
digitalWrite(PinRele[i], 0); | |
} | |
} | |
} | |
void DecodificarSerial() { | |
// Mensaje de la forma BS/0 | |
// BE - Boton Encendido | |
// BA - Boton Apagado | |
// # es el id de 0 a 6 | |
String Mensaje = Serial.readStringUntil('\n'); | |
int PosicionPleca = Mensaje.indexOf('/'); | |
int PosicionSaltoLinea = Mensaje.length(); | |
String EstadoBoton = Mensaje.substring(0, PosicionPleca); | |
int IDBoton = Mensaje.substring(PosicionPleca + 1, PosicionSaltoLinea).toInt(); | |
if (EstadoBoton.equals("BE")) { | |
EstadoRele[IDBoton] = true; | |
} | |
else if (EstadoBoton.equals("BA")) { | |
EstadoRele[IDBoton] = false; | |
} | |
Serial.print("Boton:"); | |
Serial.print(IDBoton); | |
Serial.print(" Estado:"); | |
Serial.print(EstadoRele[IDBoton]); | |
Serial.println(); | |
} |
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
import processing.serial.*; | |
Serial MiPuerto; | |
color ColorApagado = color(255, 255, 0); | |
color ColorEncendido = color(0, 255, 0); | |
color ColorFondo = color(0); | |
int CantidadBotones = 6; | |
color[] ColorCirculo = {ColorApagado, ColorApagado, ColorApagado, ColorApagado, ColorApagado, ColorApagado}; | |
boolean[] Estado = {false, false, false, false, false, false}; | |
void setup() { | |
//printArray(Serial.list()); | |
MiPuerto = new Serial(this, "/dev/ttyUSB0", 9600); | |
size(950, 300); | |
ellipseMode(CENTER); | |
textSize(32); | |
textAlign(CENTER); | |
} | |
void draw() { | |
background(ColorFondo); | |
text("Preciona un Boton", 475, 50); | |
for (int i = 0; i < 6; i++) { | |
fill(ColorCirculo[i]); | |
circle( i *150 + 100, 150, 100); | |
text(i, i*150+ 100, 250); | |
} | |
} | |
void mousePressed() { | |
for (int i = 0; i < 5; i++) { | |
float Distancia = dist(mouseX, mouseY, i*150+100, 150); | |
if (Distancia < 50) { | |
Estado[i] = !Estado[i]; | |
if (Estado[i]) { | |
ColorCirculo[i] = ColorEncendido; | |
MiPuerto.write("BE/"+i+"\n"); | |
} else { | |
ColorCirculo[i] = ColorApagado; | |
MiPuerto.write("BA/"+i+"\n"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment