writing multiple pins at once

Hello,
i have a 7 segment led and im trying to make numbers with it,
i tried to make a int with the pins needed to make the number 9 but when i run the code all i see is blinking from some of the segments.
can anybody see what i'm doing wrong ?

I know my program is not nearly finished but i need to understand the basics before i can go further
thanx

int Nine[6] = {2, 3, 4, 5, 6, 7}; 

void setup()
{pinMode(Nine[6], OUTPUT);}

void loop()
{analogWrite(Nine[6], HIGH);}

Elements in an array are numbered from 0 so if the are six elements then they are numbered from 0 to 5.

The declaration of the array give the number of elements.

Mark

In addition to what @holmes4 has said, I can't see any relationship between the code you have posted and the title of your post.

Also, I suspect that your 7-segment led will work perfectly well without the need to write all the segments at the same instant.

If you really do need to write several pins at once read about PORTx and port manipulation Be aware that none of the I/O ports on a UNO makes all 8 pins available to you.

...R

Hello,
I'm sorry if there's anything unclear,
i just want to make some sort of shortcut so i can write 1 variable to make a number instead of having to make 6 outputs high.

i just want to make some sort of shortcut so i can write 1 variable to make a number instead of having to make 6 outputs high.

Not in C or C++. Only the developers of the language can invent shortcuts.

You could use a for loop...

So... define your 7 element array of leds like this:

byte myArray[7] = {2,3,4,5,6,7,8};

try code like this:

byte myLeds[7] = {2,3,4,5,6,7,8};// all 7 elements of the display are put into the array starting wiht element zero through element six

byte myMaskArray[10] = { B0000000,B0000000,B0000000,B0000000,B0000000,B0000000,B0000000,B0000000,B1111111,B0111111};
byte blank =       B0000000;
byte elementZero = B0000001;  //notice the pattern here
byte elementOne  = B0000010;  //the one has move to the 2nd positionin the byte
byte elementTwo  = B0000100;  //the one moved to the third position of the byte


void setup() 
{
  for (byte i = 0; i < 7; i++)
  {
    pinMode(myLeds[i], OUTPUT);
  }
}

void loop() 
{
  liteLeds(9); //lite the number nine
  delay (2000);
  liteLeds(8); //lite the number eight
  delay (2000);
  liteLeds(elementZero); // only led 2 should lite
  delay(2000);
  liteLeds(elementOne); // only led 3 should lite
  delay(2000);
  liteLeds(elementTwo); // only led 4 should lite
  delay(2000);
  liteLeds(blank);
  delay(2000);
}

void liteLeds(byte myMask)
{
  for (byte i = 0; i < 7; i++)
  {
    digitalWrite(myLeds[i], bitRead(myMaskArray[myMask],i));
  }
}

and see if you can determine how to modify this:

byte myMaskArray[10] = { B0000000,B0000000,B0000000,B0000000,B0000000,B0000000,B0000000,B0000000,B1111111,B0111111};

to correct the output of elements 0 through 8 to display the in the manner you wish

Make sure you have current limit resistors and do not exceed the current for a particular port:

  1. Although each I/O port can source more than the test conditions (20mA at VCC = 5V, 10mA at VCC = 3V) under steady state conditions (non-transient), the following must be observed:
    ATmega48A/PA/88A/PA/168A/PA/328/P:
    1] The sum of all IOH, for ports C0 - C5, D0- D4, ADC7, RESET should not exceed 150mA.
    2] The sum of all IOH, for ports B0 - B5, D5 - D7, ADC6, XTAL1, XTAL2 should not exceed 150mA.
    If IIOH exceeds the test condition, VOH may exceed the related specification. Pins are not guaranteed to source current greater than the listed test condition.
  2. Although each I/O port can sink more than the test conditions (20mA at VCC = 5V, 10mA at VCC = 3V) under steady state conditions (non-transient), the following must be observed:
    ATmega48A/PA/88A/PA/168A/PA/328/P:
    1] The sum of all IOL, for ports C0 - C5, ADC7, ADC6 should not exceed 100mA.
    2] The sum of all IOL, for ports B0 - B5, D5 - D7, XTAL1, XTAL2 should not exceed 100mA.
    3] The sum of all IOL, for ports D0 - D4, RESET should not exceed 100mA.
    If IOL exceeds the test condition, VOL may exceed the related specification. Pins are not guaranteed to sink current greater than the listed test condition.

The same fontArray[] idea can be used with an external shift register also for more current drive and fewer IO pins used.