Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement