# Time server connected keyboard device for Raspberry Pi Pico W # Set the time for MachiKania by connecting to MachiKania via USB # Copy the following library files in "CIRCUITPY/lib" directory # adafruit_hid directory # adafruit_datetime.mpy # adafruit_ntp.mpy # Notice: # Do not use settings.toml in the CIRCUITPY directory as it will # slow down startup and will not be recognized as a keyboard. import usb_hid from adafruit_hid.keyboard import Keyboard from adafruit_hid.keycode import Keycode from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS import time from adafruit_datetime import datetime import rtc import wifi import socketpool import adafruit_ntp keyboard = Keyboard(usb_hid.devices) layout = KeyboardLayoutUS(keyboard) # Change the following SSID and PASSWORD wifi.radio.connect("SSID", "PASSWORD") pool = socketpool.SocketPool(wifi.radio) ntp = adafruit_ntp.NTP(pool, tz_offset=9, server="ntp.nict.jp") rtc.RTC().datetime = ntp.datetime t = datetime.now().isoformat() # Replace keycodes for Japanese keyboard # Comment out next line for US keyboard t = t.replace(":","'") # Replace '@' to '\"' for US keyboard layout.write("settime @"+t+"@", delay=0.05) keyboard.send(Keycode.F4) time.sleep(1) keyboard.send(Keycode.A) # Hit any key #Shift + F1 execute "NEW PROGRAM" keyboard.press(Keycode.LEFT_SHIFT) keyboard.send(Keycode.F1) keyboard.release(Keycode.LEFT_SHIFT) keyboard.send(Keycode.ESCAPE)