Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 16:09 09 May 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Change GUI LED Colour

Author Message
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 982
Posted: 09:47pm 25 Mar 2025
Copy link to clipboard 
Print this post

What is the easiest way to change the colour of a GUI LED given a flag before the CtrlVal is enabled? Do I have to remove the GUI LED reference of one colour then re-instate the definition of a new colour?

OA47
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2414
Posted: 01:10am 26 Mar 2025
Copy link to clipboard 
Print this post

The best I could come up with is overlapping 2 LEDs. Then using a variable for #number.
CLS 255
GUI led #1, "LED", MM.HRes/2, MM.VRes/2, 88, 255<<16
GUI led #2, "LED",  MM.HRes/2, MM.VRes/2, 88, 255<<8
Do
  Col% = 1
  CtrlVal(#Col%) = 2500
  Pause 4000
  Col% = 2
  CtrlVal(#Col%) = 2500
  Pause 4000
Loop
End
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 982
Posted: 02:18am 26 Mar 2025
Copy link to clipboard 
Print this post

This is the code I am using at the moment but I was wondering if there was a more elegant way of achieving the result.
Sub BlinkLED
If RadMsg=1 Then
 GUI DELETE #37
 GUI LED 37, "",118, 38, 10 , RGB(White)  'Action Indicator LED White
Else
 GUI DELETE #37
 GUI LED 37, "",118, 38, 10 , RGB(Red)    'Action Indicator LED Red
End If
 CtrlVal(37)=1:Pause 100:CtrlVal(37)=0    'Pulse LED to indicate operation
End Sub


OA47
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2414
Posted: 03:00am 26 Mar 2025
Copy link to clipboard 
Print this post

This does the same thing.
CLS 255
GUI led #37, "", 118, 38, 10, RGB(WHITE)
GUI led #38, "", 118, 38, 10, RGB(RED)
Do
  BlinkLED
  Pause 2000
  RadMsg = NOT RadMsg
Loop
End

Sub BlinkLED
  If RadMsg Then
    Col% = 37
   Else
    Col% = 38
  EndIf
  CtrlVal(Col%) = 100  'Pulse LED 100mS to indicate operation
End Sub

Edit.
Well it does when running the program above but at the command line it just stays on.
So at the prompt you do need the pause then switch off:-
CtrlVal(Col%) = 1 : Pause 100 : CtrlVal(Col%) = 0

Edit 2.
One less line.
CLS 255
GUI led #37, "", 118, 38, 10, RGB(WHITE)
GUI led #38, "", 118, 38, 10, RGB(RED)
Do
  BlinkLED
  Pause 2000
  RadMsg = NOT RadMsg
Loop
End

Sub BlinkLED
  If RadMsg Then
    CtrlVal(37) = 100  'Pulse LED white for 100mS to indicate operation
   Else
    CtrlVal(38) = 100  'Pulse LED red for 100mS to indicate operation
  EndIf
End Sub

Edited 2025-03-27 09:20 by phil99
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025