Hi everyone, I’m working with my program and I’m implementing some images to make them become buttons. Every time I click on the button I send a command to my Arduino to turn on the LED. Now, as it is structured, if I press ON it disappears and I turn on the LED, if I press OFF it disappears and I turn off the LED and it comes back ON. I can put these on each other and make it appear when I click. That is, initially OFF appears if I press enter the command and exit ON.
@Luka Jovic You can use a Canvas and draw one of the two icons depending on the current state:
If it is ON, draw the OFF icon
If is is OFF, draw the ON icon
Add a Boolean Property to the Window containing the Canvas (the Button representation). Something like “LED1Status”.
Set the Property to On/Off according to the LED Status.
(following Code written from my mind, may contain errors)
In the MouseUp Event of the Canvas write something like:
Serial1.Write("LED1ON")
LED1Status = Not LED1Status // Or True and False
btnCanvas.Invalidate // Makes the Canvas redraw (fire the Paint Event) ASAP
Return True // I think this is needed...
In the Canvas.Paint Event do something like this:
If LED1Status Then
g.DrawPicture(picON, 0, 0)
Else
g.DrawPicture(picOFF, 0, 0)
End If
Just add a new Property to your Window in the Xojo IDE. Name it LED1Status and set it’s Type to Boolean and the default value to the Start Status of the LED.