/*
Arduino | coding-help
Esembli🐢
1/21/25 at 11:04 PM
*/
#include <Arduino.h>
#include <string.h>
String flickerAmount = "Type the amount of times you want it to flicker!";
int totalBlinkWhite;
void setup() {
Serial.begin(9600);
pinMode(A1, OUTPUT);
pinMode(A2, OUTPUT);
}
void loop() {
Serial.println(flickerAmount);
Serial.println(" ");
while (Serial.available() == 0) {
// Waiting Period
}
totalBlinkWhite = Serial.parseInt();
if (totalBlinkWhite == 0) {
Serial.println("Retype a valid number");
delay(1000);
return;
}
Serial.println("How fast? 1000 = 1 second");
Serial.println(" ");
while (Serial.available() == 0) {
}
int delayTime = Serial.parseInt();
String BlinkText = "User Blink #: ";
String DelayTimeText = "DelayTime #: ";
Serial.println(BlinkText + totalBlinkWhite);
Serial.println(DelayTimeText + delayTime);
Serial.println(" ");
for (int j = 1; j <= totalBlinkWhite;) {
while (Serial.available() == 1) {
Serial.println("Action Pressed");
}
j++;
analogWrite(A1, 255);
analogWrite(A2, 255);
delay(delayTime);
analogWrite(A1, 0);
analogWrite(A2, 5);
delay(delayTime);
if (j >= totalBlinkWhite) {
int pdelayTime = delayTime / 1000;
String total = " total";
String second = " second";
String seconds = " seconds";
String milli = " milisecond(s)";
String text2 = " times, with an interval of ";
String text = " and lasted ";
String text1 = "Went ";
float totalTime = pdelayTime * totalBlinkWhite;
if (pdelayTime < 1) { // if the delay time is less than 1 second
if (totalTime < 1) {
Serial.println(text1 + totalBlinkWhite + text2 + delayTime + milli);
}
if (totalTime == 1) {
Serial.println(text1 + totalBlinkWhite + text2 + totalBlinkWhite +
text + totalTime + second + total);
}
if (totalTime > 1) {
Serial.println(text1 + totalBlinkWhite + text2 + totalBlinkWhite +
text + totalTime + seconds + total);
}
} else if (pdelayTime == 1) { // if the delay time is one second
Serial.println(text1 + totalBlinkWhite + text2 + pdelayTime + second + text +
totalTime + seconds + total);
} else { // if the delay time is more than one second
Serial.println(text1 + totalBlinkWhite + text2 + pdelayTime + seconds + text +
totalTime + seconds + total);
}
Serial.println(" ");
Serial.println("--------------");
Serial.println(" ");
return;
}
}
}