Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. import com.panamahitek.ArduinoException;
  2. import com.panamahitek.PanamaHitek_Arduino;
  3. import com.panamahitek.PanamaHitek_MultiMessage;
  4. import jssc.SerialPortException;
  5.  
  6. import javax.swing.*;
  7. import java.awt.*;
  8. import java.util.logging.Level;
  9. import java.util.logging.Logger;
  10.  
  11. import static javax.swing.JFrame.EXIT_ON_CLOSE;
  12.  
  13. public class MultipleSensor {
  14. // ------------------------------ FIELDS ------------------------------
  15.  
  16. private JLabel unValor;
  17.  
  18. // --------------------------- CONSTRUCTORS ---------------------------
  19.  
  20. public MultipleSensor() {
  21. JFrame v = new JFrame();
  22. v.setSize(250, 150);
  23. v.setTitle("INTERFAZ TEMPERATURA");
  24. v.setDefaultCloseOperation(EXIT_ON_CLOSE);
  25.  
  26. JLabel etiqueta1 = new JLabel("TEMPERATURA °C : ");
  27. unValor = new JLabel("Waiting ...");
  28.  
  29. FlowLayout ventana1 = new FlowLayout();
  30. v.getContentPane().add(etiqueta1);
  31. v.getContentPane().add(unValor);
  32. v.getContentPane().setLayout(ventana1);
  33. v.setVisible(true);
  34. }
  35.  
  36. // -------------------------- OTHER METHODS --------------------------
  37.  
  38. public void updateTemperature(String temperature) {
  39. unValor.setText(temperature + " °Celcius");
  40. }
  41.  
  42. // --------------------------- main() method ---------------------------
  43.  
  44. public static void main(String[] args) {
  45. MultipleSensor instance = new MultipleSensor();
  46. try {
  47. PanamaHitek_Arduino ino = new PanamaHitek_Arduino();
  48. PanamaHitek_MultiMessage multi = new PanamaHitek_MultiMessage(3, ino);
  49. ino.arduinoRX("COM4", 9600, e -> {
  50. try {
  51. if (multi.dataReceptionCompleted()) {
  52. instance.updateTemperature(multi.getMessage(0));
  53. System.out.println(multi.getMessage(0));
  54. System.out.println(multi.getMessage(1));
  55. System.out.println(multi.getMessage(2));
  56. multi.flushBuffer();
  57. }
  58. } catch (ArduinoException | SerialPortException ex) {
  59. Logger.getLogger(MultipleSensor.class.getName()).log(Level.SEVERE, null, ex);
  60. }
  61. });
  62. } catch (ArduinoException | SerialPortException ex) {
  63. Logger.getLogger(MultipleSensor.class.getName()).log(Level.SEVERE, null, ex);
  64. }
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement