Ok, so I gotta apologize right off the hop for the very confusing title. Let me first try to explain the project, then I'll get to my question.
The project is for a hot-wire cutter for styrofoam, not your typical table-top hot-wire cutter that most of you would be familiar with, but a much longer hot-wire that requires two people to use.
I work in cinema in the art department, and many of our projects use giant blocks of styrofoam that are 4' x 4' x 20' long. So if we are doing cuts over the length, my partner is at the other end, often in a loud environment and we might both be crouched behind each end of the styrofoam block. Complicated cuts require marking check-points at the corners of each cut, and yelling out numbers in said loud environment, crouched behind a massive block of styrofoam wasn't working for me. So I decided to make a hot-wire with integrated counters (TM1637 Display) and a pushbutton to increment the count on each handle, so far - so good. Both myself and my partner can increment the count as we reach each checkpoint and we both know where we're at without yelling.
With these long cuts, the wire in the centre of the block tends to be colder than the wire ate the ends. Our technique is for each of us to reach our checkpoint and hold at that point for x seconds while the wire in the middle catches up, then continue the cut. Again this requires communication.
Now I get to my question. I would like to add an adjustable countdown timer to my existing code, once that would detect that my number and my partner's number matched, would display the countdown, then when it reached zero would flash once then return to our incremental number display. This countdown timer should be adjustable, as longer pieces require a longer delay, shorter ones not so much. Say adjustable between 10 seconds, all the way down to 0 - zero however should negate the countdown timer sequence altogether and just show our increments.
I am a complete newbie with this, though I have managed to get the counter code working through lots of cut'n'paste programming. I am reluctant to start fiddling with the modification i am seeking to do though as I really don't want to break the code I have right now and I really have no idea where to start. Any help is greatly appreciated.
The following is the working code that I have so far:
/*
* This is Arduino "Hot-Wire foam cutter checkpoint counter" using a pair of TM1637 seven-segment LED Displays.
* Long pieces of syrofoam require two people to cut the length. This sketch allows for each user to increment the counter
* as they arrive at each check-point marked on the piece, as well as have a visual read-out showing their location as well as their partner's.
*
* The original code is based on "Robojax Touch Counter V3 using TM1637 4 digits LED display"
* Link: https://robojax.com/learn/arduino/?vid=robojax_touch_counter_V3_TM1637
*
*/
//***** beginning of TM1637 Display
#include <Arduino.h>
#include <TM1637Display.h>
// Master Display connection pins (Digital Pins)
#define CLK1 6 // D6
#define DIO1 7 // D7
// Slave Display connection pins (Digital Pins)
#define CLK2 8 // D8
#define DIO2 9 // D9
// The amount of time (in milliseconds) between readings
#define TEST_DELAY 200
TM1637Display display1(CLK1, DIO1); // define display 1 (Master) object
TM1637Display display2(CLK2, DIO2); // define display 2 (Slave) object
uint8_t blank[] = { 0x0, 0x0, 0x0, 0x0 };// data to clear the screen
//***** end of TM1637 Display
const int masterPin = 10; // D10: input pin where Master Increment button is connected
const int slavePin = 11; // D11: input pin where Slave Increment button is connected
const int resetPin = 12; // D12: the input pin for reset button
const int touchDelay = 500; //millisecond delay between each touch
int MasterCount=0; // variable holding the count number
int SlaveCount=0; // Same, for slave.
void setup() {
Serial.begin(9600); // initialize serial monitor with 9600 baud
Serial.println("Hotwire Checkpoint Counter");
pinMode(masterPin,INPUT_PULLUP); // define a pin for master display module
pinMode(slavePin,INPUT_PULLUP); // define a pin for slave display module
pinMode(resetPin,INPUT_PULLUP); // define a pin for reset button
display1.setBrightness(0x0f); // set brightness of display 1
display2.setBrightness(0x0f); // set brightness of display 2
uint8_t data8888[] = { 0xff, 0xff, 0xff, 0xff }; // show all segments.
display1.setSegments(data8888); // display 8888 on display1 for test.
display2.setSegments(data8888); // display 8888 on display2 for test.
delay(3000); // 3 second 8888 display at start-up.
// display1.setSegments(blank); // clear the Master screen from previous values.
// display2.setSegments(blank); // clear the Slave screen from previous values.
// Display "00:00" on both displays
display1.showNumberDecEx(MasterCount, 0b01000000, true, 2, 0); // display Master count and colon on first part of Master display.
display1.showNumberDec(SlaveCount, true, 2,2); // display Slave count on second part of Master display.
display2.showNumberDecEx(SlaveCount, 0b01000000, true, 2,0); // display Slave count and colon on first part of Slave display.
display2.showNumberDec(MasterCount, true, 2,2); // display Master count on second part of Slave display.
}
void loop() {
int masterValue = digitalRead(masterPin); // read masterPin and store it in masterValue
int slaveValue = digitalRead(slavePin); // read slavePin and store it in slaveValue
// if masterValue is LOW
if(masterValue == LOW)
{
MasterCount++; // increment the Master count
// display1.setSegments(blank); // clear Master screen from previous values.
// display2.setSegments(blank); // clear Slave screen from previous values.
display1.showNumberDecEx(MasterCount, 0b01000000, true, 2, 0); // display Master count and colon on first part of Master display.
display1.showNumberDec(SlaveCount, true, 2,2); // display Slave count on second part of Master display.
display2.showNumberDecEx(SlaveCount, 0b01000000, true, 2,0); // display Slave count and colon on first part of Slave display.
display2.showNumberDec(MasterCount, true, 2,2); // display Master count on second part of Slave display.
Serial.print("Master: "); // print the information
Serial.print(MasterCount); // print Master count
Serial.print(" | Slave: ");
Serial.print(SlaveCount); // print Slave count
Serial.println(".");
delay(touchDelay); // touch delay time
}
// if slaveValue is LOW
if(slaveValue == LOW)
{
SlaveCount++; // increment the Slave count
// display1.setSegments(blank); // clear Master screen from previous values.
// display2.setSegments(blank); // clear Slave screen from previous values.
display1.showNumberDecEx(MasterCount, 0b01000000, true, 2, 0); // display Master count and colon on first part of Master display.
display1.showNumberDec(SlaveCount, true, 2,2); // display Slave count on second part of Master display.
display2.showNumberDecEx(SlaveCount, 0b01000000, true, 2,0); // display Slave count and colon on first part of Slave display.
display2.showNumberDec(MasterCount, true, 2,2); // display Master count on second part of Slave display.
Serial.print("Master: "); // print the information
Serial.print(MasterCount); // print count
Serial.print(" | ");
Serial.print("Slave: "); // print the information
Serial.print(SlaveCount); // print count
Serial.println(".");
delay(touchDelay); // touch delay time
}
// if reset switch is pushed
if(digitalRead(resetPin) == LOW)
{
MasterCount=0;// reset master counter;
SlaveCount=0; // reset slave counter;
Serial.println("Counter Reset.");//print the information
// display1.setSegments(blank); // clear the screen from previous values
// display2.setSegments(blank); // clear the screen from previous values
display1.showNumberDecEx(MasterCount, 0b01000000, true, 2, 0); // display Master count and colon on first part of Master display.
display1.showNumberDec(SlaveCount, true, 2,2); // display Slave count on second part of Master display.
display2.showNumberDecEx(SlaveCount, 0b01000000, true, 2,0); // display Slave count and colon on first part of Slave display.
display2.showNumberDec(MasterCount, true, 2,2); // display Master count on second part of Slave display.
delay(touchDelay); // touch delay time
}
}