I can help you create a darkroom timer using the M5Stack Cardputer and a relay unit. This will allow you to control an enlarger or other darkroom equipment. Here's a basic implementation:
#include <M5Cardputer.h>
// Pin definitions
const int RELAY_PIN = 38; // Adjust this according to your relay connection
const int DEFAULT_TIME = 10; // Default time in seconds
// Global variables
int timerSeconds = DEFAULT_TIME;
bool timerRunning = false;
unsigned long startTime = 0;
void setup() {
M5Cardputer.begin();
M5Cardputer.Display.setRotation(1);
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN, LOW); // Ensure relay starts OFF
displayMenu();
}
void displayMenu() {
M5Cardputer.Display.clear();
M5Cardputer.Display.setCursor(0, 0);
M5Cardputer.Display.printf("Darkroom Timer\n");
M5Cardputer.Display.printf("Time: %d sec\n", timerSeconds);
M5Cardputer.Display.printf("\nControls:\n");
M5Cardputer.Display.printf("↑/↓: Adjust time\n");
M5Cardputer.Display.printf("ENTER: Start/Stop\n");
M5Cardputer.Display.printf("ESC: Reset\n");
}
void loop() {
M5Cardputer.update();
if (M5Cardputer.Keyboard.isPressed()) {
Keyboard_Class::KeysState key = M5Cardputer.Keyboard.keysState();
if (!timerRunning) {
// Adjust time when timer is not running
if (key.key == '=') { // Up arrow
timerSeconds++;
displayMenu();
} else if (key.key == '-') { // Down arrow
if (timerSeconds > 1) {
timerSeconds--;
displayMenu();
}
} else if (key.key == KEY_ENTER) { // Start timer
timerRunning = true;
startTime = millis();
digitalWrite(RELAY_PIN, HIGH); // Turn ON relay
}
}
if (key.key == KEY_ESC) { // Reset
timerRunning = false;
timerSeconds = DEFAULT_TIME;
digitalWrite(RELAY_PIN, LOW); // Turn OFF relay
displayMenu();
}
}
if (timerRunning) {
unsigned long elapsed = (millis() - startTime) / 1000;
int remaining = timerSeconds - elapsed;
M5Cardputer.Display.clear();
M5Cardputer.Display.setCursor(0, 0);
M5Cardputer.Display.printf("Time remaining:\n%d sec", remaining);
if (remaining <= 0) {
timerRunning = false;
digitalWrite(RELAY_PIN, LOW); // Turn OFF relay
M5Cardputer.Display.clear();
M5Cardputer.Display.printf("Done!\n");
delay(1000);
displayMenu();
}
}
}
To use this with your setup:
-
Hardware Setup:
- Connect the relay unit to the Cardputer
- Connect your enlarger or other equipment to the relay
- Make sure to verify the correct pin number for your relay connection
-
Features:
- Use up/down arrows to adjust exposure time
- Press ENTER to start the timer
- Press ESC to reset
- The relay will turn ON when the timer starts and OFF when it completes
- Display shows remaining time during countdown
-
Customization options you might want to add:
- Add a beeper for end-of-exposure notification
- Save preferred times to memory
- Add multiple preset times
- Add f-stop timing calculations
Would you like me to modify any part of this code or add additional features for your specific needs?