예제 #1
0
# Rotating 3D Wireframe Cube using MicroPython on Badger2040
# Derived from Martin Fitzpatrick's example here https://www.mfitzp.com/creating-a-3d-rotating-cube-with-micropython-and-oled-display/

import math
import badger2040

badger = badger2040.Badger2040()
badger.update_speed(3)


class Point3D:
    def __init__(self, x=0, y=0, z=0):
        self.x, self.y, self.z = x, y, z

    def rotateX(self, angle):
        """ Rotates this point around the X axis the given number of degrees. """
        rad = angle * math.pi / 180
        cosa = math.cos(rad)
        sina = math.sin(rad)
        y = self.y * cosa - self.z * sina
        z = self.y * sina + self.z * cosa
        return Point3D(self.x, y, z)

    def rotateY(self, angle):
        """ Rotates this point around the Y axis the given number of degrees. """
        rad = angle * math.pi / 180
        cosa = math.cos(rad)
        sina = math.sin(rad)
        z = self.z * cosa - self.x * sina
        x = self.z * sina + self.x * cosa
        return Point3D(x, self.y, z)
예제 #2
0
    if tick:
        draw_tick(x, y, size, size, thickness, 2 + border)


# ------------------------------
#        Program setup
# ------------------------------

# Global variables
update = True
needs_save = False
current_item = 0
items_per_page = 0

# Create a new Badger and set it to update FAST
display = badger2040.Badger2040()
display.update_speed(badger2040.UPDATE_FAST)

# Set up the buttons
button_a = machine.Pin(badger2040.BUTTON_A, machine.Pin.IN,
                       machine.Pin.PULL_DOWN)
button_b = machine.Pin(badger2040.BUTTON_B, machine.Pin.IN,
                       machine.Pin.PULL_DOWN)
button_c = machine.Pin(badger2040.BUTTON_C, machine.Pin.IN,
                       machine.Pin.PULL_DOWN)
button_up = machine.Pin(badger2040.BUTTON_UP, machine.Pin.IN,
                        machine.Pin.PULL_DOWN)
button_down = machine.Pin(badger2040.BUTTON_DOWN, machine.Pin.IN,
                          machine.Pin.PULL_DOWN)

# Find out what the longest item is
예제 #3
0
import time
import machine
import badger2040

rtc = machine.RTC()
screen = badger2040.Badger2040()
screen.update_speed(badger2040.UPDATE_TURBO)
screen.font("gothic")

cursors = ["year", "month", "day", "hour", "minute"]
set_clock = False
cursor = 0
last = 0

# Set up the buttons
button_down = machine.Pin(badger2040.BUTTON_DOWN, machine.Pin.IN,
                          machine.Pin.PULL_DOWN)
button_up = machine.Pin(badger2040.BUTTON_UP, machine.Pin.IN,
                        machine.Pin.PULL_DOWN)

button_a = machine.Pin(badger2040.BUTTON_A, machine.Pin.IN,
                       machine.Pin.PULL_DOWN)
button_b = machine.Pin(badger2040.BUTTON_B, machine.Pin.IN,
                       machine.Pin.PULL_DOWN)
button_c = machine.Pin(badger2040.BUTTON_C, machine.Pin.IN,
                       machine.Pin.PULL_DOWN)


def days_in_month(month, year):
    if month == 2 and ((year % 4 == 0 and year % 100 != 0) or year % 400 == 0):
        return 29