All High

By now we have investigated what happens if we set all pins to high Z, pull up or low. We conclude the basic sketches by setting all pins to high.

//
//	www.blinkenlight.net
//
//	Copyright 2011 Udo Klein
//
//	This program is free software: you can redistribute it and/or modify
//	it under the terms of the GNU General Public License as published by
//	the Free Software Foundation, either version 3 of the License, or
//	(at your option) any later version.
//
//	This program is distributed in the hope that it will be useful,
//	but WITHOUT ANY WARRANTY; without even the implied warranty of
//	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//	GNU General Public License for more details.
//
//	You should have received a copy of the GNU General Public License
//	along with this program. If not, see http://www.gnu.org/licenses/


// This sketch will set all outputs to high.

void setup() {
	for (uint8_t pin=0; pin<20; ++pin) {
		pinMode(pin, OUTPUT);
		digitalWrite(pin, HIGH);
	}
}

void loop() { }

All LEDs light up. Bright!

Blinkenlight Prototype On


10 Responses to All High

  1. Robert says:

    does not work with leonardo …. some light’s not high. and not in correct order. 😦

    • I do not own a Leonardo. Can you please give a little bit more details such that I can investigate this? Maybe a picture?

      • Robert says:

        Sorry here! All lights high … https://twitter.com/hifigraz/status/286523857031012353
        and I think 16 and 15 are more 20 and 19 ….

        • Thanks for the video. This makes the issue crystal clear. I searched a little bit and found this one: http://provideyourown.com/2012/arduino-leonardo-versus-uno-whats-new/:

          The original 6 analog input pins have new digital pins mappings as well. They are:

          A0 – D18
          A1 – D19
          A2 – D20
          A3 – D21
          A4 – D22
          A5 – D23

          Since the original Arduino maps A0 to D14, A1 to D15 … A5 to D19 it follows that D14 … D17 are not connected to any LEDs of the shield. This explains the effect exhibited in your video. So you have to change your code to count 0, 1, 2, …, 12, 13, 18, 19, …, 23 instead of 0 … 19.

      • Robert says:

        hey thank you, that was fast 😉

        • Here is an example how such a mapping might be implemented. The led_to_pin() function does the trick.

          //
          //  www.blinkenlight.net
          //
          //  Copyright 2013 Udo Klein
          //
          //  This program is free software: you can redistribute it and/or modify
          //  it under the terms of the GNU General Public License as published by
          //  the Free Software Foundation, either version 3 of the License, or
          //  (at your option) any later version.
          //
          //  This program is distributed in the hope that it will be useful,
          //  but WITHOUT ANY WARRANTY; without even the implied warranty of
          //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
          //  GNU General Public License for more details.
          //
          //  You should have received a copy of the GNU General Public License
          //  along with this program. If not, see http://www.gnu.org/licenses/
          
          
          uint8_t led_to_pin(const uint8_t led) {
              return led<14? led: led-14 + A0;
          }
          
          void setup() {
              for (uint8_t pin=0; pin<20; ++pin) {
                  pinMode(led_to_pin(pin), OUTPUT);
              }
          }
          
          void blink(const uint8_t pos) {
              digitalWrite(led_to_pin(pos), HIGH);
              delay((sqrt(((float)20 - pos)/20) - sqrt((19.0 - pos)/20)) * 500);
              digitalWrite(led_to_pin(pos), LOW);
          }
          
          void loop() {
              for (uint8_t pos=0; pos<19; ++pos) {
                  blink(pos);
              }
              for (uint8_t pos=19; pos>0; --pos) {
                  blink(pos);
              }
          }
          
  2. Nickson says:

    There was a little error in the comments of your code.
    Just right before the “setup()”

    Error:
    “// This sketch will set all outputs to low.”
    Should be:
    “// This sketch will set all outputs to high.”

    Made me confused for a moment.
    No big deal really. In fact, it’s a very small deal.
    But the correction makes your article more perfect! 🙂

Leave a reply to blinkenlightblog Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.