Pages: [1]   Go Down
Author Topic: very new, where do i begin  (Read 391 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 1
Posts: 41
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hello
I have a basic kit which I would like to use to make a game. the game is basically a line of leds progressing down across the 8x8 max7219 display, at the other end is a single led that can be controlled left to right. a single button will fire a missile at the descending led line and remove what ever it hits.
I have the arduino that came with the Franzis starter kit. I have some very basic understanding of programming but I cant get the ledcontroller.h to work properly. I have been able to download the example which is for the 5x7 display. I have tried to take from that and modify but with no luck. I have a book called arduino workshop which has the matrix but without the max driver. so that's no good. I have read some of the posts of others and information about the led controller.h but had no luck understanding it. I have tried mucking about with some basic code but don't understand it. I don't understand the [8] part, the byte = {B00111001}, the (0,1,a[8]);, im guessing the [8] has to do with one side of the display, the byte = im not sure of and the (0,1,a[8]) is probably column row byte a with 8 bits.
I cant get a line of leds, then I would like to make them move. I think this would be something like (count 0, <0, ++1) or something, which I think means, start at zero, if its less then zero increase by one. this is how I would get the leds to descend. again im guessing.
if anyone could please help I would appreciate it.
many thanks
simon
Logged

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 118
Posts: 4554
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The MAX7219 is a very common chip.

Google for "arduino max7219" generates 66000 hits.
Logged

No, I don't answer questions sent in private messages...

Offline Offline
Newbie
*
Karma: 1
Posts: 41
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i have noticed that there are a lot of pages with information about the chip. I cant find anything that will help with the bar that I want to create. I have tried modifying programs with no luck. I thought that an array may help but I cant get that to work. I want to make use of the ledcontrol.h library as that seems to have been made specifically for this chip. I have tried programs that use sprite, whatever that is.
I can get a flashing bar, almost across the screen. I cant make it move though. I want it to descend. just an idea would help. I don't expect someone to program this thing. I just need a push in the right direction.
I cant find information about lighting groups of leds on this chip.
any help would be appreciated
Logged

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 118
Posts: 4554
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Try google "arduino max7219 game"
Logged

No, I don't answer questions sent in private messages...

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 509
Posts: 31462
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

To make a display move you have to send it a whole lot of new data with the bar in a diffrent position.
If you post the code that dosn't work maybe we could point out where you are going wrong.
Logged

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

I have tried mucking about with some basic code but don't understand it

A good place to start learning how to control an  8 * 8 LED matrix with a Max7219 is here
 About halfway down the page is controlling a Led matrix
Pedro
Logged


NSW Australia
Offline Offline
Edison Member
*
Karma: 34
Posts: 2349
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The MAX7219 module in the kit should be a standard design.  This means at this point you do not need to know anything about wiring of the MAX7219, only how or where to wire the three control wires to the module,

Would you care to try a simple sketch with which I have been working?  It uses no library, so should work straight off.  Just use the three pin numbers cited in the code - or change them to those you are presently using.

If it works - and it certainly should - you can then try changing the parameters, understanding the functions, and writing your own from them.

Code:
/* code for MAX7219 from maxim,
reduced and optimised for using more then one 7219 in a row,
______________________________________
General notes:

-if you are only using one max7219, then use the function maxSingle to control
 the little guy ---maxSingle(register (1-8), collum (0-255))

-if you are using more then one max7219, and they all should work the same,
then use the function maxAll ---maxAll(register (1-8), collum (0-255))

-if you are using more than one max7219 and just want to change something
at one little guy, then use the function maxOne
---maxOne(Max you want controll (1== the first one), register (1-8),
column (0-255))

/* During initiation, be sure to send every part to every max7219 and then
 upload it.
For example, if you have five max7219's, you have to send the scanLimit 5 times
before you load it-- other wise not every max7219 will get the data. the
function maxInUse  keeps track of this, just tell it how many max7219 you are
using.
*/

int dataIn = 2;            // "DIN" on module
int load = 3;              // "CS" on module
int clock = 4;             // ""CLK" on module
const int ledPin =  13;    // the number of the LED pin

int maxInUse = 1;    //change this variable to set how many MAX7219's you'll use
int ledState = LOW;        // ledState used to set the LED

int e = 0;                 // just a variable

                     // define max7219 registers
byte max7219_reg_noop        = 0x00;
byte max7219_reg_digit0      = 0x01;
byte max7219_reg_digit1      = 0x02;
byte max7219_reg_digit2      = 0x03;
byte max7219_reg_digit3      = 0x04;
byte max7219_reg_digit4      = 0x05;
byte max7219_reg_digit5      = 0x06;
byte max7219_reg_digit6      = 0x07;
byte max7219_reg_digit7      = 0x08;
byte max7219_reg_decodeMode  = 0x09;
byte max7219_reg_intensity   = 0x0a;
byte max7219_reg_scanLimit   = 0x0b;
byte max7219_reg_shutdown    = 0x0c;
byte max7219_reg_displayTest = 0x0f;



void putByte(byte data) {
  byte i = 8;
  byte mask;
  while(i > 0) {
    mask = 0x01 << (i - 1);      // get bitmask
    digitalWrite( clock, LOW);   // tick
    if (data & mask){            // choose bit
      digitalWrite(dataIn, HIGH);// send 1
    }else{
      digitalWrite(dataIn, LOW); // send 0
    }
    digitalWrite(clock, HIGH);   // tock
    --i;                         // move to lesser bit
  }
}

void maxSingle( byte reg, byte col) {   
//maxSingle is the "easy"  function to use for a     //single max7219

  digitalWrite(load, LOW);       // begin     
  putByte(reg);                  // specify register
  putByte(col);        //((data & 0x01) * 256) + data >> 1); // put data   
  digitalWrite(load,HIGH);
}

void maxAll( byte reg, byte col) {    // initialize  all  MAX7219's in the system
  int c = 0;
  digitalWrite(load, LOW);  // begin     
  for ( c =1; c<= maxInUse; c++) {
  putByte(reg);                  // specify register
  putByte(col);             //((data & 0x01) * 256) + data >> 1); // put data
    }
  digitalWrite(load,HIGH);
}

void maxOne(byte maxNr, byte reg, byte col) {   
//maxOne is for adressing different MAX7219's,
//while having a couple of them cascaded

  int c = 0;
  digitalWrite(load, LOW);  // begin     

  for ( c = maxInUse; c > maxNr; c--) {
    putByte(0);    // means no operation
    putByte(0);    // means no operation
  }

  putByte(reg);  // specify register
  putByte(col);//((data & 0x01) * 256) + data >> 1); // put data

  for ( c = maxNr-1; c >= 1; c--) {
    putByte(0);    // means no operation
    putByte(0);    // means no operation
  }

  digitalWrite(load,HIGH);
}

void putCol( byte colno, byte coldat) {
// Interprets colno as (zero ref) index in combined array
    byte t;
    t = colno >> 3;
    byte u;
    u = colno & 0x07;
    maxOne(t+1, u+1, coldat);
}


void dispon () {
 maxAll(max7219_reg_shutdown, 0x01);               // Display on


void dispoff () {
 maxAll(max7219_reg_shutdown, 0x00);              // Display off


byte irow = 0;          // Row index
byte icol = 0;          // Column index
byte pattern;           // bit mask
byte lcol;              // left border
byte rcol;              // right border
byte trow;              // top row marker
byte brow;              // bottom row marker

int s_vert;             // Vertical switch
int s_horz;             // Horizontal switch

// the follow variable is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 40;           // interval at which to blink (milliseconds)
long previousMillis = 0;      // will store last time LED was updated
int scantype = 0;             // switch mode

void worker () {

  if (pattern == 0) pattern = trow;            // pattern must be set
  if (s_vert != 0) {
    if (s_vert == -1) {                     // moving upward
      pattern = pattern >> 1;
      if (pattern == trow) {                   // hit the top
        s_vert = 0; s_horz = 1;
      }
    } else {
      pattern = pattern << 1;               // moving downward
      if (pattern == brow) {                // hit the bottom
        s_vert = 0; s_horz = -1;
      }
    }
    putCol(icol,pattern);              // Show the column.
    return;
  }

  if (s_horz != 0) {
    putCol(icol,0);                    // blank previous column.
    if (s_horz == -1) {                     // moving left
      icol--;
      if (icol == lcol) {                      // hit the side
        s_horz = 0; s_vert = -1;
      }
    } else {
      icol++;                               // moving right
      if (icol == rcol) {                      // hit the side
        s_horz = 0; s_vert = 1;
      }
    }
    putCol(icol,pattern);              // Show the column.
  }
 }
 

void setup () {

  pinMode(dataIn, OUTPUT);
  pinMode(clock,  OUTPUT);
  pinMode(load,   OUTPUT);
  pinMode(ledPin, OUTPUT);     

  //Serial begin(9600);
  digitalWrite(13, HIGH); 

//initiation of the max 7219
  maxAll(max7219_reg_displayTest, 0x00); // no display test
  maxAll(max7219_reg_scanLimit, 0x07);     
  maxAll(max7219_reg_decodeMode, 0x00);  // using an led matrix (not digits)
  maxAll(max7219_reg_shutdown, 0x01);    // not in shutdown mode
  for (e=1; e<=8; e++) {        // empty registers, turn all LEDs off
    maxAll(e,0);
  }
  maxAll(max7219_reg_intensity, 0x08 & 0x0f);    // the first 0x0f is the value you can set
                                                 // range: 0x00 to 0x0f
                                                 
  pattern = 0;
  scantype = 0;
  s_vert = 0;
  s_horz = 1;
  lcol = 1;              // left border
  rcol = 6;              // right border
  trow = 0x02;           // top row marker
  brow = 0x40;           // bottom row marker     
     


void loop () {

  unsigned long currentMillis = millis();
 
  if(currentMillis - previousMillis > interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;   

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW) {
      ledState = HIGH;
    }
    else {
      ledState = LOW;

    // Alternate 2
    // set the LED with the ledState of the variable:
    // Timed process:
   
    worker();
    }
    digitalWrite(ledPin, ledState);
    }
}
Logged

Pages: [1]   Go Up
Jump to: