1
I am making a program for Rduino written in C++ to turn on and off leds when a button is pressed. I created an Led class and put in it the methods, now I wrote an if that checks when a button is pressed, but I want that when the if checks that the button was pressed it automatically passes the led referring to the button as for the method. Something like that.
if(digitalRead(led1.botão || led2.botão) == 0) { // verifica se algum botão foi pressionado
"Ledpressionado".ligar(); // seleciona o led referente ao botão pressionado
In java this happens automatically with the use of this, but in c++ no.
I am assuming that this code is within the method since you said that in java would use
this
. So just use thethis
in C++ as well:this->ligar();
– Tiago Gomes
So Tiago, actually the code is inside the void loop() and not inside a class method, so I can’t use this, already in Java I could use it to refer to the object invoked the action.
– TheGMX