Pages: [1]   Go Down
Author Topic: Basic Max7219 coding  (Read 852 times)
0 Members and 1 Guest are viewing this topic.
Canberra Australia
Offline Offline
God Member
*****
Karma: 11
Posts: 514
Hardcore Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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  smiley-cool  So that left me with    
Code:
  #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


Code:
  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

Code:
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.


Logged


Canberra Australia
Offline Offline
God Member
*****
Karma: 11
Posts: 514
Hardcore Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I hope that this is not considered bumping, I am calling it being proactive  smiley-cool 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  smiley

Code:
#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);
}

Logged


Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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 (http://arduino.cc/playground/Main/LedControl 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.
Logged

Canberra Australia
Offline Offline
God Member
*****
Karma: 11
Posts: 514
Hardcore Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you dxw00d,

and sorry for my slovenly question asking  smiley-mr-green 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.
Logged


Pages: [1]   Go Up
Jump to: