Go Down

Topic: How to repeat global declaration? (Read 814 times) previous topic - next topic



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

Here's the code:

Code: [Select]

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= {

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.


No, it isn't possible.
Have a look at using arrays.
Per Arduino ad Astra


Thank you Groove.

I've read that.

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

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

Go Up