Good morning.
I wonder whether anyone can help with a question on programming an Arduino Uno?
I am writing a programme to operate a mechanical clock mechanism. The actual time is set by a plug-in RTC module. I want to make
the clock strike each hour, once at one o'clock, twice at two o'clock and so on. I am struggling with this part of the code. I have written one sequence
that works, but it is extremely cumbersome, so am trying to use a loop to make it more efficient.
There are two code snippets below, both trying to operate the LED five times.
Snippet One. This is what I am trying to use to make an LED flash five times, without using a "delay" function, and then to remain off. It turns on, but remains on.
Snippet Two. I have added code to try and make the LED turn off again after a preset duration. However, the LED does not turn on at all with this. All of the variables and constants have been defined. The same sequence to turn off the LED works elsewhere in the programme, but I cannot see why it does not work here.
I am going around in circles and should appreciate any constructive suggestions, including an alternative way to achieve the same objective.
Thank you.
James.
Snippet One
void Strike_the_Hour () {
unsigned long Present_Each_Hour_Strike_Time = millis(); // Sets the present time
Elapsed_Each_Hour_Strike_Time = Present_Each_Hour_Strike_Time – Previous_Each_Hour_Strike_Millis; // Calculates length of time that has passed since last event
while(number_of_strikes < 5){
State_of_Hours_Activator_LED = HIGH; // Activates the solenoid.
digitalWrite(Hours_Activator, State_of_Hours_Activator_LED);
number_of_strikes ++;
}
}
Snippet 2
void Strike_the_Hour () {
unsigned long Present_Each_Hour_Strike_Time = millis(); // Sets the present time
Elapsed_Each_Hour_Strike_Time = Present_Each_Hour_Strike_Time – Previous_Each_Hour_Strike_Millis; // Calculates length of time that has passed since last event
while(number_of_strikes < 5){
State_of_Hours_Activator_LED = HIGH; // Activates the solenoid.
digitalWrite(Hours_Activator, State_of_Hours_Activator_LED);
if (Elapsed_Each_Hour_Strike_Time >= Period_Each_Hour_Strike_On) {
State_of_Hours_Activator_LED = LOW; // Activates the solenoid.
digitalWrite(Hours_Activator, State_of_Hours_Activator_LED);
number_of_strikes ++;
}
}
}