Go Down

Topic: LED Matrix - Grundlagen? (Read 1 time) previous topic - next topic

emraharican

Nov 03, 2009, 02:26 pm Last Edit: Nov 03, 2009, 11:54 pm by emraharican Reason: 1
Hallo,
Ich bin noch ein völliger Neuling in solchen Sachen. Habe diesen Arduino 2009 und steuere derzeit eine selbstgebaute 4x4 Matrix mit 8 Pins + 1 GND an.
Könnte ich jetzt mit solchen Schieberegistern, Pins sparen und sogar einige 5x7 Teile (gibts billig auf eBay) mit einem Arduino ansteuern?
Was brauch ich denn alles um möglichst viele 5x7 matrixen anzusteuern?

10 Schieberegister: cgi.ebay.de/74HC165-8-Bit-par-EIN-ser-AUS-Schieberegister-10-Stck_W0QQitemZ160344969490QQcmdZViewItemQQptZBauteile?hash=item25554e1112
Günstige Matrix: cgi.ebay.de/Kingbright-5x7-Punktmatrix-LED-Anzei-mit-X-Y-Wahl-4x_W0QQitemZ310170494673QQcmdZViewItemQQptZBauteile?hash=item48379a26d1

(PS: Die Seite arduino.cc/playground/Main/InterfacingWithHardware kenn ich schon. Hilft mir aber nicht wirklich weiter)

Muss ich meinen bisherigen Code stark umändern wenn ich diese Schieberegister von ebay einbeziehe? Für die 5x7 Dinger von eBay müssten ja keine großen änderungen nötig sein, denke ich mal.

led.cpp
Code: [Select]
/* Driver by emraharican - 2009
*/
#include <WProgram.h>
#include "led.h"
int gnd1 =  0;
int gnd2 =  1;
int gnd3 =  2;
int gnd4 =  3;
int led1 =  4;
int led2 =  5;
int led3 =  6;
int led4 =  7;
int led0101;
int led0102;
int led0103;
int led0104;
int led0201;
int led0202;
int led0203;
int led0204;
int led0301;
int led0302;
int led0303;
int led0304;
int led0401;
int led0402;
int led0403;
int led0404;

led::led(){
 pinMode(gnd1, OUTPUT);    
 pinMode(gnd2, OUTPUT);
 pinMode(gnd3, OUTPUT);
 pinMode(gnd4, OUTPUT);
 pinMode(led1, OUTPUT);
 pinMode(led2, OUTPUT);
 pinMode(led3, OUTPUT);
 pinMode(led4, OUTPUT);
 }
 
 //<<destructor>>
led::~led(){/*nothing to destruct*/}

void led::fled0101(int st)
{
led0101 = st;
}
void led::fled0102(int st)
{
led0102 = st;
}
void led::fled0103(int st)
{
led0103 = st;
}
void led::fled0104(int st)
{
led0104 = st;
}
void led::fled0201(int st)
{
led0201 = st;
}
void led::fled0202(int st)
{
led0202 = st;
}
void led::fled0203(int st)
{
led0203 = st;
}
void led::fled0204(int st)
{
led0204 = st;
}
void led::fled0301(int st)
{
led0301 = st;
}
void led::fled0302(int st)
{
led0302 = st;
}
void led::fled0303(int st)
{
led0303 = st;
}
void led::fled0304(int st)
{
led0304 = st;
}
void led::fled0401(int st)
{
led0401 = st;
}
void led::fled0402(int st)
{
led0402 = st;
}
void led::fled0403(int st)
{
led0403 = st;
}
void led::fled0404(int st)
{
led0404 = st;
}

void led::clear()
{
led0101 = 0;
led0102 = 0;
led0103 = 0;
led0104 = 0;
led0201 = 0;
led0202 = 0;
led0203 = 0;
led0204 = 0;
led0301 = 0;
led0302 = 0;
led0303 = 0;
led0304 = 0;
led0401 = 0;
led0402 = 0;
led0403 = 0;
led0404 = 0;
}

void led::circle()
{
 led0201 = 1;
 led0301 = 1;
 led0402 = 1;
 led0403 = 1;
 led0304 = 1;
 led0204 = 1;
 led0103 = 1;
 led0102 = 1;
 }
 
void led::square()
{
led0101 = 1;
led0201 = 1;
led0301 = 1;
led0401 = 1;
led0402 = 1;
led0403 = 1;
led0404 = 1;
led0304 = 1;
led0204 = 1;
led0104 = 1;
led0103 = 1;
led0102 = 1;
}

void led::triangle()
{
led0101 = 1;
led0202 = 1;
led0303 = 1;
led0404 = 1;
led0304 = 1;
led0204 = 1;
led0104 = 1;
led0103 = 1;
led0102 = 1;
}

void led::arrow()
{
led0101 = 1;
led0202 = 1;
led0303 = 1;
led0404 = 1;
led0304 = 1;
led0204 = 1;
led0104 = 1;
led0103 = 1;
led0102 = 1;
led0203 = 1;
led0302 = 1;
led0401 = 1;
}

int gndcounter = 0;


void led::matrix()  {                  
 if (gndcounter == 4) {
   gndcounter = 0;
 }
 digitalWrite(gndcounter, HIGH);   // set the LED on
 if (gndcounter == 0)
 {
   digitalWrite(led1, led0101);
   digitalWrite(led2, led0102);
   digitalWrite(led3, led0103);
   digitalWrite(led4, led0104);
 }
 else if (gndcounter == 1)
 {
   digitalWrite(led1, led0201);
   digitalWrite(led2, led0202);
   digitalWrite(led3, led0203);
   digitalWrite(led4, led0204);
 }
 else if (gndcounter == 2)
 {
   digitalWrite(led1, led0301);
   digitalWrite(led2, led0302);
   digitalWrite(led3, led0303);
   digitalWrite(led4, led0304);
 }
 else if (gndcounter == 3)
 {
   digitalWrite(led1, led0401);
   digitalWrite(led2, led0402);
   digitalWrite(led3, led0403);
   digitalWrite(led4, led0404);
 }
 delay(1);
 digitalWrite(gndcounter, LOW);    // set the LED off
 digitalWrite(led1, LOW);
 digitalWrite(led2, LOW);
 digitalWrite(led3, LOW);
 digitalWrite(led4, LOW);
gndcounter = gndcounter + 1;
}


led.h
Code: [Select]

/*
LED Matrix 4x4
*/
#ifndef led_h
#define led_h

#include <WProgram.h>

class led
{
 public:
     led();
     ~led();
     void fled0101(int st);
     void fled0102(int st);
     void fled0103(int st);
     void fled0104(int st);
     void fled0201(int st);
     void fled0202(int st);
     void fled0203(int st);
     void fled0204(int st);
     void fled0301(int st);
     void fled0302(int st);
     void fled0303(int st);
     void fled0304(int st);
     void fled0401(int st);
     void fled0402(int st);
     void fled0403(int st);
     void fled0404(int st);
     void clear();
     void circle();
     void square();
     void triangle();
     void arrow();
     void matrix();
/* private:
   void setup();
     void loop();*/
};

#endif


Hier noch ein beispielprogramm: (es muss immer im 1-2 ms Takt die funktion led.matrix aufgerufen werden damit ein Bild aufgebaut wird)
Code: [Select]
#include <led.h>

led led;
long previousMillis = 0;
long interval = 200;
int counter = 1;
void setup(){
//Serial.begin(9600);
}

void loop(){
 if (millis() - previousMillis > interval) {
   // save the last time you blinked the LED
   previousMillis = millis();  
   
 
 //Serial.println(counter);  // prints hello with ending line break
 if (counter == 1) {
   led.fled0101(1);
 }
 else if (counter == 2) {
   led.fled0201(1);
 }
 else if (counter == 3) {
   led.fled0301(1);
 }
 else if (counter == 4) {
   led.fled0401(1);
 }
   else if (counter == 5) {
   led.fled0402(1);
 }
   else if (counter == 6) {
   led.fled0403(1);
 }
   else if (counter == 7) {
   led.fled0404(1);
 }
   else if (counter == 8) {
   led.fled0304(1);
 }
   else if (counter == 9) {
   led.fled0204(1);
 }
   else if (counter == 10) {
   led.fled0104(1);
 }
   else if (counter == 11) {
   led.fled0103(1);
 }
   else if (counter == 12) {
   led.fled0102(1);
 }
   else if (counter == 13) {
   led.fled0202(1);
 }
   else if (counter == 14) {
   led.fled0302(1);
 }
   else if (counter == 15) {
   led.fled0303(1);
 }
   else if (counter == 16) {
   led.fled0203(1);
 }
   else if (counter == 17) {
 }
   else if (counter == 18) {
 }
   else if (counter == 19) {
 }
   else if (counter == 20) {
 }
 else {
   counter = 0;
   led.clear();
 }
 counter = counter + 1;
 }
led.matrix();
}

Go Up