I am using the code that you made, as I should start?, with star and then put the minutes or hours or direct start to set the minutes.
Because when I put the board to the arduino all the LEDs flash and the arduino turns, and then opromimo the first yellow led, it turns on but after 15 minutes nothing happens.
What do you recommend me?
#include <Servo.h>
boolean sessionStarted = false;
int hours = 0;
int MAX_HOURS = 3;
int HOURS_START_PIN = 5;
int minutes = 0;
int MAX_MINUTES = 3;
int MINUTES_START_PIN = 2;
boolean readingHoursInProgress = false;
boolean readingMinutesInProgress = false;
boolean readingSessionBtnInProgress = false;
unsigned long endTime = 0;
unsigned long MINUTES_MULTIPLIER = 60000; // 1000 por segundos, 60000 por minutos
unsigned long HOURS_MULTIPLIER = MINUTES_MULTIPLIER * 60;
Servo servo;
void setup() {
for (int pin = 2; pin <= 7; pin++) {
pinMode(pin, OUTPUT);
}
// SERVO
servo.attach(9);
servo.write(0);
delay(250);
}
void loop() {
if (!sessionStarted) {
readMinutes();
readHours();
showCurrentTime();
} else {
if (millis() > endTime) {
finishSession();
}
}
if (sessionStatusChanged()) {
if (!sessionStarted) {
startSession();
} else {
finishSession();
}
}
}
void finishSession() {
sessionStarted = false;
servo.write(170);
fleshLED();
servo.write(0);
}
void startSession() {
fleshLED();
sessionStarted = true;
endTime = minutes * 15 * MINUTES_MULTIPLIER;
endTime += hours * HOURS_MULTIPLIER;
endTime += millis();
}
void fleshLED() {
for (int i = 0; i < 5; i++) {
for (int pin = 2; pin <= 7; pin++) {
digitalWrite(pin, HIGH);
}
delay(500);
for (int pin = 2; pin <= 7; pin++) {
digitalWrite(pin, LOW);
}
delay(500);
}
}
boolean sessionStatusChanged() {
int sessionBtnInput = analogRead(A2);
if (!readingSessionBtnInProgress) {
if (sessionBtnInput > 1000) {
readingSessionBtnInProgress = true;
}
} else {
if (sessionBtnInput == 0) {
readingSessionBtnInProgress = false;
return true;
}
}
return false;
}
void readMinutes() {
int minInput = analogRead(A0);
if (!readingMinutesInProgress) {
if (minInput > 1000) {
minutes++;
if (minutes > MAX_MINUTES) {
minutes = 0;
}
readingMinutesInProgress = true;
}
} else {
if (minInput == 0) {
readingMinutesInProgress = false;
}
}
}
void readHours() {
int hrsInput = analogRead(A1);
if (!readingHoursInProgress) {
if (hrsInput > 1000) {
hours++;
if (hours > MAX_HOURS) {
hours = 0;
}
readingHoursInProgress = true;
}
} else {
if (hrsInput == 0) {
readingHoursInProgress = false;
}
}
}
void showCurrentTime() {
// show minutos
for (int pin = MINUTES_START_PIN; pin < MINUTES_START_PIN + MAX_MINUTES; pin++) {
digitalWrite(pin, pin < MINUTES_START_PIN + minutes ? HIGH : LOW);
}
// show horas
for (int pin = HOURS_START_PIN; pin < HOURS_START_PIN + MAX_HOURS; pin++) {
digitalWrite(pin, pin < HOURS_START_PIN + hours ? HIGH : LOW);
}
}