Arnov Sharma
Published © MIT

Pocket Synth V1

Made a Small Handy Mini Synth powered by XIAO ESP32 S3 Microcontroller

BeginnerFull instructions provided1 hour216
Pocket Synth V1

Things used in this project

Hardware components

Seeed Studio XIAO esp32 C6
×1
Seeeduino XIAO Expansion board
Seeed Studio Seeeduino XIAO Expansion board
×1

Software apps and online services

Fusion
Autodesk Fusion
Arduino IDE
Arduino IDE

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)

Story

Read more

Custom parts and enclosures

Fusion360File

STEP FILE

Schematics

SCH

Code

code

C/C++
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define SSD1306_I2C_ADDRESS 0x3C

// Declaration for SSD1306 display connected using I2C (default address 0x3C)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT);

const int buttonPins[] = {0, 1, 2, 6, 7, 8, 9, 10}; // Button pins
const int buttonCount = 8;
const int speakerPin = D3; // Speaker pin

// Define frequencies for each button
const int frequencies[8] = {523, 587, 659, 698, 784, 880, 988, 1047}; // C5 to C6

void setup() {
  // Initialize the display
  if (!display.begin(SSD1306_I2C_ADDRESS, 0x3C)) {
    for (;;);
  }
  display.display();
  delay(2000); // Pause for 2 seconds
  display.clearDisplay();
  display.setTextSize(4);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(5, 20);
  display.println(F("SYNTH"));
  display.display();

  // Initialize button pins as input with pull-up resistors
  for (int i = 0; i < buttonCount; i++) {
    pinMode(buttonPins[i], INPUT_PULLUP);
  }
  pinMode(speakerPin, OUTPUT);
  noTone(speakerPin); // Ensure the speaker is off initially
}

void loop() {
  bool buttonPressed = false;
  for (int i = 0; i < buttonCount; i++) {
    int buttonState = digitalRead(buttonPins[i]);

    if (buttonState == LOW) { // Button pressed
      tone(speakerPin, frequencies[i]); // Play tone

      // Flash the display with button press info
      display.clearDisplay();
      display.setTextSize(2);
      display.setTextColor(SSD1306_WHITE);
      display.setCursor(0, 0);
      display.print("Button ");
      display.print(i + 1); // Display button index (1-based)
      display.println(" pressed");
      display.display();

      buttonPressed = true;
    }
  }

  // Turn off the speaker if no button is pressed
  if (!buttonPressed) {
    noTone(speakerPin);
  } else {
    delay(100); // Hold the display for a short period
    display.clearDisplay();
    display.display(); // Clear the display after a button press
  }

  delay(100); // Debounce delay
}

Credits

Arnov Sharma
315 projects • 314 followers
Just your average MAKER

Comments