polemixingrp204013nov2026 — Xiao Rp2040 simulation

An interactive Xiao Rp2040 circuit simulation you can run free in your browser on Velxio, by bwei.

Components

Sketch code

//#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Fonts/FreeMonoBold12pt7b.h>
#include <hardware/pwm.h>
#include <hardware/clocks.h>
#include "LUT.h"
#define SCREEN_WIDTH  128
#define SCREEN_HEIGHT 64
#define OLED_RESET    -1
#define OLED_ADDRESS  0x3C

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
//PIN DEF ENTREES ANALOG
    #define PIN_CUTOFF    26 // ADC0 (Potentiometer 1)
    #define PIN_RESONANCE 27 // ADC1 (Potentiometer 2)
//PIN DEF ENCODER
    #define PIN_ENCODER_A 2  // Quadrature Encoder A
    #define PIN_ENCODER_B 3  // Quadrature Encoder B
    #define ENCODER_BTN_PIN 4   // D9 - Encoder Click Switch

    volatile int encoder_direction = 0;       // 1 for CW, -1 for CCW, 0 for idle/no change

//GESTION LFO
    // Pin definition for PWM output
    #define PIN_LFO_PWM     0
    // LFO & Performance Tuning Settings
    //LUTsize=256->SAMPLErate=200Hz>5msinterval; LUTsize=1024->SAMPLErate=1000Hz>1ms interval
    #define SAMPLE_RATE_HZ  1000                  // 200 Hz update rate (5ms interval) - low CPU impact
    #define LFO_UPDATE_INTERVAL_US (1000000 / SAMPLE_RATE_HZ)
    #define TABLE_SIZE      1024                  // Sine wave lookup table resolution

   
    
    // LFO State Variables
    volatile float lfoFrequency = 1.0f;          // Default frequency: 1 Hz
    volatile uint32_t phaseAccumulator = 0;      
    uint32_t phaseIncrement = 0;                 

    // Timing tracker for non-blocking 200Hz loop
    uint32_t lastMicros = 0;

    // LFO type definitions
        typedef enum {
            SINE = 0,
            TRI,
            SQUARE,
            SAW,
            RAMP,
            DECAY
        } LFOType;
        // Shared variable for the program to read
        LFOType current_LFO_type = SINE;
    //----------------------------------------------------------------------

//GESTION Menu Selection Classification
        const uint8_t nbTOTAL_Menu = 3;
        uint8_t current_Menu_Selected = 0; //0=PoleMix1 ; 1=PoleMix2; 2=LFO
//GESTION MODE de FILTRE
        // Filter Shape Classification
        enum FilterShape {
            SHAPE_LOWPASS,
            SHAPE_HIGHPASS,
            SHAPE_BANDPASS,
            SHAPE_NOTCH,
            SHAPE_ALLPASS,
            SHAPE_HP_LP,
            SHAPE_ResNOTCH,
            SHAPE_NOTCHRes,
            SHAPE_LP_NOTCH
        };

        struct FilterMode {
            const char* name;
            FilterShape shape;
            uint8_t pole_beforeCutoff; // 1 to 4 poles (determines slope steepness)
            uint8_t pole_afterCutoff;
        };

        // Oberheim Matrix-12 / Xpander Inspired Response Types
        const FilterMode FILTER_MODES[] = {
            {"LP1",   SHAPE_LOWPASS,  1,1}, //1-Pole Lowpass
            {"LP2",   SHAPE_LOWPASS,  2,2},//2-Pole Lowpass
            {"LP3",   SHAPE_LOWPASS,  3,3},//3-Pole Lowpass
            {"LP4",   SHAPE_LOWPASS,  4,4},
            {"HP1",  SHAPE_H

More projects by bwei