RGB Matrix met 74HC595 shirt register

Hardware die niet past in bovenstaande onderwerpen
Berichten: 20
Geregistreerd: 20 Mrt 2018, 21:11

RGB Matrix met 74HC595 shirt register

Berichtdoor Duckman » 01 Aug 2018, 21:27

Ik heb een RGB matrix gekocht voor mijn Arduino en ben een beetje aan het knoeien gegaan. op de volgende site staat een wiki https://wiki.52pi.com/index.php/RPI-RGB-LED-Matrix_SKU:EP-0075 Onderaan staat een arduino code die ik voorlopig even gebruik.

Deze heb ik aangepast zodat ik ook andere kleuren krijg (zie code onder). Maar kom er nog niet helemaal uit. Ik heb nu een hart die turquoise is en dan binnen groen en buiten blauw.

Waar ik niet helemaal uit kom. Dit is niet een mooie manier van kleur maken en ik kan ook niet alle mengkleuren maken. Er staat een regeltje dat je moet uitrekenen welke leds uit gaan. Maar hoe reken ik dat uit zodat ik ook andere figuurtjes kan maken, eventueel beweging.

PS code is nog niet netjes omdat ik wat zit te spelen


Code: Alles selecteren
#include <SPI.h>                  //  include the head file to enable the  library.

static uint8_t data[4] = {0x0, 0x0, 0x0, 0x0};         // defined a data matrix
static uint8_t i = 1;                                  // defined a variable vector
const int CE = 10;                                     // defined  the CE function pin
/*  VCC on VCC
 *  CLK on pin 13
 *   CE on pin 10
 * MOSI on pin 11
 *  GND on GND
 */

void heartred()                                                  // defined a function called "heart big".
{
  int j;                                                                 
  int x = 50;
  static uint8_t heart[8] = {0x00, 0x66, 0xFF, 0xFF, 0xFF, 0x7E, 0x3C, 0x18};    // you need to calculate which led should be light up by this array, it defined line by line on your matrix, for example , 0x00 means the led of the first line is off,  and the 0x66 means the second line's first led will go off and the fourth led will go off and fifth led will go off and eight led will go off. others will turn on....and so on.

  for ( j = 0; j < 8; j++)
  {
    data[0] = ~heart[j];       // color red
    data[1] = 0xFF;             // color green
    data[2] = 0xFF;             // color blue
    data[3] = 0x01 << j ;    // display the data on matrix.
    digitalWrite(CE, LOW);     // when CE is low, it begin to receive data.
    SPI.transfer(data[0]);         //transfer data[0] to the matrix(red)
    SPI.transfer(data[2]);         //transfer data[2] to the matrix(green)
    SPI.transfer(data[1]);        // transfer   data[1] to the matrix(blue)
    SPI.transfer(data[3]);      // tansfer data[3] to the matrix( scanning and display the data on matrix)
    digitalWrite(CE, HIGH);    // when CE is High, means that matrix begin to display the array's information to the matrix.
    delayMicroseconds(x);                          // a little bit delay, let the led light up and stay for a while so that it looks like it brightness.
  }
};

void heartgreen()
{
  int j;
  int x = 50;
  static uint8_t heart[8] = {0x00, 0x66, 0xFF, 0xFF, 0xFF, 0x7E, 0x3C, 0x18};
  //static uint8_t heart[8] = {0x00, 0x00, 0x24, 0x7E, 0x7E, 0x3C, 0x18, 0x00};          // change the hard to be the smaller one, all you need to do is change this parameter.
  for ( j = 0; j < 8; j++)
  {
    data[0] = 0xFF;
    data[1] = ~heart[j];
    data[2] = 0xFF;
    data[3] = 0x01 << j ;
    digitalWrite(CE, LOW);
    SPI.transfer(data[0]);
    SPI.transfer(data[2]);
    SPI.transfer(data[1]);
    SPI.transfer(data[3]);
    digitalWrite(CE, HIGH);
    delayMicroseconds(x);
  }
};

void heartblue()
{
  int j;
  int x = 50;
  static uint8_t heart[8] = {0x00, 0x66, 0xFF, 0xFF, 0xFF, 0x7E, 0x3C, 0x18};
  //static uint8_t heart[8] = {0x00, 0x00, 0x24, 0x7E, 0x7E, 0x3C, 0x18, 0x00};          // change the hard to be the smaller one, all you need to do is change this parameter.
  for ( j = 0; j < 8; j++)
  {
    data[0] = 0xFF;
    data[1] = 0xFF;
    data[2] = ~heart[j];
    data[3] = 0x01 << j ;
    digitalWrite(CE, LOW);
    SPI.transfer(data[0]);
    SPI.transfer(data[2]);
    SPI.transfer(data[1]);
    SPI.transfer(data[3]);
    digitalWrite(CE, HIGH);
    delayMicroseconds(x);
  }
};

void inv_heartblue()
{
  int j;
  int x = 50;
  static uint8_t heart[8] = {0x00, 0x66, 0xFF, 0xFF, 0xFF, 0x7E, 0x3C, 0x18};
  //static uint8_t heart[8] = {0x00, 0x00, 0x24, 0x7E, 0x7E, 0x3C, 0x18, 0x00};          // change the hard to be the smaller one, all you need to do is change this parameter.
  for ( j = 0; j < 8; j++)
  {
    data[0] = 0xFF;
    data[1] = 0xFF;
    data[2] = heart[j];
    data[3] = 0x01 << j ;
    digitalWrite(CE, LOW);
    SPI.transfer(data[0]);
    SPI.transfer(data[2]);
    SPI.transfer(data[1]);
    SPI.transfer(data[3]);
    digitalWrite(CE, HIGH);
    delayMicroseconds(x);
  }
};

void matrixoff()
{
  int j;
  int x = 50;
  static uint8_t heart[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};        // you can see, all of the led will go off here.
  for ( j = 0; j < 8; j++)
  {
    data[0] = ~heart[j];
    data[2] = ~heart[j];
    data[1] = ~heart[j];
    data[3] = 0x01 << j ;
    digitalWrite(CE, LOW);
    SPI.transfer(data[0]);
    SPI.transfer(data[2]);
    SPI.transfer(data[1]);
    SPI.transfer(data[3]);
    digitalWrite(CE, HIGH);
    delayMicroseconds(x);
  }
};

void setup() {
  pinMode(CE, OUTPUT);                          //initialized the pin's mode.
  SPI.begin();                                              // start spi function
}

void loop()                                                  //defined a loop function
{
  int m = 10;
  for ( m = 500; m > 0; m--) {                     // make a for loop to let the data displayed on the matrix.
    heartblue();
    heartgreen();
  };
  matrixoff();                                          // turn off the matrix
  delay(10);                                         // delay 100 ms
  for ( m = 500; m > 0; m--) {                 // let the data displayed on the matrix
    heartgreen();
    inv_heartblue();
    //heartgreen();
  };
  matrixoff();
  delay(10);
}
Ter Leeringe ende Vermaeck

Advertisement

Gebruikers-avatar
Berichten: 210
Geregistreerd: 03 Sep 2013, 10:03
Woonplaats: Katwijk ZH

Re: RGB Matrix met 74HC595 shirt register

Berichtdoor baco1978 » 01 Aug 2018, 22:21

wil je een ander figuurtje maken
dan kan je dat met deze matrix calculator doen

http://xlr8.at/8x8hexbin/


voor de kleurtjes gebruik je deze
data[0] = ~heart[j]; // color red
data[1] = 0xFF; // color green
data[2] = 0xFF; // color blue

voor de 3 kleuren RGB (denk ik)
https://www.rapidtables.com/convert/color/rgb-to-hex.html
Met vriendelijke groet Arjan

Terug naar Overige hardware

Wie is er online?

Gebruikers in dit forum: Geen geregistreerde gebruikers en 9 gasten