Netbeans - grafica de sensores con arduino

 
Vista:
sin imagen de perfil
Val: 1
Ha aumentado su posición en 19 puestos en Netbeans (en relación al último mes)
Gráfica de Netbeans

grafica de sensores con arduino

Publicado por angel (1 intervención) el 03/10/2018 04:46:34
Hola amigos, no llevo mucho tiempo en esto de la programación, sin embargo me e aventurado por cuestiones académicas y me gusta bastante, estoy buscando solución acerca de un código que vi en internet al cual le e cambiado varias cosas, el objetivo es que cuando se le de "run" salga un botón y al apretarlo empiece a graficar, por el momento utilizo una fotoresistencia, pero el objetivo será emplear un sensor dht22, agradecería muchísimo su ayuda de porque al apretar el botón no me sale la grafica, se antemano gracias.
Este es el código y también adjunto el proyecto.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package window;
 
import jssc.SerialPortEvent;
import jssc.SerialPortEventListener;
import com.panamahitek.ArduinoException;
import com.panamahitek.PanamaHitek_Arduino;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import jssc.SerialPortException;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
 
public class window extends javax.swing.JFrame {
//declaración de Variables
    final XYSeries Serie = new XYSeries("Luminosidad");
    final XYSeriesCollection Coleccion = new XYSeriesCollection();
    JFreeChart Grafica;
//conexion arduino
 
    int i = 0;
    PanamaHitek_Arduino ino = new PanamaHitek_Arduino ();
    SerialPortEventListener Listener = new SerialPortEventListener(){
        @Override
        public void serialEvent(SerialPortEvent spe) {
            try {
                if (ino.isMessageAvailable()== true){
                    i++;
 
                   Serie.add(i, Integer.parseInt(ino.printMessage()));
                }
            } catch (SerialPortException ex) {
                Logger.getLogger(window.class.getName()).log(Level.SEVERE, null, ex);
            } catch (ArduinoException ex) {
                Logger.getLogger(window.class.getName()).log(Level.SEVERE, null, ex);
            }
 
        }
    };
 
//Conexión a Arduino
    public window() {
        initComponents();
        try {
            ino.arduinoRX("COM4", 9600, Listener);
        } catch (ArduinoException ex) {
            Logger.getLogger(window.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SerialPortException ex) {
            Logger.getLogger(window.class.getName()).log(Level.SEVERE, null, ex);
        }
//Gráfica de los Datos que recibiremos
        Serie.add(0,0);
        Coleccion.addSeries(Serie);
        Grafica = ChartFactory.createXYLineChart("Luminosidad vs Tiempo", "Tiempo", "Luminosidad", Coleccion, PlotOrientation.VERTICAL, rootPaneCheckingEnabled, rootPaneCheckingEnabled, rootPaneCheckingEnabled);
        }
// Al momento de dar clic en el botón Graficar, nos mandara la pantalla donde se esta graficando los datos.
 
 
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {
 
        jButton1 = new javax.swing.JButton();
 
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
 
        jButton1.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
        jButton1.setText("Graficar");
        jButton1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
 
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(20, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
            .addGap(38, 38, 38)
            .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap(39, Short.MAX_VALUE))
        );
 
        pack();
    }// </editor-fold>
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
        ChartPanel Panel = new ChartPanel(Grafica);
        JFrame Ventana = new JFrame("JFreeChart");
        Ventana.getContentPane().add(Panel);
        Ventana.pack();
        Ventana.setVisible(true);
        Ventana.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
 
 
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html

         */
        java.awt.EventQueue.invokeLater(() -> {
            new window().setVisible(true);
        });
 
 
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(window.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
 
        //</editor-fold>
 
        /* Create and display the form */
 
    }
 
    // Variables declaration - do not modify                     
    private javax.swing.JButton jButton1;
    // End of variables declaration                   
 
    private static class Luminosidad {
 
        public Luminosidad() {
        }
    }
 
    private static class arduino {
 
        public arduino() {
        }
 
        private boolean MessageAvailable() {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
 
        private String PrintMessage() {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
 
        private void ArduinoRX(String COM4, int i, int i0, SerialPortEventListener evento) {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    }
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder