state change detection in the 21st century

Fair enough ;)

I don’t understand the comment about wiring diagonally to avoid a short? Isn't it sometimes more convenient to wire 'laterally', i.e. on same side of the button?

Diagonals are always switched, so it’s a good way to guarantee you don’t connect two wires permanently as would happen if you accidentally used terminals 3 and 4 in the red box below for example.

Thanks, understood. So avoiding connecting the opposite pins on the [u]longer[/u] sides. I still occasionally find it convenient to wire between 2 & 4 or 1 & 3.

@groundFungus: What tool do you use for your neat schematics please?

What tool do you use for your neat schematics please?

I use Express Sketch which comes with the EspressPCB software. I downloaded it years ago. Don't know how the newest is, but I love the older one that I have. I used to use OrCad but since I no longer work for a company I can't afford it.

Thanks. I’m using a program that’s probably even older, CircuitMaker Pro, but I’ll take a close look at Express Sketch.

Staying OT for a minute, do you also use the Fritzing app BTW, that I see mentioned frequently?

I have used Fritzing, but only to make simple PC boards* (I route them on my little CNC router). Fritzing will generate the Gerber files for free. Express PCB charges for Gerber files. I do not use the Fritzing breadboard view or schematic drawing. People don't like Fritzing breadboard views, generally, because they leave out a lot of information that would be on a good schematic.

*I find Eagle and KiCad too complex for the simple boards that I make.

@groundFungus,

Trying your sketch while learning about states. LED is ON after start or reset. One press takes it OFF. Three more presses (four in total) takes it ON again.

Is that the intended behaviour? How would I change it to be OFF at the start, please, awaiting four presses? I tried taking the LED low during Setup but that didn't do it.

“ I tried taking the LED low during Setup but that didn't do it.”

@ Terrypin

When you try something and still have trouble, always show us ‘what’ you tried.


Use CTRL T to format your code. Attach your ‘complete’ sketch between code tags

[code]Paste your sketch here[/code]

How would I change it to be OFF at the start, please

All of the LED action takes place in the last few lines of the program.

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.

if (buttonPushCounter % 4 == 0 && buttonPushCounter > 0)
   {
      digitalWrite(ledPin, HIGH);
      }
   
   else
   {
      digitalWrite(ledPin, LOW);
   }

groundFungus: All of the LED action takes place in the last few lines of the program.

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.

if (buttonPushCounter % 4 == 0 && buttonPushCounter > 0)
   {
      digitalWrite(ledPin, HIGH);
      }
   
   else
   {
      digitalWrite(ledPin, LOW);
   }

Thanks, understood.

groundFungus: *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.

TheMemberFormerlyKnownAsAWOL: 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?

bool buttonState = digitalRead(buttonPin) == HIGH; Might be. Or maybe even "== LOW"

Is the issue bad form?

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

if (pbState)

works [correlating 1, HIGH, true; 0, LOW, false)]

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.

_5volts _0volts

VCC GND

:D

larryd: _5volts _0volts

No - discriminatory towards the 3.3V variants :D

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 !