Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 01:59 07 Jul 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 : Help with LED.

Author Message
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 02:31pm 17 Sep 2016
Copy link to clipboard 
Print this post

Anyone got any suggestion or up for a challenge with this?

I think it would be useful to be able to blink a GUI LED.

The Challenge is how?

Started this simple bit of code as a framework, but can see a few things that need consideration.

Using PAUSE is not a real option, I only put it there for my first demo to see a result on the screen. I know that's not evenly remotely the right approach.

Second to that, this could only work with a single GUI LED at any time.

Assuming I wanted to flash, say 4 LED's I presume their Timer on value may need to be stored in an Array, so the function or sub would know when they have been illuminated for the prescribed period.

This is the VERY SIMPLE framework I have started with.

[Code]'Flash Led

Option Explicit
Option Default None

Dim Integer L_StatLed1=1,n

CLS
GUI LED L_StatLed1, "Test LED", 100, 100, 100, RGB(Red)


For n=1 to 10
FlashLed (L_StatLed1,300) 'Blink the GUI LED for 300ms
Pause 1000 'Flash it again after 1 second.
Next n

'Function FlashLed
Sub FlashLed (LedID as Integer,Duration as Integer) As Integer

CtrlVal(LedID)=1
Print "LED On"
Pause Duration
CtrlVal(LedID)=0
Print "LED Off"

End Sub
'End Function[/code]

As I said, I know it's wrong, just demonstrates.

Thanks

Phil.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6269
Posted: 06:28pm 17 Sep 2016
Copy link to clipboard 
Print this post

I might be way off the mark, but I think this will do what you are after

An array holds the desired state of each gui element. Keep the nuimbers consecutive to make life easier.

If you want to flash a LED, set its array element to '1'
To stop flashing, set zero and to flash inverted (off when the others are on) set '2'
When they are not flashing you can still turn them on and off as normal.

  Quote  
OPTION EXPLICIT
COLOUR RGB(WHITE), RGB(BLACK)
DIM isON, n
DIM flickThese(10) ' array big enough to hold the controls you want to flicker
CONST led_run = 1, led_alarm = 2, led_warn = 3

CLS
GUI LED led_run, "Running", 100, 100, 16, RGB(GREEN)
GUI LED led_alarm, "Oh my gosh!", 100, 120, 16, RGB(RED)
GUI LED led_warn, "Interesting", 100, 140, 16, RGB(WHITE)

SETTICK 500, flicker, 4 ' togle the leds every 500mS

flickThese(
1) = 1
flickThese(
3) = 1
DO
IF TOUCH(x) >0 THEN
flickThese(
2) = 1-flickThese(2) : CTRLVAL(2) = flickThese(2) ' toggle
IF TOUCH(x) > MM.HRES/2 THEN
flickThese(
3) = 1
ELSE
flickThese(
3) = 2
ENDIF
PRINT flickThese(3)
ENDIF
PAUSE 50
LOOP

SUB flicker
LOCAL n
isON=
1 - isON
FOR n = 1 TO 3
IF flickThese(n) = 1 THEN
CTRLVAL(n) = isON
ELSEIF flickThese(n) = 2 THEN
CTRLVAL(n) = 1 - isON
ENDIF
NEXT n
END SUB


I haven't done any GUI programming yet so the example is very basic.
Touch on the left side of the display to have LED 3 inverted, right side for in phase.

Jim
VK7JH
MMedit
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 07:38pm 17 Sep 2016
Copy link to clipboard 
Print this post

  TassyJim said   I might be way off the mark, but I think this will do what you are after[/quote]

Hi Jim,

That helps a bit. I figured an array would be required.

The practical application is a bit along these lines:-

If say a coms request is received; the coms Led would illuminate for a brief period to indicate the request has been received etc for other LEDS.

Maybe I'm looking it from the wrong angle, as I was considering different pulse times, a bit along the PULSE command that can pulse an IO pin.

Might be better off just sticking with 500ms of whatever.
Otherwise I'm going to ge diving in & out of a sub all the time to check how long a LED's been turned on & if its time yet to turn it off.

I was thinking an array would need a Timer value on time for each element, so I could control the duration of the flash for different Leds.

On a side note, regards you coloured code.

When I pasted the above code into MMedit it appeared double spaced.

Cheers

Phil
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6269
Posted: 08:59pm 17 Sep 2016
Copy link to clipboard 
Print this post

I would go with the simple choice:
Turn the LED on at the start of the comms receive routine and off at the end.
The more data, the longer the LED is on for.
Simple and a good indicator of activity.

I will talk to Glenn and see how we are going to get rid of the double spacing.
Luckily, MMEdit has a get-rid-of-blank-lines function.

Jim

VK7JH
MMedit
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 10:54pm 17 Sep 2016
Copy link to clipboard 
Print this post

  TassyJim said   I would go with the simple choice:
Turn the LED on at the start of the comms receive routine and off at the end.


That's basically what I'm doing at one of the slave ends at present, needs a 150ms pause to make the LED noticeable.

The other has a physical Led that's much more easily visible. That slave has no display.

On the Master I've resorted to inverting the Led on each successful receipt of coms.
On & off at the start & end of the routines didn't work on the MM+ as it's processing is too quick.

Similarly, early on I had a status Led that inverted each time the main loop was run.
You could tell all was running easily from a distance.

Had to reclaim that pin, so it's a graphic led now (28p backpack).

Thanks

Phil.
 
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