comenzando desde cero (Starting from scratch)

What are you working on .... Show off your Rov's Projects here.
Post Reply
User avatar
bigbadbob
Posts: 272
Joined: Nov 28th, 2011, 10:24 am

Re: comenzando desde cero (Starting from scratch)

Post by bigbadbob »

also-

in your slave code you put-

Code: Select all

else if (ps2x.Button(PAD_DOWNstate))
    // Si presionamos el boton izquierda abajo
  {
    rxdata.PAD_DOWNstate = (rxdata.PAD_DOWNstate);
    digitalWrite(yelLEDpin, HIGH);
    // Enciende el Led Amarillo
  }
the slave cannot read the PS2 buttons so you need to read the rxdata.
so you need-

Code: Select all

PAD_DOWNstate = (rxdata.PAD_DOWNstate);//this must be before the if.
if (PAD_DOWNstate)
    // Si presionamos el boton izquierda abajo
  {
    digitalWrite(yelLEDpin, HIGH);
    // Enciende el Led Amarillo
  }
You want to use if's not else if's here or the code will only do one thing.

and here in your slave-

Code: Select all

void loop_Luces() { // Bloque de trabajo de los focos
  digitalWrite(HeadLts, rxdata.LEDHdlts);
  // Enciende los faros en función del retraso de los datos del mensaje
  if (rxdata.LEDHdlts = 0) //This will make rxdata.LEDHlts equal to 0, ?????? never use = with if statements                                       
                                  // try if (rxdata.LEDHdlts > 0) or (rxdata.LEDHdlts == 1) or just (rxdata.LEDHdlts) ;-) 
 {
    Serial.print(" \n Focos encendidos ");
  }
  else {
    (rxdata.LEDHdlts == 0); //This will not work either... try- else if (rxdata.LEDHdlts == 0){serial print......
                                     // or- else if (!rxdata.LEDHdlts){ serial print... or just use else {serial print...
    Serial.print(" \n Focos apagados ");
  }
}
here is my code for you to have a look at and see how the code flows.
Attachments
MiniRay_OSD.zip
(2.75 KiB) Downloaded 1291 times
Miniray_Slave.zip
(3.6 KiB) Downloaded 1402 times
MiniRay_Master.zip
(2.27 KiB) Downloaded 1480 times
Last edited by bigbadbob on Apr 19th, 2020, 8:15 am, edited 2 times in total.
asesorplaza1
Posts: 187
Joined: Mar 4th, 2018, 6:11 pm
Location: Valverde de Júcar, Cuenca, España

Re: comenzando desde cero (Starting from scratch)

Post by asesorplaza1 »

Muchas gracias por tu tiempo y tu comentario. Voy a estudiarlo y a implantar la solución, muchas gracias.

Thank you very much for your time and your comment. I'm going to study it and implement the solution, thank you very much.
User avatar
bigbadbob
Posts: 272
Joined: Nov 28th, 2011, 10:24 am

Re: comenzando desde cero (Starting from scratch)

Post by bigbadbob »

If you study me code I have put in a lot of comments to explain each step, that should help you understand how to do what you want to do.
lo siento, no hablo español.
asesorplaza1
Posts: 187
Joined: Mar 4th, 2018, 6:11 pm
Location: Valverde de Júcar, Cuenca, España

Re: comenzando desde cero (Starting from scratch)

Post by asesorplaza1 »

No te preocupes por el idioma, el traductor de Google hace milagros.
He realizado los cambios que me has sugerido, por lo que he visto en tus códigos solo tenia que añadir unas lineas al Maestro, y dejar el Esclavo como estaba, te ruego lo compruebes, muchas gracias.


Don't worry about the language, Google's translator works miracles.
I have made the changes that you have suggested to me, so I have seen in your codes I just had to add a few lines to the Master, and leave the Slave as it was, I beg you to check, thank you very much.
Attachments
25_19_04_2020.rar
(15.75 KiB) Downloaded 1377 times
User avatar
bigbadbob
Posts: 272
Joined: Nov 28th, 2011, 10:24 am

Re: comenzando desde cero (Starting from scratch)

Post by bigbadbob »

Ok.... :?

in your master, line 318 you say-

if (ps2x.Button(PAD_UPstate)) // Si presionamos el boton izquierda arriba
{
txdata.PAD_UPstate = (PAD_UPstate);
digitalWrite(yelLEDpin, HIGH); // Enciende el Led Amarillo
}


it should be-
if (ps2x.Button(PAD_UP)) // Si presionamos el boton izquierda arriba
{
digitalWrite(yelLEDpin, HIGH); // Enciende el Led Amarillo
}
else
{
digitalWrite(yelLEDpin, low);// you have to turn it off if it is allready on
}
txdata.PAD_UPstate = (PAD_UPstate);

or you can use-

if (PAD_UPstate) // Si presionamos el boton izquierda arriba
{
digitalWrite(yelLEDpin, HIGH); // Enciende el Led Amarillo
}
else
{
digitalWrite(yelLEDpin, low);// you have to turn it off if it is allready on
}
txdata.PAD_UPstate = (PAD_UPstate);

And repeat this for the other buttons.
User avatar
bigbadbob
Posts: 272
Joined: Nov 28th, 2011, 10:24 am

Re: comenzando desde cero (Starting from scratch)

Post by bigbadbob »

and master line 277-

if (error = 0) {// SHOULD BE- if (error == 0) OR YOU CAN USE- if(!error) it means the same thing. ;-)
Serial.print(" \n Iniciando Sistema: !");
Serial.print(" \n Mando PS2 Preparado: !");
}
asesorplaza1
Posts: 187
Joined: Mar 4th, 2018, 6:11 pm
Location: Valverde de Júcar, Cuenca, España

Re: comenzando desde cero (Starting from scratch)

Post by asesorplaza1 »

Muchas gracias por su tiempo y sus comentarios.
Casi no me da tiempo a leerlos y ha hacer las modificaciones, muchas gracias de verdad.
Sigue así por favor, llevo mucho tiempo atascado con el código y de verdad, necesitaba a alguien que me echara una mano.
Un saludo desde España.


Thank you very much for your time and feedback.
He hardly gives me time to read them and he has made the modifications, thank you very much for real.
Keep it up, please, I've been stuck with the code for a long time, and I really needed someone to give me a hand.
A greeting from Spain
asesorplaza1
Posts: 187
Joined: Mar 4th, 2018, 6:11 pm
Location: Valverde de Júcar, Cuenca, España

Re: comenzando desde cero (Starting from scratch)

Post by asesorplaza1 »

Tengo una duda, que no se si te la he comentado, o si la has podido leer en la presentación de código.
Pretendo cambiar el LCD, por una pantalla Nextion de 5", y en otro foro ne han comentado que si pongo muchos " if ", el código se hace demasiado pesado para que trabajen bien el Arduino y la Nextion, me han aconsejado que en vez de utilizar los " if ", utilice " else if ", para agilizar el código, de cara a utilizarlo con la Nextion.
¿Que te parece esto?.
Te lo recuerdo, no valla a ser que cambiemos y arreglemos el código y luego haya que volverlo a cambiar.
Un saludo desde España.


I have a question, that I don't know if I've told you, or if you've been able to read it in the code presentation.
I intend to change the LCD, to a 5" Nextion screen, and in another ne forum have commented that if I put many "if", the code becomes too heavy for the Arduino and the Nextion to work well, I have been advised that instead of using the "if", use "else if", to expedite the code, to use it with the Nextion
How about this?.
I remind you, it's not going to turn around and we'll change and fix the code and then we have to change it again.
Greetings from Spain.
asesorplaza1
Posts: 187
Joined: Mar 4th, 2018, 6:11 pm
Location: Valverde de Júcar, Cuenca, España

Re: comenzando desde cero (Starting from scratch)

Post by asesorplaza1 »

Muchas gracias por su tiempo.
Ya he arreglado los dos códigos como me dijo, no ha sido tan difícil, al contrario ha sido bastante fácil gracias a sus comentarios. De verdad muchas gracias por ayudarme.
Un saludo desde España.


Thank you very much for your time. I have already fixed the two codes as you told me, it has not been so difficult, on the contrary it has been quite easy thanks to your comments. Really thank you so much for helping me.Greetings from Spain.
Attachments
26_19_04_2020.rar
(15.81 KiB) Downloaded 1274 times
Last edited by asesorplaza1 on Apr 19th, 2020, 7:34 pm, edited 1 time in total.
asesorplaza1
Posts: 187
Joined: Mar 4th, 2018, 6:11 pm
Location: Valverde de Júcar, Cuenca, España

Re: comenzando desde cero (Starting from scratch)

Post by asesorplaza1 »

Esta tarde he perdido muchísimo tiempo intentando arreglar la parte del código que controla el mando de PS2.
Tanto en el " Maestro ", como en el " Esclavo ", y no he conseguido arreglar nada, sigo igual.
El mando no hace caso a las ordenes que le doy.
Para colmo en los dos últimos códigos que he probado, que son poco mas que las librerías, el LED chivato que indica que el mando esta encendido, ni si quiera se ha dignado a encenderse.
Esta tarde si se encendía, pero en las dos ultimas pruebas no se ha encendido.
El caso es que no he tocado las conexiones eléctricas, solo he tocado los códigos, asegurándome que la distribución de los pines de contacto del mando fuese en los mismos pines,

" error = ps2x.config_gamepad(13, 11, 10, 12, true, true); // Pines y ajustes de configuración ".

Ya solo puede quedarme alguna tontería, que por obvia no veo, ni encuentro como solucionarla.
He probado a cambiar de mando, por si se hubiera roto, pero no los 2 que tengo hacen lo mismo.
Una cosa muy rara, porque un mando se puede estropear, pero los dos el mismo día?, es muy difícil.
Debe ser algún error de programación.
De todas formas no es la primera vez que me lo hace, y después, se arregla solo, es algo muy raro.

Muchas gracias por su tiempo.

Un saludo desde España.




This afternoon I wasted a lot of time trying to fix the part of the code that controls the PS2 controller.
Both in the "Master" and in the "Slave", and I have not managed to fix anything, I remain the same.
he command ignores the orders I give you.
To top it off in the last two codes I have tried, which are little more than the bookstores, the chivato LED indicating that the controller is on, nor has it even deigned to turn on.
This afternoon if it was turned on, but in the last two tests it hasn't been turned on.
The fact is that I have not touched the electrical connections, I have only touched the codes, making sure that the distribution of the control contact pins was on the same pins,

" error = ps2x.config_gamepad(13, 11, 10, 12, true, true); // Pins and configuration settings ".

Now all there can be something nonsense left, which I obviously don't see, nor do I find how to fix it.
I've tried switching controls, in case it's broken, but not the two I've got do the same thing.
A very strange thing, because a controller can be messed up, but the two on the same day?, is very difficult.
There must be some programming error.
Anyway, it's not the first time he's done it to me, and then he fixes himself, it's a very weird thing.

Thank you very much for your time.

Greetings from Spain.
Post Reply