Showing posts with label oh_no_more_clocks. Show all posts
Showing posts with label oh_no_more_clocks. Show all posts

Tuesday, 23 June 2020

M5Atom Binary Clock

Finally received M5's latest tiny ESP32 module (it was way delayed due to the virus). Tried some demos, the LedDisplay demo doesn't work unless you change as per this advice:

"change in LED_DisPlay.ccp line 103
// xSemaphoreTake(_xSemaphore, portMAX_DELAY);
xSemaphoreTake(_xSemaphore, 100);" 


from ririfonfon on the M5Stack/M5Atom forum.

And then, a binary clock based on SimpleTime from the ESP32 examples, gets the time from NTP and displays on the M5Atom's leds.

The M5Atom set up uses the FastLed library but for some reason the colours work strange if you use the defined colour constants eg, if you use "CRGB::Red" the led lights green and vice-versa .

The fifth column is the seconds/2 in binary. The hours and minutes are BCD.

It does need a daylight savings check added.

the code is here

Thursday, 1 February 2018

ESP Basic analog clock on TFT display

Reusing arduino analog clock code from years ago on ESP Basic.
Yeah I know... BASIC right ?, but honestly as a quick way of getting something happening on the ESP it is one of the simplest ways available.

time.setup(+11,0)
tft.setup(16,4,3)
tft.text.color(tft.rgb(55,155,67))
tft.text.font(1)

WHITE=tft.rgb(255,255,255)

gosub [showtime]

timercb 60000 , [showtime]
wait

[showtime]
tft.cls()
tvx = 320/2
tvy = 240/2
tvradius = 240/2 - 2
'clock face
tft.circle(tvx,tvy,tvradius,WHITE)

gosub [ticks]

minute = time("minute")
hour=time("hour")
second=time("second")

'angle = second * 6
'Convert degrees to radians

'angle = (angle/57.29577951)
'x3 = (tvx+(sin(angle)*(tvradius-6)))
'y3 = (tvy-(cos(angle)*(tvradius-6)))
'tft.line(tvx,tvy,x3,y3,WHITE)

angle = minute * 6
angle = (angle/57.29577951)      'Convert degrees to radians
x3 = (tvx+(sin(angle)*(tvradius-11)))
y3 = (tvy-(cos(angle)*(tvradius-11)))
tft.line(tvx,tvy,x3,y3,WHITE)

angle = hour * 30 + int((minute / 12) * 6 ) 
angle = (angle/57.29577951)     'Convert degrees to radians
x3 = (tvx+(sin(angle)*(tvradius-40)))
y3 = (tvy-(cos(angle)*(tvradius-40)))
tft.line(tvx,tvy,x3,y3,WHITE)
return

[ticks]
'hour ticks
  z = 0
  n = 12
  do 
 'Begin at 0 and stop at 360
  angle = z
  angle=(angle/57.29577951)      'Convert degrees to radians
  x2=(tvx+(sin(angle)*tvradius))
  y2=(tvy-(cos(angle)*tvradius))
  x3=(tvx+(sin(angle)*(tvradius-5)))
  y3=(tvy-(cos(angle)*(tvradius-5)))
 
  tft.line(x2,y2,x3,y3,WHITE)
  tft.text.cursor(x3,y3)
  tft.print( str(n) )
  if n == 12 then n = 0
  n = n + 1 
  z = z + 30
  loop while z < 360
  return