Pages: [1]   Go Down
Author Topic: How to repeat global declaration?  (Read 345 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I am searching for a method, on how can we repeat the global declaration of , let say-  bytes.

Here's the code:

Code:
int latchPin = 8;
int clockPin = 12;
int dataPin = 11;

//holders for information you're going to pass to shifting function
byte mod1;
byte mod2;
byte mod3;
byte mod4;
byte mod5;
byte mod6;
byte mod7;
byte mod8;
byte mod9;
byte mod10;

const uint16_t running[] PROGMEM= {
B11111111,B11111111,B11111111,B11111111,
}

void setup() {
............
}


void loop() {
.....
 mod1 = pgm_read_byte(&(running[0]));
 mod2 = pgm_read_byte(&(running[1]));   .......// I will be using the global declared byte here

............

 shiftOut(dataPin, clockPin, mod1); 


}


As you can see, I have the same repetition

mod1, mod2, mod3 to be declared at the top (global)....

rather than manually declare it, is it possible for me to use for loop?

Thank you in advance.


Logged

UK
Offline Offline
Faraday Member
**
Karma: 16
Posts: 2883
Gorm deficient
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No, it isn't possible.
Have a look at using arrays.
http://arduino.cc/en/Reference/Array
Logged

Per Arduino ad Astra

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you Groove.

I've read that.

And I've found the way to shorten the code using

Code:
    for(int i=noofmodules-1; i>=0; i--){
    byte k= pgm_read_byte(&(running[j+i]));
    Serial.println(k);
    shiftOut(dataPin, clockPin, k);
    }
Logged

Pages: [1]   Go Up
Jump to: