2022 Temple Convention Clinic

Welcome to another Make-and-Take clinic!

In this clinic we will show how to use more than one Arduino pin to do all kinds of different things. But, to keep it simple, we will encourage beginners to participate too and only play with LEDs. Think about things that include a beacon, a welder, a campfire, a traffic light and so forth. Once you grasp the idea of using millis( ) and the ++ part in C++, you can more advanced devices like servos and sensors.


What do you need to bring? Everything! Including:

  • An Arduino (Uno or Nano) that has some way of plugging into a little breadboard, where you can stick all the LEDs and resistors into.

  • Various colors of through hole LEDs, the kind that can stick into a breadboard (see kit shown above)

  • A little breadboard (see kit shown above)

  • The interconnect "Arduino" wires (see kit shown above)

  • 1 kilo-ohm resistors (see kit shown above)

  • And then the USB cable to connect the Arduino to your computer, as well as the power supply to keep the computer running.


We will publish the .pdf file here the day before, but the thumb drive we will pass around in class, will also contain the .pdf file and the code we will work with.


So, to get you ready for the clinic, read through the next:


main.cpp contains the important and needed calls to the blue parts you might have seen opening the IDE (Integrated Development Environment):


int main( void ) {

init( ); // set up all common things needed

initVariant( ); // set up specific things needed

setup( ); // only happens once

for(;;) {

loop( );

if( serialEventRun ) serialEventRun( ); // used to check if new software is incoming

} // repeat forever

return 0;

} // int main( )


This main.cpp file, does all the work behind the scenes to only ask you to provide the contents of setup( ) and loop( )


So, in setup( ) you tell the pins with LEDs connected to be outputs:

pinMode( pinNumber, OUTPUT );

And this needs to happen for every LED connected.


And then in loop( ), we turn those LEDs on and off, by making their pins HIGH or LOW.

digitalWrite( pinNumber, HIGH );

or

digitalWrite( pinNumber, LOW );


So that is the control we have: make the pins outputs, and then make the output 5 volts or 0 volts. (Yes, there are 3.3 volt systems too, we know.)


...blink, blink, blink, beep, beep, smoke, less smoke, more smoke, smoke clearing ... yes we know ... but the steam engine will pass and all will become clear...


Now what do we do with this?

We turn an LED on, wait 1/2 a second and turn it back on, wait 2 1/2 seconds and turn it back on, and then repeat!


And that is a beacon! Install it on a tall tower and call the airspace safe. But what about the other pins? Well, you can easily turn a second LED on and off and call it beacon 2.0! And then you want it a little out of sequence, so you do the math: Turn 1 on; wait 1/2 a second: turn it off; wait another 1/2 a second: turn #2 on; wait 1/2 a second: turn #2 off; wait...what huh? Yes, you can do the math and get it up and working in less than 10 minutes. Then you add the third beacon and redo ALL the math and it works. And then you discover a welder, with some random "waits", subtract it from the first 1/2 second and only wait that amount...and so forth...all doable, for real.


But, would this not be a whole lot less math:

void loop( ) {

beacon1.update( );

beacon2.update( );

beacon3.update( );

welder1.update( );

welder2.update( );

} // loop( )



Sorry, here is the less math full version, where every beacon and every welder runs itself, so they all use the same math:

#define DELAYSTART 500

#define BEACONPERIOD 3000

#define BEACONONTIME 500

#define WELDERPAUSE 250

#define BEACON1PIN 5

#define BEACON2PIN 6

#define BEACON3PIN 7

#define WELDER1PIN 8

#define WELDER2PIN 9


Beacon beacon1 = Beacon( BEACON1PIN, BEACONPERIOD, BEACONONTIME, 0 );

Beacon beacon2 = Beacon( BEACON2PIN, BEACONPERIOD, BEACONONTIME, DELAYSTART );

Beacon beacon3 = Beacon( BEACON3PIN, BEACONPERIOD, BEACONONTIME, 2 * DELAYSTART );


Welder welder1 = Welder( WELDER1PIN, WELDERPAUSE );

Welder welder2 = Welder( WELDER2PIN, 1.5 * WELDERPAUSE );


void setup( ) {

beacon1.setup( );

beacon2.setup( );

beacon3.setup( );

welder1.setup( );

welder2.setup( );

} // setup( )


void loop( ) {

beacon1.update( );

beacon2.update( );

beacon3.update( );

welder1.update( );

welder2.update( );

// And that is it!!!

} // loop( )


And what hides inside Welder and Beacon? Come to the clinic!


Here is the code...


And the pdf for the clinic!