Page 1 of 1

3-Color Dynamic LED Switch

PostPosted: Sat Mar 26, 2022 2:46 pm
by pwesynthmaker
My 'almost-all-my-very-own ruby code' .fsm schematic.
A LED switch with 3-colored 'dynamic' text and 'float' value input/output.
.
Download Link:
https://invntefx.com/ssl/_invntefxfston ... rubysw.zip

Here is the Ruby Code:

==========

# ledsw32pxmultilbl ruby code

def draw v

# Calculate the rect to draw the text inside
# Rectangle width & height = relative to font size w/word wrap
# + led diam
rect1 = [0,-3.5,v.width,v.height]
rect2 = [0,0.75,v.width,v.height]
rect3 = [0,4,v.width,v.height]

# Setup font1 and alignment
font1 = Font.new "Arial",1.75,"bold"
sf1 = StringFormat.new
sf1.setAlignment "center"
sf1.setLineAlignment "center"

# Draw the label
v.drawString @label1,font1,sf1,rect1,(Brush.new @color1)


# Setup font2 and alignment
font2 = Font.new "Arial",1.75,"bold"
sf2 = StringFormat.new
sf2.setAlignment "center"
sf2.setLineAlignment "center"

# Draw the label
v.drawString @label2,font2,sf2,rect2,(Brush.new @color2)


# Setup font3 and alignment
font3 = Font.new "Arial",1.75,"bold"
sf3 = StringFormat.new
sf3.setAlignment "center"
sf3.setLineAlignment "center"

# Draw the label
v.drawString @label3,font3,sf3,rect3,(Brush.new @color3)

end

def event i,v
redraw 0
end

==========