Created
June 6, 2019 02:50
This file contains hidden or 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 com.panamahitek.ArduinoException; | |
import com.panamahitek.PanamaHitek_Arduino; | |
import com.panamahitek.PanamaHitek_MultiMessage; | |
import jssc.SerialPortException; | |
import javax.swing.*; | |
import java.awt.*; | |
import java.util.logging.Level; | |
import java.util.logging.Logger; | |
import static javax.swing.JFrame.EXIT_ON_CLOSE; | |
public class MultipleSensor { | |
// ------------------------------ FIELDS ------------------------------ | |
private JLabel unValor; | |
// --------------------------- CONSTRUCTORS --------------------------- | |
public MultipleSensor() { | |
JFrame v = new JFrame(); | |
v.setSize(250, 150); | |
v.setTitle("INTERFAZ TEMPERATURA"); | |
v.setDefaultCloseOperation(EXIT_ON_CLOSE); | |
JLabel etiqueta1 = new JLabel("TEMPERATURA °C : "); | |
unValor = new JLabel("Waiting ..."); | |
FlowLayout ventana1 = new FlowLayout(); | |
v.getContentPane().add(etiqueta1); | |
v.getContentPane().add(unValor); | |
v.getContentPane().setLayout(ventana1); | |
v.setVisible(true); | |
} | |
// -------------------------- OTHER METHODS -------------------------- | |
public void updateTemperature(String temperature) { | |
unValor.setText(temperature + " °Celcius"); | |
} | |
// --------------------------- main() method --------------------------- | |
public static void main(String[] args) { | |
MultipleSensor instance = new MultipleSensor(); | |
try { | |
PanamaHitek_Arduino ino = new PanamaHitek_Arduino(); | |
PanamaHitek_MultiMessage multi = new PanamaHitek_MultiMessage(3, ino); | |
ino.arduinoRX("COM4", 9600, e -> { | |
try { | |
if (multi.dataReceptionCompleted()) { | |
instance.updateTemperature(multi.getMessage(0)); | |
System.out.println(multi.getMessage(0)); | |
System.out.println(multi.getMessage(1)); | |
System.out.println(multi.getMessage(2)); | |
multi.flushBuffer(); | |
} | |
} catch (ArduinoException | SerialPortException ex) { | |
Logger.getLogger(MultipleSensor.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
}); | |
} catch (ArduinoException | SerialPortException ex) { | |
Logger.getLogger(MultipleSensor.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment