) en el mundo de la electronica, y es crear mi software, y con este controlar mi arduino, mediante envio de un codigo numerico sencillo, la cosa es que no puedo graduar el fadding, no se que problema puede ser, la cosa es la siguiente, tengo el siguiente codigo en java:Código
Que envia el siguiente codigo numerico:
/* * PanelControl.java * * Created on 31-may-2010, 19:33:36 */ package javacom; import app.Com; import app.Parameters; import core.SerialPort; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; /** * * @author debci */ /** Creates new form PanelControl */ public PanelControl() { initComponents(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jButton1.setText("Enciende LED"); jButton1ActionPerformed(evt); } }); jButton2.setText("Apaga LED"); jButton2ActionPerformed(evt); } }); jButton3.setText("Fadding"); jButton3ActionPerformed(evt); } }); jSlider1.setMaximum(254); jSlider1.setValue(0); jSlider1StateChanged(evt); } }); jButton4.setText("Inicio FADDING"); jButton4ActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jButton1) .addComponent(jButton2) .addComponent(jButton3) .addComponent(jButton4) .addComponent(jSlider1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jButton1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jButton4) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jSlider1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) ); pack(); }// </editor-fold>//GEN-END:initComponents private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed }//GEN-LAST:event_jButton2ActionPerformed private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed }//GEN-LAST:event_jButton1ActionPerformed private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed }//GEN-LAST:event_jButton3ActionPerformed private void jSlider1StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSlider1StateChanged }//GEN-LAST:event_jSlider1StateChanged private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed }//GEN-LAST:event_jButton4ActionPerformed /** * @param args the command line arguments */ public void run() { new PanelControl().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables // End of variables declaration//GEN-END:variables } class Control { static SerialPort puerto = new SerialPort(); static List<String> listaPuertos; static Com com1; public static void EnviaComando(int interrupcion, int argumento) { try { listaPuertos = puerto.getFreeSerialPort(); Parameters settings = new Parameters(); settings.setPort("COMUSB2"); settings.setBaudRate("9600"); com1 = new Com(settings); com1.writeDataInt("COMUSB2", interrupcion); com1.writeDataInt("COMUSB2", argumento); } } }
97 -> Enciende LED
98-> Apaga LED
99-> Fadding Pre-establecido
100 + valorCustom -> Gradua la intensidad del led con el valor custom, ose 100 quiere decir, espera otro valor y ponlo como valor de intensidad.
Y este es el codigo de mi arduino:
Código
Que en concreto, se puede apreciar que cuando recive el valor 100, vuelve a leer, porque mi programa en java, envia un segundo dato con el valor del fadding, de manera que cuando muevo el slide del programa envia 100, 5 100, 230 y cuando detecta 100 lee lo siguiente y se lo pone, pero no funciona bien, es tocar el slide y que se encienda sin variaciones.
// start reading from the first byte (address 0) of the EEPROM int address = 0; byte value; int incomingByte = 0; const int pinLed = 11; void setup() { Serial.begin(9600); pinMode(pinLed, OUTPUT); Serial.println("Hola, te has conectado"); } void loop() { if (Serial.available() > 0) { // read the incoming byte: incomingByte = Serial.read(); // say what you got: //Serial.print("Orden recivida: "); //Serial.println(incomingByte, DEC); switch(incomingByte) { case 97: digitalWrite(pinLed, HIGH); Serial.println("Enciendo led..."); break; case 98: digitalWrite(pinLed, LOW); Serial.println("Apagando led..."); break; case 99: Serial.println("Iniciando proceso de fadding..."); digitalWrite(pinLed, LOW); for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) { // sets the value (range from 0 to 255): analogWrite(pinLed, fadeValue); // wait for 30 milliseconds to see the dimming effect delay(30); } // fade out from max to min in increments of 5 points: for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) { // sets the value (range from 0 to 255): analogWrite(pinLed, fadeValue); // wait for 30 milliseconds to see the dimming effect delay(30); } break; case 100: Serial.read(); int valorFadding = Serial.read(); analogWrite(pinLed, valorFadding); break; } } }
Alguien tiene idea de porque ocurre esto?
Saludos





Autor




En línea

