PU-2: PIN assigments and some testing

It’s good to have a Mega! Plenty of pins for the prototype. Some of the digital pins are hidden by the shield I made for the connectors.

As far as coding goes, programming the PU-2 is easier than programming the PU-1. The switches are all assigned to an independent digital pin. Each can effectively be debounced in software. The FCB1010 switches are all tied together on one side. The other contact of each switch is tied to a digital pin. Defining that pin as INPUT and doing a digitalWrite on it turns on the internal pull-up resistor of the Arduino:

Be careful about which pin is turned into INPUT or OUTPUT, otherwise you will short them.

  int switchMinus16 = 35;
  pinMode(switchMinus16, OUTPUT);
  digitalWrite(switchMinus16, LOW);
  int switchMinus712 = 52;
  pinMode(switchMinus712, OUTPUT);
  digitalWrite(switchMinus712, LOW);

  for(int j = 0; j <= 11; j++){
    pinMode(switches[j], INPUT);
    digitalWrite(switches[j], HIGH);

For the prototype, I decided to limit the parts count. All LEDs are tied to one 330 ohms resistor that is connected in series with +5 volts.

The code below just defines the pins as OUTPUT and then, as a quick test, lights each LED for 250 ms. Then, the pin is set to HIGH, so the LED is turned off. The digital pin is, in effect, supplying GROUND to the LED when low, creating a simple +_resistor_LED_- circuit.

  for(int i = 0; i <= 11; i++){ // LED pins as OUTPUT
    pinMode(led[i], OUTPUT);
    digitalWrite(led[i], LOW);
    delay(250);                // Just a quick test to see
    digitalWrite(led[i],HIGH); // If everything is working

Note that you can’t (or shouldn’t) turn more than one LED on at a time. As a test, I have used the “persistence of vision” (POV) principle with good results:

digitalWrite(pin1, LOW); // Turn LED1 on
digitalWrite(pin1, HIGH);// then off
digitalWrite(pin2, LOW); // Turn LED2 on
digitalWrite(pin2, HIGH);// then off

If the code is fast enough, you eyes won’t see the LEDs blink.


Leave a Reply

Your email address will not be published. Required fields are marked *