MAX7219 does not respond to code written using LedControl library


i working on project show state of votes after pressing red or green button.  voting state shown using 2 led matrices 50 leds each, light according percentages had been recorded until point.
my problem code ledcontrol library supposed control max7219 bears no response.  code using below:

code: [select]

//we have include libary
#include "c:\users\adi\downloads\arduino-1.0.4-windows\arduino-1.0.4\libraries\ledcontrol\ledcontrol.h"

// enter number of leds on side
#define num_leds  50

//and create ledcontrol
ledcontrol fordisplay = ledcontrol(12,11,10,1);
ledcontrol againstdisplay = ledcontrol(9,8,7,1);

// pushbutton pins
int buttonforpin = 2;
int buttonagainstpin = 3;

// button led pins
int forledpin = 4;
int againstledpin = 5;

// button state markers
int buttonstatefor = 0;
int buttonstateagainst = 0;

// amount of data each led holds
double delta = num_leds/100.0;

// data holders
int totalcount = 0;
int forcount = 0;
int againstcount = 0;

void setup() {
  //wake max72xx power-saving mode
  fordisplay.shutdown(0,false);
  againstdisplay.shutdown(0,false);
 
  //set high brightness leds
  fordisplay.setintensity(0,15);
  againstdisplay.setintensity(0,15);

  //initialize button pins input
  pinmode(buttonforpin, input);
  pinmode(buttonagainstpin, input);

  //initialize led light-up pins
  pinmode(forledpin, output);
  pinmode(againstledpin, output);
   
  //turn off leds
  fordisplay.cleardisplay(0);

  againstdisplay.cleardisplay(0);

  serial.begin(9600);
}

void showresults() {
 
  // increase total count of people voted
  totalcount++;

  //serial.println(forcount);
  //serial.println(totalcount);

  // calculate decimal value of people voting for
  double fordecimal = (double)forcount/totalcount;

  // calculate whole number percentage of people voting for
  int forpercentage = fordecimal * 100;
  //serial.println(forpercentage);

  // turn on correct number of leds show percentage
  for(int = 0; <= forpercentage*delta; i++) {
    fordisplay.setled(0, / 8, % 8, true);
  }

  for(int = 0; <= 25; i++) {
    againstdisplay.setled(0, / 8, % 8, true);
  }

  //serial.println("displaying results");
  delay(5000);

  // turn off leds regardless of whether turned on
  fordisplay.cleardisplay(0);

  againstdisplay.cleardisplay(0);
}

void loop() {

  // read button states
  buttonstatefor = digitalread(buttonforpin);
  buttonstateagainst = digitalread(buttonagainstpin);

  //button pressed
  if(buttonstatefor == high) {
    forcount++;
    serial.println("voted for");
    digitalwrite(forledpin, high);
    showresults();
    digitalwrite(forledpin, low);
    //serial.println("now vote again");
  }
  if(buttonstateagainst == high){
    againstcount++;
    serial.println("voted against");
    digitalwrite(againstledpin, high);
    showresults();
    digitalwrite(againstledpin, low);
    //serial.println("now vote again");
  }
}



some notes:
i did not import ledcontrol library library, rather imported 2 separate files.  compiles, , buttons work , made code go through showresults().  calculations of percentages correct. 
as electronics, double , triple checked connections, , connected correctly.  using 1k ohm resistors, , capacitor.  arduino getting 9v, , both max7219s being powered 5v output pin.

any appreciated.

1k ohm way small - check data sheet max7219, likes big resistors iset.  try 60k.


Arduino Forum > Using Arduino > LEDs and Multiplexing > MAX7219 does not respond to code written using LedControl library


arduino

Comments

Popular posts from this blog

Convierte tu Raspberry en un NAS. Firmware fvdw-sl 15.3 - Raspberry Pi Forums

How to format a Get Request

avrdude: verification error, first mismatch at byte 0x0000 0x0c != 0x62