Arnov Sharma
Published © MIT

Mega Man's Mega Buster

Full-Size Working Replica of Mega Man's Mega Buster

BeginnerFull instructions provided1 hour126
Mega Man's Mega Buster

Things used in this project

Hardware components

Raspberry Pi Pico 2
Raspberry Pi Pico 2
×1
NextPCB  Custom PCB Board
NextPCB Custom PCB 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

STEP FILE

Schematics

Circuit SCH Main board

Side LED Power PCB SCH

Front Blaster SCH

Code

code

C/C++
#include <Adafruit_NeoPixel.h>

#define AUDIO_PIN    26
#define BUTTON_PIN   15
#define BLAST_LED    17

#define PIXEL_PIN    16
#define PIXEL_COUNT  6

#define MAX_CHARGE_TIME 3000
#define MAX_AMMO        6
#define COOLDOWN_TIME   10000

// Software volume control (percent)
#define AUDIO_VOLUME   60   // 100 = max, 60 = mid

// Front blast LED brightness cap (70%)
#define BLAST_LED_MAX  180  // ~70% of 255

// WS2812B colors
#define AMMO_YELLOW   strip.Color(255, 160, 0)
#define OVERHEAT_RED  strip.Color(255, 0, 0)

Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);

int ammo = MAX_AMMO;
bool coolingDown = false;

void setup() {
  pinMode(AUDIO_PIN, OUTPUT);
  pinMode(BUTTON_PIN, INPUT_PULLUP);
  pinMode(BLAST_LED, OUTPUT);

  strip.begin();
  strip.setBrightness(180);
  strip.show();

  randomSeed(analogRead(0));
  refillAmmo();
}

void loop() {
  if (coolingDown) return;

  if (digitalRead(BUTTON_PIN) == LOW && ammo > 0) {
    chargeAndFire();
    ammo--;
    updateAmmoBar();

    if (ammo == 0) {
      startCooldown();
    }
  }
}

// ================= CHARGE =================

void chargeAndFire() {
  unsigned long startTime = millis();
  unsigned long heldTime  = 0;

  while (digitalRead(BUTTON_PIN) == LOW) {
    heldTime = millis() - startTime;
    if (heldTime > MAX_CHARGE_TIME) heldTime = MAX_CHARGE_TIME;

    int chargeFreq = map(heldTime, 0, MAX_CHARGE_TIME, 300, 900);
    tone(AUDIO_PIN, chargeFreq);
    delay(15);
  }

  noTone(AUDIO_PIN);
  fireBlast(heldTime);
}

// ================= BLAST =================

void fireBlast(unsigned long blastTime) {
  if (blastTime < 120) blastTime = 120;

  int startFreq = map(blastTime, 0, MAX_CHARGE_TIME, 900, 2400);
  int step      = map(blastTime, 0, MAX_CHARGE_TIME, 25, 70);

  unsigned long start = millis();
  unsigned long gate  = 0;

  while (millis() - start < blastTime) {
    for (int f = startFreq; f > 300; f -= step) {

      gate++;
      if ((gate % 100) < AUDIO_VOLUME) {
        tone(AUDIO_PIN, f);
      } else {
        noTone(AUDIO_PIN);
      }

      // Front LED aggressive flicker, capped at 70%
      for (int i = 0; i < 3; i++) {
        analogWrite(BLAST_LED, random(60, BLAST_LED_MAX));
        delayMicroseconds(400);
      }

      delay(2);
    }
  }

  noTone(AUDIO_PIN);

  // Front LED cooldown (fade from 70% to off)
  for (int i = BLAST_LED_MAX; i >= 0; i--) {
    analogWrite(BLAST_LED, i);
    delay(5);
  }
}

// ================= AMMO BAR =================

void refillAmmo() {
  ammo = MAX_AMMO;
  for (int i = 0; i < PIXEL_COUNT; i++) {
    strip.setPixelColor(i, AMMO_YELLOW);
  }
  strip.show();
}

void updateAmmoBar() {
  for (int i = 0; i < PIXEL_COUNT; i++) {
    if (i < ammo) {
      strip.setPixelColor(i, AMMO_YELLOW);
    } else {
      strip.setPixelColor(i, 0);
    }
  }
  strip.show();
}

// ================= COOLDOWN =================

void startCooldown() {
  coolingDown = true;
  unsigned long start = millis();

  while (millis() - start < COOLDOWN_TIME) {
    for (int i = 0; i < PIXEL_COUNT; i++) {
      strip.setPixelColor(i, OVERHEAT_RED);
    }
    strip.show();
    analogWrite(BLAST_LED, BLAST_LED_MAX);
    delay(300);

    strip.clear();
    strip.show();
    analogWrite(BLAST_LED, 0);
    delay(300);
  }

  refillAmmo();
  coolingDown = false;
}

Credits

Arnov Sharma
372 projects • 387 followers
I'm Arnov. I build, design, and experiment with tech—3D printing, PCB design, and retro consoles are my jam.

Comments