Pages: [1] 2   Go Down
Author Topic: please help with code  (Read 801 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

#include <avr/pgmspace.h>

#define COLUMN 8        // Anzahl der Spalten
#define PLANE 5         // Anzahl der Ebenen
#define PLANETIME 3333  // Anzeigedauer einer Ebene
#define TIMECONST 15    // Multiplikator für Anzeigedauer eines Bildes (33 LEDs)

// LED Muster: Eine Zeile besteht aus den 5 Ebenen mit je 8 LEDs (außer Ebene 5 mit einer LED) und der Anzeigedauer
prog_uchar PROGMEM PatternTable[] = {
B11111111, B11111111, B11111111, B11111111, B1, 5,  // Alle LEDs an
B00000000, B00000000, B00000000, B00000000, B0, 1,  // Alle LEDs aus
B11111111, B11111111, B11111111, B11111111, B1, 5,
B00000000, B00000000, B00000000, B00000000, B0, 10,
// Bei Anzeigedauer 0 endet die Schleife
B00000000, B00000000, B00000000, B00000000, B0, 0
};

// Definition der Pins für Ebenen und Spalten (hängt davon ab, wie man sie verlötet hat)
int LedPin[] = {7, 8, 6, 9, 10, 11, 12, 5};
int PlanePin[] = {18, 17, 16, 15, 14};

void setup()
{
   int pin;
   // Pins als OUTPUT initialiseren
   for (pin=0; pin<COLUMN; pin++) {
      pinMode( LedPin[pin], OUTPUT );
   }

   for (pin=0; pin<PLANE; pin++) {
      pinMode( PlanePin[pin], OUTPUT );
   }
}

void loop()
{
   byte PatternBuf[PLANE]; // speichert eine Zeile aus LED Muster
   int PatternIdx;
   byte DisplayTime;
   unsigned long EndTime;
   int plane;
   int patbufidx;
   int ledpin;
   
   // Index in LED Muster setzen
   PatternIdx = 0;
   // Wiederholen solange Anzeigedauer > 0
   do {
      // Zeile aus LED Muster lesen
      memcpy_P( PatternBuf, PatternTable+PatternIdx, PLANE );
      PatternIdx += PLANE;
      // Anzeigedauer lesen
      DisplayTime = pgm_read_byte_near( PatternTable + PatternIdx++ );
      // Anzeigedauer für Bild berechnen
      EndTime = millis() + ((unsigned long) DisplayTime) * TIMECONST;
      
      // LEDs der Ebenen immer wieder aufbauen, solange Anzeigedauer für Bild noch nicht erreicht ist
      while ( millis() < EndTime ) {
         patbufidx = 0; // Am Anfang der Zeile beginnen
         // Schleife über Ebenen
         for (plane=0; plane<PLANE; plane++) {
            // vorherige Ebene ausschalten
            if (plane==0) {
              digitalWrite( PlanePin[PLANE-1], HIGH );
            } else {
              digitalWrite( PlanePin[plane-1], HIGH );
            }
      
            // Spalten der aktuelle Ebene setzen

            // Ebene 5 gesondert behandeln, da nur eine LED
             if (plane==PLANE-1) {
                digitalWrite( LedPin[0], PatternBuf[plane] );
                                } else {
                // Einzelne Spalten setzen
                                   for (ledpin=0; ledpin<COLUMN; ledpin++) {
                  // Bitoperation zur Ermittlung der einzelnen Bitwerte
                  // Beispiel:
                  // LED Zeile & ledpin (left shift (<<) schiebt ledpin um 1 nach rechts)
                  // B01010000 & B10000000 = 0 (LED leuchtet nicht)
                  // B01010000 & B01000000 = 1 (LED leuchtet)
                  // B01010000 & B00100000 = 0 (LED leuchtet nicht)
                   digitalWrite( LedPin[ledpin], PatternBuf[plane] & (1 << ledpin) );
                }
                                }
      
            // aktuelle Ebene aktivieren
            digitalWrite( PlanePin[plane], LOW );
            // Anzeigedauer für Ebene
            delayMicroseconds( PLANETIME );
         }
      }
   } while (DisplayTime > 0);
}




i uploaded the file to the atmega328 arduinoBoardDuemilanove and all it does it keeps blinking on off.please help.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 168
Posts: 12425
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Please modify your post, select the code and press the # button so the code get tagged properly,
thank you
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 45987
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
i uploaded the file to the atmega328 arduinoBoardDuemilanove and all it does it keeps blinking on off.please help.
You uploaded code to blink LEDs, and all the LEDs do is blink. And the problem is?

What do you expect this code to do? What does it actually do?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
#include <avr/pgmspace.h>

#define COLUMN 8        // Anzahl der Spalten
#define PLANE 5         // Anzahl der Ebenen
#define PLANETIME 3333  // Anzeigedauer einer Ebene
#define TIMECONST 15    // Multiplikator für Anzeigedauer eines Bildes (33 LEDs)

// LED Muster: Eine Zeile besteht aus den 5 Ebenen mit je 8 LEDs (außer Ebene 5 mit einer LED) und der Anzeigedauer
prog_uchar PROGMEM PatternTable[] = {
B11111111, B11111111, B11111111, B11111111, B1, 5,  // Alle LEDs an
B00000000, B00000000, B00000000, B00000000, B0, 1,  // Alle LEDs aus
B11111111, B11111111, B11111111, B11111111, B1, 5,
B00000000, B00000000, B00000000, B00000000, B0, 10,
// Bei Anzeigedauer 0 endet die Schleife
B00000000, B00000000, B00000000, B00000000, B0, 0
};

// Definition der Pins für Ebenen und Spalten (hängt davon ab, wie man sie verlötet hat)
int LedPin[] = {7, 8, 6, 9, 10, 11, 12, 5};
int PlanePin[] = {18, 17, 16, 15, 14};

void setup()
{
int pin;
// Pins als OUTPUT initialiseren
for (pin=0; pin<COLUMN; pin++) {
pinMode( LedPin[pin], OUTPUT );
}

for (pin=0; pin<PLANE; pin++) {
pinMode( PlanePin[pin], OUTPUT );
}
}

void loop()
{
byte PatternBuf[PLANE]; // speichert eine Zeile aus LED Muster
int PatternIdx;
byte DisplayTime;
unsigned long EndTime;
int plane;
int patbufidx;
int ledpin;

// Index in LED Muster setzen
PatternIdx = 0;
// Wiederholen solange Anzeigedauer > 0
do {
// Zeile aus LED Muster lesen
memcpy_P( PatternBuf, PatternTable+PatternIdx, PLANE );
PatternIdx += PLANE;
// Anzeigedauer lesen
DisplayTime = pgm_read_byte_near( PatternTable + PatternIdx++ );
// Anzeigedauer für Bild berechnen
EndTime = millis() + ((unsigned long) DisplayTime) * TIMECONST;

// LEDs der Ebenen immer wieder aufbauen, solange Anzeigedauer für Bild noch nicht erreicht ist
while ( millis() < EndTime ) {
patbufidx = 0; // Am Anfang der Zeile beginnen
// Schleife über Ebenen
for (plane=0; plane<PLANE; plane++) {
// vorherige Ebene ausschalten
if (plane==0) {
  digitalWrite( PlanePin[PLANE-1], HIGH );
} else {
  digitalWrite( PlanePin[plane-1], HIGH );
}

// Spalten der aktuelle Ebene setzen

// Ebene 5 gesondert behandeln, da nur eine LED
  if (plane==PLANE-1) {
    digitalWrite( LedPin[0], PatternBuf[plane] );
                                } else {
    // Einzelne Spalten setzen
                                   for (ledpin=0; ledpin<COLUMN; ledpin++) {
      // Bitoperation zur Ermittlung der einzelnen Bitwerte
      // Beispiel:
      // LED Zeile & ledpin (left shift (<<) schiebt ledpin um 1 nach rechts)
      // B01010000 & B10000000 = 0 (LED leuchtet nicht)
      // B01010000 & B01000000 = 1 (LED leuchtet)
      // B01010000 & B00100000 = 0 (LED leuchtet nicht)
        digitalWrite( LedPin[ledpin], PatternBuf[plane] & (1 << ledpin) );
    }
                                }

// aktuelle Ebene aktivieren
digitalWrite( PlanePin[plane], LOW );
// Anzeigedauer für Ebene
delayMicroseconds( PLANETIME );
}
}
} while (DisplayTime > 0);
}



this is basically a led tree with 5 plane and 8 columns..this is supposed to have diff effects..please have a look at this http://m12s23.vlinux.de/mediawiki/index.php/Xmastree
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 45987
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
this is basically a led tree with 5 plane and 8 columns..this is supposed to have diff effects.
OK. So what do you expect the code to do? What does is ACTUALLY do? How does what it actually does differ from what you want?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset



follow the link and this is what its supposed to do.all it does is blink the leds on and off after i uploaded the file to the arduino board.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 45987
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
all it does is blink the leds on and off after i uploaded the file to the arduino board.
Code:
prog_uchar PROGMEM PatternTable[] = {
B11111111, B11111111, B11111111, B11111111, B1, 5,  // Alle LEDs an
B00000000, B00000000, B00000000, B00000000, B0, 1,  // Alle LEDs aus
B11111111, B11111111, B11111111, B11111111, B1, 5,
B00000000, B00000000, B00000000, B00000000, B0, 10,
// Bei Anzeigedauer 0 endet die Schleife
B00000000, B00000000, B00000000, B00000000, B0, 0
};
All you have defined for the patterns is either all on or all off. I don't know how/why you expect to see different patterns.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Please modify your post, select the code and press the # button so the code get tagged properly,
thank you


please help as i am struggling with this for a month now..
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
all it does is blink the leds on and off after i uploaded the file to the arduino board.
Code:
prog_uchar PROGMEM PatternTable[] = {
B11111111, B11111111, B11111111, B11111111, B1, 5,  // Alle LEDs an
B00000000, B00000000, B00000000, B00000000, B0, 1,  // Alle LEDs aus
B11111111, B11111111, B11111111, B11111111, B1, 5,
B00000000, B00000000, B00000000, B00000000, B0, 10,
// Bei Anzeigedauer 0 endet die Schleife
B00000000, B00000000, B00000000, B00000000, B0, 0
};
All you have defined for the patterns is either all on or all off. I don't know how/why you expect to see different patterns.


if you look at the code after this it does different patterns i suppose..
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 64
Posts: 6889
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

No it does not. There are only 5 sequences and they are on, off, on, off, off. I don't think you understand the code that well. The following section dictates how the tree is lit:

Code:
prog_uchar PROGMEM PatternTable[] = {
B11111111, B11111111, B11111111, B11111111, B1, 5,  // Alle LEDs an
B00000000, B00000000, B00000000, B00000000, B0, 1,  // Alle LEDs aus
B11111111, B11111111, B11111111, B11111111, B1, 5,
B00000000, B00000000, B00000000, B00000000, B0, 10,
// Bei Anzeigedauer 0 endet die Schleife
B00000000, B00000000, B00000000, B00000000, B0, 0
};

Again on, off, on, off, off. If you want the tree lit differently, modify the above to different stuff.

I google translated the instruction:

"LED Muster: Eine Zeile besteht aus den 5 Ebenen mit je 8 LEDs (außer Ebene 5 mit einer LED) und der Anzeigedauer"

LED pattern: A line consists of five levels, each with 8 LEDs (except level 5 with an LED) and the display time

The first 4 numbers control the bottom 4 lever, the 5th number controls the one LED on the top, the 6th number is time this pattern is lit.

To indicate the end of loop, set 0 to time:

"Bei Anzeigedauer 0 endet die Schleife"

At display time 0 ends the loop

So change the first 4 lines of the PROGMEM code and you will see different patterns. Add more if you want but don't remove the last line of the PROGMEM code.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No it does not. There are only 5 sequences and they are on, off, on, off, off. I don't think you understand the code that well. The following section dictates how the tree is lit:

Code:
prog_uchar PROGMEM PatternTable[] = {
B11111111, B11111111, B11111111, B11111111, B1, 5,  // Alle LEDs an
B00000000, B00000000, B00000000, B00000000, B0, 1,  // Alle LEDs aus
B11111111, B11111111, B11111111, B11111111, B1, 5,
B00000000, B00000000, B00000000, B00000000, B0, 10,
// Bei Anzeigedauer 0 endet die Schleife
B00000000, B00000000, B00000000, B00000000, B0, 0
};

Again on, off, on, off, off. If you want the tree lit differently, modify the above to different stuff.

I google translated the instruction:

"LED Muster: Eine Zeile besteht aus den 5 Ebenen mit je 8 LEDs (außer Ebene 5 mit einer LED) und der Anzeigedauer"

LED pattern: A line consists of five levels, each with 8 LEDs (except level 5 with an LED) and the display time

The first 4 numbers control the bottom 4 lever, the 5th number controls the one LED on the top, the 6th number is time this pattern is lit.

To indicate the end of loop, set 0 to time:

"Bei Anzeigedauer 0 endet die Schleife"

At display time 0 ends the loop

So change the first 4 lines of the PROGMEM code and you will see different patterns. Add more if you want but don't remove the last line of the PROGMEM code.

after this there is a void set up and void loop..what is this for..
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24308
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
after this there is a void set up and void loop..what is this for..
To set-up the I/O pins and run the sequence.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
after this there is a void set up and void loop..what is this for..
To set-up the I/O pins and run the sequence.

so basically that does  not do anythn like it shows in the video.how do i make different patterns any idea.i dont know much about programming..
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24308
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You need to change the ones and zeros in "PatternTable", but don't change anything in the very last entry in the table.
Try:
Code:
prog_uchar PROGMEM PatternTable[] = {
0x55, 0xAA, 0x55, 0xAA, 1, 5,
0x33, 0xCC, 0x33, 0x33, 0, 1, 
0x81, 0x7E, 0x81, 0x7E, 1, 5,
0xAA, 0x55, 0xAA, 0x55, 0, 10,
//
0, 0, 0, 0, 0, 0   // don't change this
};
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You need to change the ones and zeros in "PatternTable", but don't change anything in the very last entry in the table.
Try:
Code:
prog_uchar PROGMEM PatternTable[] = {
0x55, 0xAA, 0x55, 0xAA, 1, 5,
0x33, 0xCC, 0x33, 0x33, 0, 1, 
0x81, 0x7E, 0x81, 0x7E, 1, 5,
0xAA, 0x55, 0xAA, 0x55, 0, 10,
//
0, 0, 0, 0, 0, 0   // don't change this
};


will try it sir thank you so much.. smiley.if i want to add more how must i continue..
Logged

Pages: [1] 2   Go Up
Jump to: