Go Down

Topic: state change detection in the 21st century (Read 1 time) previous topic - next topic


All of the LED action takes place in the last few lines of the program.
Code: [Select]
if (buttonPushCounter % 4 == 0)
Until the first button press, buttonPushCounter = 0.  0 % 4 = 0 so the LED is HIGH.  
Unless the buttonPushCounter is greater than 0 do not turn the LED on.

Code: [Select]
if (buttonPushCounter % 4 == 0 && buttonPushCounter > 0)
      digitalWrite(ledPin, HIGH);
      digitalWrite(ledPin, LOW);

Thanks, understood.


*I find Eagle and KiCad too complex for the simple boards that I make.
I have used Altium for years but since I am trying to avoid Windoze like the plague and I am now using Linux I have installed KiCad and for a freebie it is awesome. Maybe a bit complex for simple stuff but I make some not quite so simple stuff.
Engineers design things.....technicians make them work.

I don't need anti-static wrist straps.....an instructor years ago told me I had no potential.


Code: [Select]
buttonState = digitalRead(buttonPin);
 In the 21st century, "buttonState" doesn't have global scope (it wouldn't be a Boolean either)
+ reply #3

Would bool buttonState = (bool) digitalRead(buttonPin); be more correct?
I don't trust atoms.  They make up everything.

No private consultations undertaken!


Code: [Select]
bool buttonState = digitalRead(buttonPin) == HIGH; Might be. Or maybe even "== LOW"
Please don't PM technical questions - post them on the forum, then everyone benefits/suffers equally


Is the issue bad form?

If my sketch has --
bool pbState;
pbState = digitalRead(pb);

if (pbState)

works [correlating 1, HIGH, true; 0, LOW, false)]
"Who is like unto the beast? who is able to make war with him?"
When all else fails, check your wiring!


If truth be told, HIGH and LOW are very prosaic names. If they weren't already all over the Arduino planet, I'd be quite happy using 0 and 1 for I/O states.
  ... with a transistor and a large sum of money to spend ...
Please don't PM me with technical questions. Post them in the forum.


Jan 14, 2021, 04:27 am Last Edit: Jan 14, 2021, 04:28 am by larryd



No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.


Please don't PM technical questions - post them on the forum, then everyone benefits/suffers equally


Jan 14, 2021, 10:41 am Last Edit: Jan 14, 2021, 10:42 am by lastchancename
Just being pedantic...

It would be nice to flip your initial schematics horizontally to depict signal flow from left to right...
Just a thought to introduce the learners to logical schematic layout.

You did well with positive higher, and negative lower.

Sorry !
Experienced responders have a nose for laziness, (they were beginners once)... Sure, there are trolls, chest-beaters, and pretenders - but the help you'll get here is about as good as it gets - if you try to help youself!.

Go Up