1/19
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
machine
MicroPython module for direct hardware-level access and peripheral control.
Example:
import machine
machine.Pin
MicroPython class used to configure and control digital input/output pins on a microcontroller.
Example:
from machine import Pin
led = Pin(2, Pin.OUT)
machine.ADC
MicroPython class used to convert continuous analog voltage signals into digital values.
Example:
from machine import ADC, Pin
adc = ADC(Pin(34))
val = adc.read_u16()
machine.PWM
MicroPython class used to generate pulse-width modulated signals with configurable frequency and duty cycle.
Example:
from machine import PWM, Pin
pwm = PWM(Pin(15), freq=1000, duty_u16=32768)
machine.I2C
MicroPython class providing a two-wire serial communication interface for peripherals.
Example:
from machine import I2C, Pin
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
machine.Timer
MicroPython class used to execute periodic or one-shot timed callback functions.
Example:
from machine import Timer
timer = Timer(-1)
timer.init(period=1000, mode=Timer.PERIODIC, callback=lambda t: print("Tick"))
machine.reset()
Function used to perform a software reset of the microcontroller.
Example:
import machine
machine.reset()
machine.freq()
Function used to retrieve or set the CPU clock frequency of the board.
Example:
import machine
current_freq = machine.freq()
machine.I2C
MicroPython class providing a two-wire serial communication interface for peripherals.
Example:
from machine import I2C, Pin
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
machine.Timer
MicroPython class used to execute periodic or one-shot timed callback functions.
Example:
from machine import Timer
timer = Timer(-1)
timer.init(period=1000, mode=Timer.PERIODIC, callback=lambda t: print("Tick"))
machine.reset()
Function used to perform a software reset of the microcontroller.
Example:
import machine
machine.reset()
machine.freq()
Function used to retrieve or set the CPU clock frequency of the board.
Example:
import machine
current_freq = machine.freq()
pin.value()
Method used to read or set the digital state (0 or 1) of a Pin object.
Example:
state = pin.value()
pin.value(1)
pin.on() / pin.off()
Methods used to set a digital output pin to high (1) or low (0).
Example:
led.on()
led.off()
pin.toggle()
Method used to switch the output state of a digital pin from high to low or vice versa.
Example:
led.toggle()
Pin.IN / Pin.OUT
Mode constants used when initializing a Pin object to set it as an input or output pin.
Example:
btn = Pin(14, Pin.IN)
led = Pin(2, Pin.OUT)
Pin.PULL_UP / Pin.PULL_DOWN
Constants used to enable internal pull-up or pull-down resistors on input pins.
Example:
button = Pin(12, Pin.IN, Pin.PULL_UP)
pin.irq()
Method used to configure an interrupt handler (callback) triggered by state changes on an input pin.
Example:
btn.irq(handler=lambda p: print("Pressed!"), trigger=Pin.IRQ_FALLING)
pwm.freq()
Method used to get or set the frequency of a PWM signal in Hertz.
Example:
pwm.freq(2000)
pwm.duty_u16()
Method used to get or set the PWM duty cycle using an unsigned 16-bit integer ranging from 0 to 65535.
Example:
pwm.duty_u16(32768) # 50% duty cycle