Need advices for "linear leds"

Questions about deployment and use of Air Manager Instruments

Moderators: russ, Ralph

Message
Author
oscarDelta77
Posts: 57
Joined: Sat Nov 26, 2016 9:58 pm

Need advices for "linear leds"

#1 Post by oscarDelta77 »

Hi there,

How would you manage display ?

I mean, Red, Green and Yellow Leds

This a gauge for a PA28 Cadet Diesel

Image

Thanks for your advices !

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Need advices for "linear leds"

#2 Post by Keith Baxter »

Hi,

I would use canvas_draw and then a for loop for all the led's.

Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

oscarDelta77
Posts: 57
Joined: Sat Nov 26, 2016 9:58 pm

Re: Need advices for "linear leds"

#3 Post by oscarDelta77 »

Thanks Keith !

Edit : I've found canvas_draw in wiki.

User avatar
Ralph
Posts: 7878
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: Need advices for "linear leds"

#4 Post by Ralph »

If canvas is too difficult then images can work as well.
You can put them in an array to make it a bit easier. But if that's also new for you then I suggest to start simple.

oscarDelta77
Posts: 57
Joined: Sat Nov 26, 2016 9:58 pm

Re: Need advices for "linear leds"

#5 Post by oscarDelta77 »

Thanks Ralph !

I' trying canvas_draw()

These lines are working fine :

Code: Select all

Volt_1 = canvas_add(105, 50, 200, 200, function()
   _rect(50,50,7,25)
   _fill("red")
end)

Volt_2 = canvas_add(115, 50, 200, 200, function()
   _rect(50,50,7,25)
   _fill("red")
end)

Volt_3 = canvas_add(125, 50, 200, 200, function()
   _rect(50,50,7,25)
   _fill("yellow")
end)

Volt_4 = canvas_add(135, 50, 200, 200, function()
   _rect(50,50,7,25)
   _fill("green")
end)

Volt_5 = canvas_add(145, 50, 200, 200, function()
   _rect(50,50,7,25)
   _fill("green")
end)

Volt_6 = canvas_add(155, 50, 200, 200, function()
   _rect(50,50,7,25)
   _fill("green")
end)

Volt_7 = canvas_add(165, 50, 200, 200, function()
   _rect(50,50,7,25)
   _fill("green")
end)

Volt_8 = canvas_add(175, 50, 200, 200, function()
   _rect(50,50,7,25)
   _fill("yellow")
end)

Volt_9 = canvas_add(185, 50, 200, 200, function()
   _rect(50,50,7,25)
   _fill("red")
end)

Volt_10 = canvas_add(195, 50, 200, 200, function()
   _rect(50,50,7,25)
   _fill("red")
end)

Volt_Group = group_add(Volt_1,Volt_2,Volt_3,Volt_4,Volt_5,Volt_6,Volt_7,Volt_8,Volt_9,Volt_10)
opacity(Volt_Group, 0.3)
However , an error "ERROR - logic.lua:71: Argument 'id(1)' in function 'opacity' is not a valid reference, which is not allowed is returned with these lines :

Code: Select all

for ID = 1, 10  do
    Volt_Id = "Volt_".. ID
    print(Volt_Id)
    opacity(Volt_Id, 0.0)
end
The print line works as it is a string, but the opacity line returns the error. The node_id is not a string. How can i handle it in a loop ?

I'm searching ...

User avatar
Ralph
Posts: 7878
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: Need advices for "linear leds"

#6 Post by Ralph »

Did you try tostring() ?

oscarDelta77
Posts: 57
Joined: Sat Nov 26, 2016 9:58 pm

Re: Need advices for "linear leds"

#7 Post by oscarDelta77 »

Yes, i did.

it does not work :

Code: Select all

for ID = 1, 10  do
    Volt_Id = "Volt_".. ID
    print(Volt_Id)
    opacity(tostring(Volt_Id), 1.0)
end
Return :

Code: Select all

INFO - Volt_1
ERROR - logic.lua:88: Argument 'id(1)' in function 'opacity' is not a valid reference, which is not allowed

User avatar
Ralph
Posts: 7878
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: Need advices for "linear leds"

#8 Post by Ralph »

I looked at your script on my phone, so I didn't have a close look at first. You're doing a opacity on a non existing node. First you have to create the node (image or whatever).

oscarDelta77
Posts: 57
Joined: Sat Nov 26, 2016 9:58 pm

Re: Need advices for "linear leds"

#9 Post by oscarDelta77 »

Ralph, thans for your help.

The nodes are created before the loop :

The fisrt one :

Code: Select all

Volt_1 = canvas_add(105, 50, 200, 200, function()
   _rect(50,50,7,25)
   _fill("red")
end)
This is working fine. So, with the line

Code: Select all

opacity(tostring(Volt_Id), 1.0)
should work when

Code: Select all

Volt_Id equals Volt_1
.

Am I missing something ?

To complete my anwser, with this line, all is fine :

Code: Select all

opacity(Volt_1, 1.0)
It looks like the variable Volt_Id should be converted to node_id type ...

User avatar
Ralph
Posts: 7878
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: Need advices for "linear leds"

#10 Post by Ralph »

Why would you create separate canvasses for each item? Why not one canvas for all?

Post Reply