Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Examples

Arduino/C++ Examples

The following examples demonstrate various features of this development board.

pwm

// LED Fade + PWM duty print on Serial Monitor (simple version)

int LED_PIN = 9;      // PWM pin
int STEP    = 5;      // Brightness increment per step

void setup() {
  pinMode(LED_PIN, OUTPUT);
  Serial.begin(115200);          // Match this baud rate in the Serial Monitor
  delay(200);                    // Small pause to avoid garbage at start
  Serial.println("Starting fade...");
}

void loop() {
  // Fade up
  for (int duty = 0; duty <= 255; duty += STEP) {
    analogWrite(LED_PIN, duty);
    Serial.print("Duty: ");
    Serial.println(duty);
    delay(500);
  }

See complete code on GitHub

Python Examples

The following Python examples demonstrate usage with the sensor.

pwm

# LED Fade + PWM duty print 

from machine import Pin, PWM
from time import sleep_ms

LED_PIN = 2          # Change to your LED pin
STEP    = 512        # Brightness increment per step (0..65535)
DELAY_MS = 500

pwm = PWM(Pin(LED_PIN), freq=1000)  # 1 kHz

MAX_DUTY = 65535

def print_duty(d):
    pct = d * 100.0 / MAX_DUTY
    print("Duty:", d, f"({pct:0.1f}%)")

# Fade loop
while True:
    # Fade up

See complete code on GitHub