Controlando “infinitos” LEDs com Arduino III



Abaixo, a imagem das protoboards (foi necessário usar 2) com os CI conectados aos LEDs. Estou elaborando o projeto de uma placa para substituir as protoboards.


Os fios dos LEDs foram escolhidos conforme as cores destes. Existem também alguns outros fios de outros sensores que eu usei, falarei sobre eles em um outro post.

Uma outra coisa interessante a respeito desse CI é que ele pode operar muito rápido, até 100 Mhz. Isso é muito mais rápido do que o Arduino pode fazer, o que significa que, usando PWM, a gente poderia até controlar a intensidade de brilho dos LEDs. A lib que eu vou descrever abaixo não tem essa feature, mas é fácil de fazer. Numa versão 2.0 eu pretendo implementar isso. Se alguém quiser contribuir, é só me avisar e eu compartilho o projeto lá no Google Code.

O Software

Para gerenciar os LEDs, criei uma lib do Arduino.Para saber como criar uma, clique aqui para maiores detalhes em português ou aqui para texto em inglês do site do Arduino.

O projeto está hospedado no Google Code e vc pode pegar a última versão por aqui.

A interface (parte pública da lib) é a seguinte:

class LEDMatrix595  
 {  
   public:  
 // Constructor  
 //  int _LEDCount: number of LEDs to be managed  
 //  int _clockPin: number of Arduino port that´s connected the clock pin of the first 595 CI (CI pin 12)  
 //  int _latchPin: number of Arduino port that´s connected the latch pin of the first 595 CI (CI pin 11)  
 //  int _dataPin: number of Arduino port that´s connected the data pin of the first 595 CI (CI pin 14)  
    LEDMatrix595(int _LEDCount, int _clockPin, int _latchPin, int _dataPin);  
 //  color constants   
    int red;  
    int green;  
    int blue;  
 //  set the corresponding LED mask (from now on, it will be considered common cathod)  
    void setLEDMask(byte LED);  
 //  switch on the RGB LED corresponding colors     
    void LEDOn(byte LED, byte color);  
 //  switch off the RGB LED corresponding colors     
    void LEDOff(byte LED);  
 //  send LEDs to CIs  
    void sendLEDs();  
 //  switch off all LEDs  
    void allLEDsOff();  
 //  print LED Matriz to the serial port in binary mode, in a way to debug  
    void printMatrix();  
 //  print LED Mask to the serial port in binary mode, in a way to debug  
    void printLEDMask();  
 //  if true, it wil print matrix in serial port  
    int debug;  //Indicates debug mode        
 // Keep led values  
 //           LED mask: each number indicates where the corresponding LED data will be stored  
 //                    0 1 2 3    4  5  6    7  8    9  0  1    2  3  4    5  6    7  8  9    0  1  2    3  4  5    6  
byte matrix[10]; //= {B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000};  
 // Stores a mask indicting when a LED is common-positive (000) or common-negative (111)  
    byte LEDMask[10];//= {B00000000,B00000000,B00111111,B11111100,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000};  
   private:  
    int LEDCount; //Number of LEDs to manage   
    int CI595Count;//Number of 74HC595 necessary to manage the LEDs    
    int clockPin; //Pin connected to Pin 11 of 74HC595 (Clock)  
    int latchPin; //Pin connected to Pin 12 of 74HC595 (Latch)  
    int dataPin;  //Pin connected to Pin 14 of 74HC595 (Data)   
    void shiftOut(byte dataOut);  
    void internalPrintMatrix(byte _matrix[]);  
    void internalLEDOn(byte _matrix[], byte ledNo, byte color);  
    void internalLEDOff(byte _matrix[], byte ledNo);  
    void clearMatrix(byte _matrix[]);  
 };  

Comentários

Postagens mais visitadas deste blog

Controle PID de Potência em Corrente Alternada - Arduino e TRIAC - Parte III

Dividindo um programa (sketch) do Arduino em mais de um arquivo

Controle PID de Potência em Corrente Alternada - Arduino e TRIAC - Parte I