Basic Max7219 coding

I am trying to learn to use the LedControl library with Max7219 chips and I thought that if I took the basic code from the tutorial and cut it back to the bone I might be able to use it to start writing my own code.

Right I thought to myself I will start with the setLed function,I will just take out everything that I don't "think" it needs ...I "think" that that was my first mistake 8) So that left me with

  #include "LedControl.h"

LedControl lc=LedControl(12,11,10,1);

unsigned long delaytime=500;

void setup() {
  
  lc.shutdown(0,false);
  /* Set the brightness to a medium values */
  lc.setIntensity(0,8);
  /* and clear the display */
  lc.clearDisplay(0);
}

void loop() { 
  
 }

Then if I want to turn on two LED's, delay and then switch both off

  void setLed(int addr, int row, int col, boolean state);

lc.setLed(0,2,7,true);   
lc.setLed(0,0,1,true); 
  
delay(500);

lc.setLed(0,2,7,false); 
lc.setLed(0,0,1,false);

Then call the function setLed in the void loop

void loop() 
{ 
  setLed ();
}

that I would be on my way, but "no way Jose", as they say. I realise that I need the curly braces in the void setLed function but no matter where I tried to place them it returned errors. So would someone be kind enough to point out my mistake/s please.
Thank you Pedro.

p.s. I am sure that it is evident that I got this code, or what is left of it from the Arduino Playground.

I hope that this is not considered bumping, I am calling it being proactive 8) but I was playing around with the code and realised that I was both declaring and calling the setLed function in void setup.Well I think that's what I have done? So I just declared setLed in void setup and called it in void loop and the two LED's turn on and stay on. Please tell me why and please don't laugh I am trying ...This stuff is like trying to join a secret society :slight_smile:

#include "LedControl.h"

LedControl lc=LedControl(12,11,10,1);

 unsigned long delaytime=500;

void setup() {
  
  lc.shutdown(0,false);
  /* Set the brightness to a medium values */
  lc.setIntensity(0,8);
  /* and clear the display */
  lc.clearDisplay(0);
 
void setLed(int addr, int row, int col, boolean state);

}
void loop() { 
  
 lc.setLed(0,1,2,true);   
 lc.setLed(0,1,3,true); 
  
delay(500);

lc.setLed(0,1,2,false); 
lc.setLed(0,1,3,false); 
}

p.s. I am sure that it is evident that I got this code, or what is left of it from the Arduino Playground.

No, that's not evident at all. It wouldn't have taken you much time to add a link (Arduino Playground - HomePage for the benefit of others), so that we don't have to go and look for it.

LedControl.setLed() is already defined in LedControl.h, so you don't need to add a function prototype for it in your sketch.

Take a look at what your sketch is doing. Every time through loop it switches the leds on, waits for half a second, switches the leds off, then immediately starts loop again. The leds do turn off, but are turned back on again so quickly that you don't see it. Try adding another delay after switching them off.

Thank you dxw00d,

and sorry for my slovenly question asking :grin: I was not being lazy I just thought that I had provided enough code to illustrate my dilemma. It's easy when you know how and why.Thank you for your prompt reply and have a nice day

Pedro.