Arnov Sharma
Published © MIT

PulpPro

Made a Paper Maché Machine from scratch using 3D-printed parts and a custom circuit.

BeginnerFull instructions provided1 hour537
PulpPro

Things used in this project

Hardware components

XIAO ESP32C3
Seeed Studio XIAO ESP32C3
×1

Software apps and online services

Fusion
Autodesk Fusion
Arduino IDE
Arduino IDE

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)
Seeed Studio Fusion PCB/PCBA
Seeed Studio Fusion PCB/PCBA

Story

Read more

Custom parts and enclosures

STEP FILE

Schematics

SCH

Code

code

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

// OLED display dimensions
#define OLED_WIDTH 128
#define OLED_HEIGHT 64
#define OLED_ADDR 0x3C

Adafruit_SSD1306 display(OLED_WIDTH, OLED_HEIGHT);

// Define pins
#define MOTOR_PIN D10
#define START_STOP_BUTTON_PIN D1
#define ADD_TIME_BUTTON_PIN D6
#define SUBTRACT_TIME_BUTTON_PIN D3

// Motor timer variables
unsigned long motorRunTime = 60000; // Default 1 minute in milliseconds
unsigned long timeAdjustment = 10000; // 10 seconds in milliseconds
bool motorRunning = false; // Motor state
unsigned long motorStartTime;

// Button state tracking
bool lastStartStopButtonState = HIGH;
bool buttonPressed = false;
bool lastAddTimeButtonState = HIGH;
bool lastSubtractTimeButtonState = HIGH;

void setup() {
  // Motor and button pins setup
  pinMode(MOTOR_PIN, OUTPUT);
  digitalWrite(MOTOR_PIN, LOW); // Ensure motor is off at startup
  pinMode(START_STOP_BUTTON_PIN, INPUT_PULLUP);
  pinMode(ADD_TIME_BUTTON_PIN, INPUT_PULLUP);
  pinMode(SUBTRACT_TIME_BUTTON_PIN, INPUT_PULLUP);

  // Serial communication setup
  Serial.begin(115200);

  // OLED display setup using your example method
  if (!display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR)) { // Initialize display
    Serial.println(F("SSD1306 allocation failed"));
    for (;;); // Halt execution if OLED fails
  }

  // Initial display output
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(10, 20); // Adjust cursor for centering the single-line text
  display.println(F("Paper Mache Maker"));
  display.display();
  delay(2000); // Hold the welcome screen for 2 seconds
  updateDisplay(); // Display the initial timer value
}

// Function to update the OLED display with the current time
void updateDisplay() {
  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(5, 20); // Moved closer to the left
  display.print("Time: ");
  display.print(motorRunTime / 1000); // Time in seconds
  display.print("s");
  display.display();
}

void loop() {
  // Handle Start/Stop button
  bool currentStartStopButtonState = digitalRead(START_STOP_BUTTON_PIN);
  if (currentStartStopButtonState == LOW && lastStartStopButtonState == HIGH) {
    buttonPressed = true; // Button pressed
  }
  if (currentStartStopButtonState == HIGH && lastStartStopButtonState == LOW && buttonPressed) {
    motorRunning = !motorRunning; // Toggle motor state
    if (motorRunning) {
      motorStartTime = millis();
      digitalWrite(MOTOR_PIN, HIGH); // Turn on motor
      Serial.println("Motor started.");
    } else {
      digitalWrite(MOTOR_PIN, LOW); // Turn off motor
      Serial.println("Motor stopped.");
    }
    buttonPressed = false; // Reset the flag
  }
  lastStartStopButtonState = currentStartStopButtonState;

  // Handle Add Time button
  bool currentAddTimeButtonState = digitalRead(ADD_TIME_BUTTON_PIN);
  if (currentAddTimeButtonState == LOW && lastAddTimeButtonState == HIGH) {
    motorRunTime += timeAdjustment;
    updateDisplay(); // Update the time on the display
    delay(50); // Debounce
  }
  lastAddTimeButtonState = currentAddTimeButtonState;

  // Handle Subtract Time button
  bool currentSubtractTimeButtonState = digitalRead(SUBTRACT_TIME_BUTTON_PIN);
  if (currentSubtractTimeButtonState == LOW && lastSubtractTimeButtonState == HIGH) {
    if (motorRunTime > timeAdjustment) {
      motorRunTime -= timeAdjustment;
      updateDisplay(); // Update the time on the display
    } else {
      Serial.println("Cannot reduce time below 0.");
    }
    delay(50); // Debounce
  }
  lastSubtractTimeButtonState = currentSubtractTimeButtonState;

  // Countdown Timer and Motor Off
  if (motorRunning) {
    if (millis() - motorStartTime >= motorRunTime) {
      motorRunning = false;
      digitalWrite(MOTOR_PIN, LOW); // Turn off motor
      Serial.println("Motor stopped automatically after timeout.");
      updateDisplay(); // Reset display after timeout
    } else {
      unsigned long timeLeft = (motorRunTime - (millis() - motorStartTime)) / 1000;
      display.clearDisplay();
      display.setTextSize(2);
      display.setTextColor(WHITE);
      display.setCursor(5, 20); // Timer display moved closer to the left
      display.print("Time: ");
      display.print(timeLeft);
      display.print("s");
      display.display();
    }
  }
}

Credits

Arnov Sharma
338 projects • 343 followers
Just your average MAKER
Contact

Comments

Please log in or sign up to comment.