Novice: if thisPIN OR thatPIN

I’m two weeks into learning Arduino programming, stepping through Simon Monk’s book, trying simple sketches and getting much appreciated help here and in AllAboutCircuits.

The current test project is simply intended to deliver a positive 5V output pulse if either one pin (say 12) goes LOW or another pin (say 5) goes HIGH. (I’ll use the pulse to activate a 12V sounder in my garage whenever either the front door button is pressed or my wife uses an RC gadget in the house to call me.)

Q1: I assume it would work with just two successive IF sections?

Q2: But is there a way to combine the two neatly into one command, thus avoiding duplicating several lines of code please?

I built it yesterday using classic parts (CMOS 4001, etc) but thought I’d test both my learning and the relative effort now by doing it with my Arduino UNO.

Terry, East Grinstead, UK

But is there a way to combine the two neatly into one command, thus avoiding duplicating several lines of code please?

Yes it is called a compound if. You have two or more comparisons and link them with an AND or OR function. The symbol for AND is && and that for OR is || So to do something if pin 12 is Low OR pin 5 is high use

if(digitalRead(12) == LOW) || digitalRead(5) == HIGH) { // do stuff

Note this happens when those conditions apply not when they first apply.

Thanks, understood, appreciate the fast and clear reply. I’ll try that soon.