LED watch simulation

Here is my LED watch simulation using os.date to get the time. You have to read it like a binary watch. Add the values from each glowing LED. To show/hint the values and the time touch the display.
Have Fun and excuse me for my bad german english ^^

Here is the code
It has two classes the main class and the Led class

Edit: See link below for extended Description.

--# Main
-------------
-- LED Uhr --
-------------
function setup()
    w = 0
    xu = HEIGHT/2
    yu = WIDTH/2
    zeit = false
    uhr = {Led(xu-75, yu+50, 9),    -- 9h        --
           Led(xu, yu+25, 6),       -- 6h        --
           Led(xu+75, yu+50, 3),    -- 3h        -- this block sets the 
           Led(xu-25, yu+50, 1),    -- 1h        -- position of the hour LEDs
           Led(xu+25, yu+50, 1),    -- 1h        --
           Led(xu, yu+75, 0),       -- 12h or 0h --
        
           Led(xu-75, yu-50, 45),   -- 45 min    --
           Led(xu, yu-75, 30),      -- 30 min    --
           Led(xu+75, yu-50, 15),   -- 15 min    --
           Led(xu-25, yu-50, 5),    --  5 min    --
           Led(xu+25, yu-50, 5),    --  5 min    -- this block sets the
           Led(xu-75, yu, 1),       --  1 min    -- position of the min LEDs
           Led(xu-25, yu, 1),       --  1 min    --
           Led(xu+25, yu, 1),       --  1 min    --
           Led(xu+75, yu, 1),       --  1 min    --
           Led(xu, yu-25, 0),       --  0 min    --
        
           Led(xu, yu, 0)           -- a.m. or p.m. LED
        }
    backingMode(RETAINED)
end

function draw()
    
    s = os.date("*t").sec         -- get seconds
    m = os.date("*t").min         -- get minutes
    h = os.date("*t").hour        -- get hours
    --print(h,":",m,":",s)          -- prints the time every frame
    
    noStroke()
    
    font("Courier-Bold")
    fill(255,0,0)
    fontSize(31)
    textAlign(CENTER)
    
    
    if zeit then -- if zeit == true then show the value of each LED
    text(h..":"..m..":"..s, xu, yu + 150)
    fill(255, 255, 255, 255)
    
    fontSize(10)
    
           text("9h",xu-75, yu+65)    -- 9h        --
           text("6h",xu, yu+40)       -- 6h        --
           text("3h",xu+75, yu+65)    -- 3h        --
           text("1h",xu-25, yu+65)    -- 1h        --
           text("1h",xu+25, yu+65)    -- 1h        --
           text("12h",xu, yu+90)      -- 12h or 0h --
        
           text("45m",xu-75, yu-35)   -- 45 min    --
           text("30m",xu, yu-60)      -- 30 min    --
           text("15m",xu+75, yu-35)   -- 15 min    --
           text("5m",xu-25, yu-35)    --  5 min    --
           text("5m",xu+25, yu-35)    --  5 min    -- 
           text("1m",xu-75, yu+15)    --  1 min    -- 
           text("1m",xu-25, yu+15)    --  1 min    --
           text("1m",xu+25, yu+15)    --  1 min    --
           text("1m",xu+75, yu+15)    --  1 min    --
           text("0m",xu+15, yu-25)    --  0 min    --
        
           --text("a.m. or p.m.",xu, yu)           -- a.m. or p.m. LED
    end
    
    fill(0, 0, 0, 20)
    rect(0,0,WIDTH,HEIGHT)        -- Background
    
    
    if h < 12 then                    -- a.m. or p.m.
        uhr[17]:draw(0, 0, 255, 255)  -- a.m. LED = blue
    else
        uhr[17]:draw(255, 145, 0, 255)-- p.m. LED = orange
    end
    
    if h >= 12 then  h = h-12 end
    
    if h == 0 then                    -- shows the hours
        uhr[6]:draw(255,0,0,255)
        for q=1,5 do
            uhr[q]:draw(30,30,30,255)
            end
    else
        for q=1,5 do
            uhr[6]:draw(30,30,30,255)
            w = uhr[q].zeit
            if w <= h then
                h = h-w
                uhr[q]:draw(255,0,0,255)
            else
                uhr[q]:draw(30,30,30,255)
            end
        end
    end
    
    if m == 0 then                    -- shows the minutes
        uhr[16]:draw(255,0,0,255)
        for q=7,15 do
            uhr[q]:draw(30,30,30,255)
        end
    else
        for q=7,15 do
            uhr[16]:draw(30,30,30,255)
            w = uhr[q].zeit
            if w <= m then
                m = m-w
                uhr[q]:draw(255,0,0,255)
            else
                uhr[q]:draw(30,30,30,255)
            end
        end
    end
    
    t = (90-6*s)*math.pi/180        -- let the seconds circle around the LEDs
    translate(xu,yu)
    noStroke()
    fill(255, 0, 0, 255)
    ellipse(math.cos(t)*120, math.sin(t)*120, 10, 10)
end

function touched(touch)
    if touch.state == BEGAN then
        if zeit == false then
            zeit = true
        else
            zeit = false
        end
    end
end



--# Led
Led = class()

function Led:init(x,y,z)
    self.x = x    -- x-position
    self.y = y    -- y-position
    self.zeit = z -- sets the LED value
end

function Led:draw(r,g,b,a)
    -- Codea does not automatically call this 
    noStroke()
    fill(r,g,b,a)
    ellipse(self.x, self.y, 20, 20)
end

function Led:touched(touch)
    -- Codea does not automatically call this method
end

Omg Chaos… Can Someone help me to post the code

Read the FAQ on forum formatting. I’ve fixed the post for now.

Thanks for your help Andrew :wink:

Here is the link for extended Description how to read the time.

http://www.tokyoflash.com/pages/000218/000218.pdf

As you can see, it wasn’t my idea to create this kind of watch but i had a lot of fun Creating this watch in codea.

@Nibla Thanks for the extended description. I couldn’t figure out how to read the time. I think I’ll stick with my analog watch.

@dave1707 Yea its really confusing the first time … Sorry for that… But in the end it is simple to read the time.