Difference between revisions of "Arduino::LEDControl"

From DiLab
Jump to: navigation, search
(New page: thumb| 8x8 LED matrica ar MAX7219 LEDControl bobliotēka - programmatūra, lai ar Arduino varetu darbinat 8x8 LED matricu, ko vada MAX7219 vai MAX7221 kontrol...)
 
Line 2: Line 2:


LEDControl bobliotēka - programmatūra, lai ar Arduino varetu darbinat 8x8 LED matricu, ko vada MAX7219 vai MAX7221 kontrolieris.
LEDControl bobliotēka - programmatūra, lai ar Arduino varetu darbinat 8x8 LED matricu, ko vada MAX7219 vai MAX7221 kontrolieris.


[https://www.dropbox.com/s/xhmao0hcd1fgd21/max7219.h?dl=1 Max7219.h] draivera kods:

//===== MAX 7219 driver ====
#include <SPI.h>
// You may redefine this pin
#ifndef
#define SS_PIN 10
#endif
// MAX7219 SPI LED Driver
#define MAX7219_TEST 0x0f // in real code put into a .h file
#define MAX7219_BRIGHTNESS 0x0a // in real code put into a .h file
#define MAX7219_SCAN_LIMIT 0x0b // in real code put into a .h file
#define MAX7219_DECODE_MODE 0x09 // in real code put into a .h file
#define MAX7219_SHUTDOWN 0x0C // in real code put into a .h file
//------------------------------------------
// Send a command to max7219
//------------------------------------------
void max72SendCMD(uint8_t address, uint8_t value) {
uint8_t i;
digitalWrite(SS_PIN, LOW);
SPI.transfer(address); // Send address.
SPI.transfer(value); // Send the value.
SPI.transfer(address); // Send address.
SPI.transfer(value); // Send the value.
digitalWrite(SS_PIN, HIGH); // Finish transfer.
}
//------------------------------------------
// Send data to two serially connected max7219 (matrices)
//------------------------------------------
void max72SendDATA(uint8_t address, uint8_t value, uint8_t v2) {
uint8_t i;
digitalWrite(SS_PIN, LOW);
SPI.transfer(address); // Send address.
SPI.transfer(value); // Send the value.
SPI.transfer(address); // Send address.
SPI.transfer(v2); // Send the value.
digitalWrite(SS_PIN, HIGH); // Finish transfer.
}
//------------------------------------------
// Call this from setup()
//------------------------------------------
void max72Init()
{
pinMode(SS_PIN, OUTPUT);
SPI.setBitOrder(MSBFIRST); // Reverse the SPI Data o/p.
SPI.begin(); // Start SPI
// Run test - All LED segments lit.
max72SendCMD(MAX7219_TEST, 0x01); delay(1000);
max72SendCMD(MAX7219_TEST, 0x00); // Finish test mode.
max72SendCMD(MAX7219_DECODE_MODE, 0x00); // Disable BCD mode.
max72SendCMD(MAX7219_BRIGHTNESS, 0x00); // Use lowest intensity.
max72SendCMD(MAX7219_SCAN_LIMIT, 0x0f); // Scan all digits.
max72SendCMD(MAX7219_SHUTDOWN, 0x01); // Turn on chip.
}
//================



Piemērs programmai, kas izspīdina nejaušus punktus uz LED matricas

Revision as of 09:00, 29 October 2016

8x8 LED matrica ar MAX7219

LEDControl bobliotēka - programmatūra, lai ar Arduino varetu darbinat 8x8 LED matricu, ko vada MAX7219 vai MAX7221 kontrolieris.


Max7219.h draivera kods:

//===== MAX 7219 driver ====

#include <SPI.h>

// You may redefine this pin
#ifndef
#define SS_PIN 10
#endif

// MAX7219 SPI LED Driver
#define MAX7219_TEST 0x0f // in real code put into a .h file
#define MAX7219_BRIGHTNESS 0x0a // in real code put into a .h file
#define MAX7219_SCAN_LIMIT 0x0b // in real code put into a .h file
#define MAX7219_DECODE_MODE 0x09 // in real code put into a .h file
#define MAX7219_SHUTDOWN 0x0C // in real code put into a .h file

//------------------------------------------
// Send a command to max7219
//------------------------------------------
void max72SendCMD(uint8_t address, uint8_t value) {  
  uint8_t i;
  digitalWrite(SS_PIN, LOW);   
  SPI.transfer(address);      // Send address.
  SPI.transfer(value);        // Send the value.
  SPI.transfer(address);      // Send address. 
  SPI.transfer(value);        // Send the value.
  digitalWrite(SS_PIN, HIGH); // Finish transfer.
}

//------------------------------------------
// Send data to two serially connected max7219 (matrices)
//------------------------------------------
void max72SendDATA(uint8_t address, uint8_t value, uint8_t v2) {  
  uint8_t i;
  digitalWrite(SS_PIN, LOW);   
  SPI.transfer(address);      // Send address.
  SPI.transfer(value);        // Send the value.
  SPI.transfer(address);      // Send address. 
  SPI.transfer(v2);           // Send the value.
  digitalWrite(SS_PIN, HIGH); // Finish transfer.
}

//------------------------------------------
// Call this from setup()
//------------------------------------------
void max72Init()
{
  pinMode(SS_PIN, OUTPUT);  

  SPI.setBitOrder(MSBFIRST);   // Reverse the SPI Data o/p. 
  SPI.begin();                 // Start SPI

  // Run test - All LED segments lit. 
  max72SendCMD(MAX7219_TEST, 0x01);  delay(1000);  
  max72SendCMD(MAX7219_TEST, 0x00);        // Finish test mode.
  max72SendCMD(MAX7219_DECODE_MODE, 0x00); // Disable BCD mode. 
  max72SendCMD(MAX7219_BRIGHTNESS, 0x00);  // Use lowest intensity. 
  max72SendCMD(MAX7219_SCAN_LIMIT, 0x0f);  // Scan all digits.
  max72SendCMD(MAX7219_SHUTDOWN, 0x01);    // Turn on chip.
}
//================


Piemērs programmai, kas izspīdina nejaušus punktus uz LED matricas