Wifi Clock Micropython Class Reference

Carlo Supina

March 5, 2020

0 Comment

Class WifiClock

The WifiClock class is built around the Wifi Clock kit. View and download the Wifi Clock code from our github.

Example Usage

Set time manually.

from wifi_clock_starter import WifiClock

wificlock = WifiClock()
wificlock.set_time(15, 47, 32) # Set time to 15:47:32 (3:47 PM)
wificlock.start_clock24()

Set time using a time server.

from wifi_clock_starter import WifiClock

wificlock = WifiClock()
wificlock.connect_to_wifi('ssid', 'password')
wificlock.set_time_ntp(-5) # Set time to UTC -5
wificlock.start_clock24()

Constructor

class WifiClock()

Creates a WifiClock instance.

External Methods

WifiClock.connect_to_wifi(ssid, password)

Connects to a wifi access point.

  • ssid is a string and the name of a wifi access point to connect to.
  • password is a string and the name of the password for the wifi access point.

WifiClock.set_time(hour, minute, second)

Sets the hours, minutes and seconds to the RTC.

  • hour is a positive integer and the hour to set the clock to.
  • minute is a positive integer and the minutes to set the clock to.
  • second is a positive integer and the seconds to set the clock to.

WifiClock.set_time_ntp(utc_offset)

Sets the hours, minutes and seconds to the RTC using a time server.

  • utc_offset is an integer and the offset of a time from utc time.

WifiClock.start_clock24()

Starts the clock, updating the displays every second.

WifiClock.display_brightness(value)

Sets the brightness of the six 7-segment displays.

  • value is an integer and a number between 0 and 15 representing the desired brightness level.
    • 0 is the dimmest setting.
    • 15 is the brightest setting.

WifiClock.display_clear()

Turns all of the 7-segment displays completely off and sets the current number to None.

WifiClock.write_num(value, [dp=0b000000])

Writes a decimal number to the displays.

  • value is an integer number between -99999 and 999999.
  • dp is an optional binary value between 000000 and 111111 which respectively represents which displays to turn on the decimal point.

WifiClock.write_hex(value)

Writes a hexadecimal number to the displays.

  • value is a hexadecimal integer between 0x000000 and 0xFFFFFF.

WifiClock.toggle_led(led)

Toggles an LED on and off.

  • led is a machine.Pin assigned to an LED output.

WifiClock.increment_num([hex=False])

Increments the number written on the displays by 1.

  • hex is a bool that when set to True increments and displays the value in hexadecimal.

WifiClock.decrement_num([hex=False])

Decrements the number written on the displays by 1. If

  • hex is a bool that when set to True increments and displays the value in hexadecimal.

WifiClock.mode_button_callback(pin)

Function called when the Mode button is pressed.

  • pin is the pin of the interrupt.

WifiClock.incr_button_callback(pin)

Function called when the Incr button is pressed.

  • pin is the pin of the interrupt.

WifiClock.decr_button_callback(pin)

Function called when the Decr button is pressed.

  • pin is the pin of the interrupt.

WifiClock.clock_timer_callback(tim)

Callback function used to update the clock time from RTC.

  • tim is the Timer of the interrupt.

WifiClock.timer_callback(tim)

Callback function to be used for the Wifi Clock's timer.

  • tim is the Timer of the interrupt.

Internal Methods

WifiClock._update_clock24()

Updates the display from the RTC.

WifiClock._register(command, data)

Writes data to MAX7219 using a command.

  • command is an integer and a MAX7219 command.
  • data is an integer and the data to be sent.

WifiClock._debounce(button)

Checks for consecutive reads from a button and returns 1 or 0 depending on weather it passes.

  • button is a Pin and a button to sample.

External Variables

WifiClock.red_led

An output Pin representing the red LED on the Wifi Clock.

WifiClock.green_led

An output Pin representing the green LED on the Wifi Clock.

WifiClock.blue_led

An output Pin representing the blue LED on the Wifi Clock.

WifiClock.mode_button

An input Pin representing the Mode button on the Wifi Clock.

WifiClock.incr_button

An input Pin representing the Incr button on the Wifi Clock.

WifiClock.decr_button

An input Pin representing the Decr button on the Wifi Clock.

WifiClock.current_num

An integer that is the current number displays.

WifiClock.current_dp

A binary integer that represents the current decimal point arrangement on the displays.

WifiClock.sta_if

A WLAN instance setup with a station interface for the Wifi Clock.

WifiClock.rtc

A RTC instance for the Wifi Clock.

WifiClock.timer

A Timer instance for the Wifi Clock.

Internal Variables

WifiClock._spi

A SPI bus for the Wifi Clock.

WifiClock._cs

A Pin that is the CS for the MAX7219 chip.

Comments (0)

Page 1 of 0

Go back to top

You need to be logged in to comment