Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LED control code in "p08_DigitalHourglass" affects non-LED pins after completion of timer #83

Closed
drf5n opened this issue Feb 15, 2025 · 2 comments
Assignees
Labels
conclusion: off topic Off topic for this repository topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project

Comments

@drf5n
Copy link

drf5n commented Feb 15, 2025

if (currentTime - previousTime > interval) {
// save the current time as the last time you changed an LED
previousTime = currentTime;
// Turn the LED on
digitalWrite(led, HIGH);
// increment the led variable
// in 10 minutes the next LED will light up
led++;
if (led == 7) {
// the hour is up
}
}

Note that the code in the Digital Hourglass example starts cycling above pin 7 after the hour is up, setting pins to low and essentially setting the pinMode(switchPin,INPUT_PULLUP), overriding the external pulldown, and making the button non-functional.

The code should either reset the hourglass automatically, or check that it is in the 2-7 range before setting the pin to low.

Maybe change the test to:

if (currentTime - previousTime > interval && led <= 7 ) {

Sped-up (6 seconds/step) Example:

https://wokwi.com/projects/422992836439284737

@drf5n
Copy link
Author

drf5n commented Feb 16, 2025

@drf5n drf5n changed the title Starter Kit Digital Hourglass out-of-bounds error Starter Kit Example 10.p08_DigitalHourglass.ino out-of-bounds error Feb 16, 2025
@per1234 per1234 changed the title Starter Kit Example 10.p08_DigitalHourglass.ino out-of-bounds error LED control code in "p08_DigitalHourglass" affects non-LED pins after completion of timer Feb 16, 2025
@per1234 per1234 added type: imperfection Perceived defect in any part of project topic: code Related to content of the project itself labels Feb 16, 2025
@per1234 per1234 self-assigned this Feb 16, 2025
@per1234
Copy link
Contributor

per1234 commented Feb 16, 2025

Thanks for your report @drf5n. The sketches under the 10.StarterKit_BasicKit folder are provided to accompany the Arduino Projects Book of the Arduino Starter Kit. The Arduino Projects Book explains the code of these sketches and gives instructions for their usage.

The "p08_DigitalHourglass" sketch is unique in that it is intentionally left incomplete. The Arduino Projects Book instructs the user to add their own code to indicate the completion of the timer (which should also halt the timer code). The if (led == 7) block is annotated:

Add one more if statement in the program to check if the LED on
pin 7 is turned on. Don’t do anything with this yet. You’ll decide
what happens at the end of the hour later.

And the tutorial instructions include:

When the clock reaches one hour and all six lights are on, they just stay on. Can
you think of a way to get your attention when the hour is up? Sound or flashing
the lights are both good indicators. The led variable can be checked to see if all
the lights are on, that’s a good place to check for grabbing someone’s attention.

©

Arduino Projects Book by Arduino SA - CC BY-NC-SA 3.0

Since the primary purpose of the sketch is to accompany the Arduino Starter Kit, the code can not be changed here as you propose. The only way to do that would be to first update the code in the Arduino Projects Book and publish a new edition with the changes, then pull those changes into this repository. If you would like to propose that change, I think it will be best done via the official contact form, since the Arduino Projects Book content is not hosted in a public GitHub repository:

https://www.arduino.cc/en/contact-us

We do have discretion in the comments in these sketches, which were added to the sketches in this repository in order to provide the information that is not available to those users who don't have an Arduino Projects Book. I saw that the incomplete nature of this sketch was not documented and so I added comments to make this clear: #84. Those comments will mitigate the problem you reported here.

@per1234 per1234 closed this as not planned Won't fix, can't repro, duplicate, stale Feb 16, 2025
@per1234 per1234 added the conclusion: off topic Off topic for this repository label Feb 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conclusion: off topic Off topic for this repository topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

2 participants