Help With COVID UVC Project

Hello, I really need help on this project from school. Basically the goal is to have a button press start a timer then have a few things turn on/off afterwards. Where I'm getting stuck is the timer part, I cannot make the code function to have a countdown like I would want. In the code here I would like the button press to activate a 2 minute timer, then turn on a fan on the pin described. I am not a good coder, I know the embedded loop is stupid but I cant understand other peoples codes. If someone can provide help in any way id really appreciate that. Thankyou

P.s if someone can also explain why when I have an issue clearing the display after it prints

#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#define OLED_RESET -1
Adafruit_SSD1306 display(128, 32);

const int fan_1 = 2;
int fan_1value;
const int button_1 = 7;
int button_1value;
const int screen = 10;
int m;
int ts;
int s;
String minutes_counter = String(m);
String tenseconds_counter = String(ts);
String seconds_counter = String(s);
void setup() {

display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
pinMode(2, OUTPUT);
pinMode(7, INPUT_PULLUP);
Serial.begin(9600);
display.clearDisplay();

}

void loop()
{
button_1value = digitalRead(button_1);
if (button_1value == LOW)

display.clearDisplay();
display.invertDisplay(false);
display.setTextSize(4);
display.setTextColor(WHITE);
display.setCursor(32, 0);
display.print(": ");
display.setCursor(0, 0);

for (int m = 1; m >= 0; m--)//starting embedded loop for timer
{
display.print(m);
display.display();

for (int ts = 5; ts >= 0; ts --)
{

display.print(ts);
display.display();

for (int s = 9; ts >= 0; s --)
{
display.print(s);
display.display();
}
}

}
digitalWrite (2, HIGH); //fan on

}

Please follow the advice on posting a programming question given in Read this before posting a programming question

In particular note the advice to Auto format code in the IDE and to use code tags when posting code here as it prevents some combinations of characters in code being interpreted as HTML commands such as italics, bold or a smiley character, all of which render the code useless

  for (int s = 9; ts >= 0; s --)

Cut and paste oops

1 Like

First of all I tell you that embedded loops isn't stupid >:( "ok" but I know your situation when I was a student, I also faced this type of problems and I solved all my problems in "cheeg" Basically this is a paid site for students.