Go Down

Topic: MsTimer2 and arrays (Read 528 times) previous topic - next topic


Hi everyone

I've been trying to use MsTimer2 to update a led array outside of the main loop but I'm having a little trouble writing the update function without including parameters. Especially trying to call the array of numbers into the function. If you guys could take a look I would be grateful.


Code: [Select]

#include <MsTimer2.h>

void setup() {
  int i=0;
  pinMode (6,OUTPUT);
  pinMode (7,OUTPUT);
  pinMode (8,OUTPUT);
 int array[] ={0,0,0,0,0,0,0,0};
 MsTimer2::set(1, updatearray);

void loop() {

void updatearray() {
 static int i;
 if (i < 8)
 i = i+1;

void shift(int i)


Hey, greendude...

When you declare a variable like "array" inside a function, it is only visible from within that function.  Since your "array" lives inside setup(), the code inside shift() can't get to it.  An easy solution is just to move it outside of setup() like this:

Code: [Select]

int array[] ={0,0,0,0,0,0,0,0};

void setup() {


Go Up