|
Mostrar Mensajes
|
Páginas: [1] 2 3
|
1
|
Programación / Programación C/C++ / Re: Ayuda con ejercicio de bucles.
|
en: 8 Noviembre 2014, 18:18 pm
|
Buenas tardes Sr. eveelynn24. Tengo una observación sobre su codificación y es la siguiente. He logrado comprobar que cuando la variable zona2 = @ no sale del while es por eso que he añadido la siguiente parte de código: //SOLUCION if (zona2 == '@') break;
Estas 2 lineas logran ver que su programa esta correctamente y realiza el trabajo como usted lo indica en el ejemplo descrito arriba. En conclusión seria el siguiente código: #include <iostream> #include <stdio.h> using namespace std;
int main ()
{ char zona1, zona2; int temp1, temp2, hum1, hum2; do { cout << "\nIntroduce la zona (Mayúsculas): "; cin >> zona1; } while (((zona1<'A') || (zona1>'Z'))&& zona1!='@'); do { cout << "\nIntroduce la temperatura (entre 0 y 100): "; cin >> temp1; } while ((temp1<0) || (temp1>100)); do { cout << "\nIntroduce la humedad (entre 0 y 100): "; cin >> hum1; } while ((hum1<0) || (hum1>100)); while ( (zona1!='@') || (zona2!='@')) { do { cout << "\nIntroduce otra zona (Mayúsculas): "; cin >> zona2; } while (((zona2<'A') || (zona2>'Z'))&& zona2!='@'); //SOLUCION if (zona2 == '@') break; do { cout << "\nIntroduce la temperatura (entre 0 y 100): "; cin >> temp2; } while ((temp2<0) || (temp2>100)); do { cout << "\nIntroduce la humedad (entre 0 y 100): "; cin >> hum2; } while ((hum2<0) || (hum2>100)); if (temp1<temp2) { temp1 = temp2; hum1 = hum2; zona1 = zona2; } else if (temp1 == temp2) { if (hum1>hum2) { hum1 = hum2; zona1 = zona2; } }
} cout << "\n\nZona: " << zona1 << "\nTemperatura: " << temp1 << "\nHumedad: " << hum1; getchar(); //system ("pause"); }
Si he comprendido mal el problema, podemos seguir discutiéndolo. Cordiales Saludos.
|
|
|
2
|
Programación / Programación C/C++ / Re: Problema con mi codigo
|
en: 8 Noviembre 2014, 14:24 pm
|
Buenos días Sr. ratchetmdt. Con la intención de ayudarle he realizado 2 cambios en su codificación y su programa funciona sintaxticamente. Se las listo a continuación: 1. Siempre se deben inicializar las variables en C/C++ porque sino las llena de basura (variable a = 0, b= 0 ). 2. La variable char se debe leer con %c (entiendo que aquí tal vez se confundió -- refiriéndome al segundo sacanf que tiene). scanf("%n",&n); Luego de esto he logrado que corra correctamente, mas no tiene la logica cuando ingreso VVV = 25 eso es falso debe ser = 15. #include <stdio.h> char n; int suma=0; int a = 0; int b = 0; int main () { printf("Escribe un numero en romano \n"); scanf("%c",&n); if (n=='I' || n=='V' || n=='X' || n=='L' || n=='C' || n=='D' || n=='M' || n=='\n'){ while (n!='\n'){ if (n=='I') { a=1; if(b<a) { suma=suma+(a-b); } else { suma=suma+(a+b);} } if (n=='V') { a=5; if(b<a) { suma=suma+(a-b); } else { suma=suma+(a+b); } } if (n=='X') { a=10; if(b<a) { suma=suma+(a-b); } else { suma=suma+(a+b); } } if (n=='L') { a=50; if(b<a) { suma=suma+(a-b); } else { suma=suma+(a+b); } } if (n=='C') { a=100; if(b<a) { suma=suma+(a-b); } else { suma=suma+(a+b); } } if (n=='D') { a=500; if(b<a) { suma=suma+(a-b); } else { suma=suma+(a+b); } } if (n=='M') { a=1000; if(b<a) { suma=suma+(a-b); } else { suma=suma+(a+b); } } b=a; scanf("%c",&n); } } else { fprintf(stderr,"ERROR: El numero introducido no es correcto \n"); return -1; } printf("Este es el numero: %i",suma); return 0; }
Si tienes problemas con la lógica para la conversión lo indicas y se te puede ayudar. Cordiales Saludos.
|
|
|
3
|
Programación / Java / Actualizar MYSQL desde evento JAVA
|
en: 6 Abril 2014, 14:10 pm
|
Hola buenos dias mi gente, estoy teniendo problema para actualizar mi base de datos mysql desde un envento serial. El tema seria el siguiente: estoy recogiendo datos desde otro sistema mediante un evento serial, los datos se estan mostrando a la perfeccion, pero cuando estos datos llegan trato de llamar al metodo insert (mi metodo de insert en mysql) y nunca llega a este metodo. el codigo es el siguiente. SerialPortEventListener evento = new SerialPortEventListener() { @Override public void serialEvent(SerialPortEvent spe) { if(arduino.MessageAvailable()==true) { concatenar = concatenar + arduino.PrintMessage(); } if (concatenar.length()>20) { data = concatenar.split("!"); for (inicio=0; inicio<data.length; inicio++) { System.out.println(data[inicio]); } db_conexion obj = new db_conexion(); try { obj.db_conexion(); obj.insertar(data); System.out.println("aka"); Thread.sleep(60000); } catch (SQLException ex) { Logger.getLogger(ventana_p.class.getName()).log(Level.SEVERE, null, ex); } termo.setValue(Double.parseDouble(data[4]));//Integer.parseInt(data[3])); txt_temperatura_actual.setText((data[4])+"º C"); segundosDataset = new DefaultValueDataset(Double.parseDouble(data[1])); dialplot_velocidad.setDataset(0, segundosDataset); txt_velocidad_actual.setText(data[1]+" km/h"); indice = Integer.parseInt(data[5]); // utilizo la misma variable indice dataset = new DefaultValueDataset(indice/133.322368); dialplot_presion_at.setDataset(dataset); txt_humedad_relativa.setText(data[3]+" %"); indice = Integer.parseInt(data[2]);//{"1","2","3","4","5","6","7","8"};//{"O","NO","N","SO","NE","S","SE","E"} if(indice== 3) { System.out.println ("--->N"); panel_de_vel_viento.setIcon(Imagen[0]); } if(indice== 5) { System.out.println ("--->NE"); panel_de_vel_viento.setIcon(Imagen[1]); } if(indice== 2) { System.out.println ("--->NO"); panel_de_vel_viento.setIcon(Imagen[2]); } if(indice== 8) { System.out.println ("--->E"); panel_de_vel_viento.setIcon(Imagen[3]); } if(indice== 1) { System.out.println ("--->O"); panel_de_vel_viento.setIcon(Imagen[4]); } if(indice== 6) { System.out.println ("--->S"); panel_de_vel_viento.setIcon(Imagen[5]); } if(indice== 7) { System.out.println ("--->SE"); panel_de_vel_viento.setIcon(Imagen[6]); } if(indice== 4) { System.out.println ("--->SO"); panel_de_vel_viento.setIcon(Imagen[7]); } System.out.println(concatenar); System.out.println(concatenar.length()); concatenar =""; } throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } // fin del metodo }; //fin del evento
colocare mi metodo insert pero segun mis pruebas el metodo insert esta bien, porque lo llamo de la misma forma desde un boton y este si funciona. pero bueno aqui esta: public void insertar( String data[]) throws SQLException { prepared=conexion.prepareStatement("SELECT max(da_id_data) FROM `te_data`"); tabla=prepared.executeQuery(); metadata=tabla.getMetaData(); while (tabla.next()) { filas =new Object[metadata.getColumnCount()]; for (int i = 0; i < filas.length; i++) filas[i]=tabla.getObject(i+1); } String convert = String.valueOf(filas[0]); int siguiente = Integer.parseInt(convert)+1; Calendar cal = Calendar.getInstance(); // java.sql.Timestamp date = new java.sql.Timestamp(new java.util.Date().getTime());
PreparedStatement pstmt = null; try { String query = "insert into te_data (da_id_usuario, da_id_data, da_fecha, da_temperatura, da_humedad, da_velocidad, da_direccion, da_presion_at) values(?, ?, ?, ?, ?, ?, ?, ?)";
// create PrepareStatement object pstmt = conexion.prepareStatement(query); pstmt.setInt(1,1); pstmt.setInt(2, siguiente); pstmt.setTimestamp(3, new java.sql.Timestamp(cal.getTimeInMillis())); pstmt.setFloat(4, 24);//Float.parseFloat(data[4])); pstmt.setInt(5,12);//Integer.parseInt(data[3])); pstmt.setDouble(6, 23);//Double.parseDouble(data[1]) ); pstmt.setString(7,"S");// data[2]); pstmt.setDouble(8, 762);//Double.parseDouble(data[5])); int rowCount = pstmt.executeUpdate(); System.out.println("rowCount=" + rowCount); } finally { pstmt.close(); conexion.close(); } }//fin del metodo
si alguien ha actualizado mysql desde un evento serial ayuda. OJO EL MÉTODO ESTA ACTUALIZANDO DESDE UN BOTÓN, mas no cuando ocurre el envento serial. Saludos y gracias de ante mano por cualquiera ayuda.
|
|
|
4
|
Informática / Electrónica / Arduino (Sensor de temperatura y presion Bmp085 o Gy-65) Ayuda
|
en: 23 Abril 2013, 03:54 am
|
Hola Hackers, espero como siempre todos este bien de salud y sino bueno al menos con animo de aprender cada dia algo nuevo. Esta vez he recurido a ustedes por el simple hecho de que me he comprado un sensor barometrico bmp085, el problema es que al conectarlo a mi arduino Mega 2560 no me envia mensaje al pc. Adjunto Codigo: #include <Wire.h>
#define BMP085_ADDRESS 0x77 // I2C address of BMP085
const unsigned char OSS = 0; // Oversampling Setting
// Calibration values int ac1; int ac2; int ac3; unsigned int ac4; unsigned int ac5; unsigned int ac6; int b1; int b2; int mb; int mc; int md;
// b5 is calculated in bmp085GetTemperature(...), this variable is also used in bmp085GetPressure(...) // so ...Temperature(...) must be called before ...Pressure(...). long b5;
short temperature; long pressure;
// Use these for altitude conversions const float p0 = 101325; // Pressure at sea level (Pa) float altitude;
void setup() { Serial.begin(9600); Wire.begin(); bmp085Calibration(); }
void loop() { temperature = bmp085GetTemperature(bmp085ReadUT()); pressure = bmp085GetPressure(bmp085ReadUP()); altitude = (float)44330 * (1 - pow(((float) pressure/p0), 0.190295));
Serial.print("Temperature: "); Serial.print(temperature, DEC); Serial.println(" *0.1 deg C"); Serial.print("Pressure: "); Serial.print(pressure, DEC); Serial.println(" Pa"); Serial.print("Altitude: "); Serial.print(altitude, 2); Serial.println(" m"); Serial.println(); delay(1000); }
// Stores all of the bmp085's calibration values into global variables // Calibration values are required to calculate temp and pressure // This function should be called at the beginning of the program void bmp085Calibration() { ac1 = bmp085ReadInt(0xAA); ac2 = bmp085ReadInt(0xAC); ac3 = bmp085ReadInt(0xAE); ac4 = bmp085ReadInt(0xB0); ac5 = bmp085ReadInt(0xB2); ac6 = bmp085ReadInt(0xB4); b1 = bmp085ReadInt(0xB6); b2 = bmp085ReadInt(0xB8); mb = bmp085ReadInt(0xBA); mc = bmp085ReadInt(0xBC); md = bmp085ReadInt(0xBE); }
// Calculate temperature given ut. // Value returned will be in units of 0.1 deg C short bmp085GetTemperature(unsigned int ut) { long x1, x2; x1 = (((long)ut - (long)ac6)*(long)ac5) >> 15; x2 = ((long)mc << 11)/(x1 + md); b5 = x1 + x2;
return ((b5 + 8)>>4); }
// Calculate pressure given up // calibration values must be known // b5 is also required so bmp085GetTemperature(...) must be called first. // Value returned will be pressure in units of Pa. long bmp085GetPressure(unsigned long up) { long x1, x2, x3, b3, b6, p; unsigned long b4, b7; b6 = b5 - 4000; // Calculate B3 x1 = (b2 * (b6 * b6)>>12)>>11; x2 = (ac2 * b6)>>11; x3 = x1 + x2; b3 = (((((long)ac1)*4 + x3)<<OSS) + 2)>>2; // Calculate B4 x1 = (ac3 * b6)>>13; x2 = (b1 * ((b6 * b6)>>12))>>16; x3 = ((x1 + x2) + 2)>>2; b4 = (ac4 * (unsigned long)(x3 + 32768))>>15; b7 = ((unsigned long)(up - b3) * (50000>>OSS)); if (b7 < 0x80000000) p = (b7<<1)/b4; else p = (b7/b4)<<1; x1 = (p>>8) * (p>>8); x1 = (x1 * 3038)>>16; x2 = (-7357 * p)>>16; p += (x1 + x2 + 3791)>>4; return p; }
// Read 1 byte from the BMP085 at 'address' char bmp085Read(unsigned char address) { unsigned char data; Wire.beginTransmission(BMP085_ADDRESS); Wire.write(address); Wire.endTransmission(); Wire.requestFrom(BMP085_ADDRESS, 1); while(!Wire.available()) ; return Wire.read(); }
// Read 2 bytes from the BMP085 // First byte will be from 'address' // Second byte will be from 'address'+1 int bmp085ReadInt(unsigned char address) { unsigned char msb, lsb; Wire.beginTransmission(BMP085_ADDRESS); Wire.write(address); Wire.endTransmission(); Wire.requestFrom(BMP085_ADDRESS, 2); while(Wire.available()<2) ; msb = Wire.read(); lsb = Wire.read(); return (int) msb<<8 | lsb; }
// Read the uncompensated temperature value unsigned int bmp085ReadUT() { unsigned int ut; // Write 0x2E into Register 0xF4 // This requests a temperature reading Wire.beginTransmission(BMP085_ADDRESS); Wire.write(0xF4); Wire.write(0x2E); Wire.endTransmission(); // Wait at least 4.5ms delay(5); // Read two bytes from registers 0xF6 and 0xF7 ut = bmp085ReadInt(0xF6); return ut; }
// Read the uncompensated pressure value unsigned long bmp085ReadUP() { unsigned char msb, lsb, xlsb; unsigned long up = 0; // Write 0x34+(OSS<<6) into register 0xF4 // Request a pressure reading w/ oversampling setting Wire.beginTransmission(BMP085_ADDRESS); Wire.write(0xF4); Wire.write(0x34 + (OSS<<6)); Wire.endTransmission(); // Wait for conversion, delay time dependent on OSS delay(2 + (3<<OSS)); // Read register 0xF6 (MSB), 0xF7 (LSB), and 0xF8 (XLSB) Wire.beginTransmission(BMP085_ADDRESS); Wire.write(0xF6); Wire.endTransmission(); Wire.requestFrom(BMP085_ADDRESS, 3); // Wait for data to become available while(Wire.available() < 3) ; msb = Wire.read(); lsb = Wire.read(); xlsb = Wire.read(); up = (((unsigned long) msb << 16) | ((unsigned long) lsb << 8) | (unsigned long) xlsb) >> (8-OSS); return up; }
Este codigo a sido copiado de la internet. lo he revisado y con el poco conocimiento que tengo de programacion en Arduino, creo que esta bien. En realidad me compila sin errores pero cuando lo cargo a mi placa no manda señal, la placa esta buena comprobada 100%, el barometro no tengo idea si funciona me llego de china esta mañana y soy de panama. 1 mes me tardo alguna idea de como probar este barometro usa salidas analogicas. he notado que mi barometro dice gy-65 !! creo que esto tambien puede estar afectando no dice bmp085 aunq esta fue la especificacion que pedi. Adjunto guia:
|
|
|
7
|
Programación / Desarrollo Web / Perfil de un Programador Web.
|
en: 2 Julio 2012, 21:17 pm
|
Hola un saludo y un gran abrazo a todos.
He visto en algunas paginas de trabajo que lo que mas se requiere son programadores web, donde algunas especifican todo los que debe saber la persona que aspire al trabajo. algunos solo dicen programador web otros dicen diseñador web. Entonces los términos me están matando. quisiera saber: 1-¿La diferencia entre diseñador y programador web? 2-¿Las empresas usan programadores y diseñadores o 1 persona tienen que ejecutar el mismo rol? 3-¿Cual es el perfil de un programador web? (perfil digo los conocimientos basicos que deebe tener.)
Gracias de ante mano!
|
|
|
|
|
|
|