Thanks for fixing the post, now I know how to make it work.
Original code worked fine but when I added proportional minutes to the hour it screwed up. Had to go to a meter face of 0-12 instead of 1-12. Clock currently shows 12:42. I'll eventually modify the face to have a 12 where the 0 is as well.
(note the permanent perf board sitting in front, waiting for trim pots before assembly)
I found that adding the minute proportion to the hour is all that is needed, you can't really see the seconds added to minute, plus technically that requires rescaling as well. Also, thanks Electroguard for the IP string manipulation for the broadcast address much more elegant than my original.
One last note, DST must be handled locally, not sure if the timesetup() function is supposed to do that or not since there is a DST setting. I may add a button on the clock to select DST by the user, not going to try to calculate in code, who knows, maybe we'll just stick with DST all year long!
Here's the modified code.
Code: Select all'******************************************************
'* Analog Panel Meter Clock *
'* by Russ McIntire, 8/27/16 *
'* D0 = Hours *
'* D1 = Minutes *
'* D2 = Seconds *
'* *
'* To do: HTML setup screen to select DST, TZ, SSID *
'******************************************************
timesetup(-4,1) 'Need to figure out what is wrong with DST
delay 5000
udpbegin 5001
hour = 0
min = 0
sec = 0
M = " "
udptimer = 0
hourpwm = 0
minpwm = 0
secpwm = 0
'Determine broadcast address
let localIP = ip()
pos = instrrev(localIP,".")
netIP = left(localIP,pos)
nodeIP = mid(localIP,pos+1)
let broadcastaddr = netIP & "255"
timer 1000, [updatetime]
wait
end
[updatetime]
'Get time values from NTP server
hour = val(time("hour"))
min = val(time("min"))
sec = val(time("sec"))
'Set 12 hour time and determine AM/PM
if hour > 12 then
hour = hour - 12
M = "PM"
else
if hour = 0 then
hour = 12
endif
M = "AM"
endif
'Panel PWM calculation
'hourpwm = 85.33 * (hour) 'divide 1024/12
hourpwm = (85.33 * hour) + (1.55 * min) 'divide 1024/12 add proportion of minutes (~1.5/min)
minpwm = 17.36 * min 'divide 1024/59
'minpwm = (17.36 * min) + (.29 * sec) '- don't recommend - divide 1024/59 add proportion of seconds (.29/sec)
secpwm = 17.36 * sec 'divide 1024/59
'Panel output
io(pwo,d0,hourpwm)
io(pwo,d1,minpwm)
io(pwo,d2,secpwm)
'Daily NTP refresh at 2:00 AM
if ((hour=2) and (min=0) and (sec>0) and (sec<5) and (M="AM")) then
timesetup(-4,1) 'Need to figure out what is wrong with DST
delay 5000
endif
'Send UDP broadcast message out for current time every 30 seconds
udptimer = udptimer + 1
if udptimer > 30 then
ct = str(hour)&":"&time("min:sec")&" "&M
udpwrite broadcastaddr, 5001, ct
udptimer = 0
endif
wait