Hello world!
I'm a newbie and try to setup a tool to display a distance difference on a Led matrix display MAX7219 (4 modules), I want to use it to enter with the car in a narrow garage.
The 2 central modules are used to show the difference and the external modules are used to show an arrow (right or left) to suggest where to go and when diff= 0 both should show two up-arrows.
I adapted the examples included in the MD_MAX72XX library to create my program.
It works almost fine except the scrolling function: the "side arrows" are displayed but it scroll only the middle row (I get an horizontal line "scrolling" on the interested module).
When diff = 0, I do not have the up-arrows at all.
here is the code:
// Program to display analog read and animate arrow:
// two central modules to display the reading
// If > 10 then arrow left scroll on right module
// if < -10 then arrow right scroll on left module
// if between -9 and 9 then arrows up on both external module
#include <MD_MAX72xx.h>
#include <SPI.h>
// We always wait a bit between updates of the display
#define DELAYTIME 300 // in milliseconds
// Define the number of devices we have in the chain and the hardware interface
// NOTE: These pin numbers will probably not work with your hardware and may
// need to be adapted
#define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW
#define MAX_DEVICES 4
#define CLK_PIN 13 // or SCK
#define DATA_PIN 11 // or MOSI
#define CS_PIN 10 // or SS
// SPI hardware interface
MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
// Global variables
uint32_t lastTime = 0;
int diff = 0 ;
int diffcent = 0 ;
void setup() {
pinMode(A0, INPUT);
mx.begin();
Serial.begin(9600);
// use wraparound mode
mx.control(0,3,MD_MAX72XX::WRAPAROUND, MD_MAX72XX::ON);
mx.clear();
lastTime = millis();
mx.control(MD_MAX72XX::UPDATE, MD_MAX72XX::ON);
}
void showCharset(void) {
mx.clear(1,2);
mx.control(MD_MAX72XX::UPDATE, MD_MAX72XX::OFF);
char hex[3];
sprintf(hex, "%02d", abs(diffcent));
mx.clear(1);
mx.setChar((2*COL_SIZE)-2,hex[1]);
mx.clear(2);
mx.setChar((3*COL_SIZE)-3,hex[0]);
mx.control(MD_MAX72XX::UPDATE, MD_MAX72XX::ON);
}
void runArrows(void)
{
if (diffcent > 10 ) {
mx.control(MD_MAX72XX::UPDATE, MD_MAX72XX::OFF);
mx.setChar(28, 27);
mx.transform(3,3,MD_MAX72XX::TSL);
mx.control(MD_MAX72XX::UPDATE, MD_MAX72XX::ON);
mx.clear(0,0);
}
else if (diffcent < -10) {
mx.control(MD_MAX72XX::UPDATE, MD_MAX72XX::OFF);
mx.setChar(7, 26);
mx.transform(0,0,MD_MAX72XX::TSR);
mx.control(MD_MAX72XX::UPDATE, MD_MAX72XX::ON);
mx.clear(3,3);
}
else {
mx.control(MD_MAX72XX::UPDATE, MD_MAX72XX::OFF);
mx.setChar (7, ArrowUp);
mx.setChar (28, ArrowUp);
mx.transform(3,3,MD_MAX72XX::TSU);
mx.transform(0,0,MD_MAX72XX::TSU);
mx.control(MD_MAX72XX::UPDATE, MD_MAX72XX::ON);
//mx.update();
}
}
void loop() {
int diff =analogRead(A0);
diffcent = diff - 500 ;
Serial.println(diffcent);
if (millis() - lastTime >= DELAYTIME)
{
showCharset();
newArrows();
lastTime = millis();
}
}
I tried to use MD.Parola, but I was able to display only "right arrow" (26), when select other "arrows", I got blank display.
Also, because I'm using Adafruit_VL53L0X for distance measurement, it seems to me that all the libraries and the program are too big to be hosted in Arduino Uno.
Please, could you give me help ?
Probably, I have to change the way on how to load the character (arrows) to be displayed ..... I tried in different ways, but I lack of experience on how to use buffers or arrays or....
Thanks in advance for your attention and patience.
(let me know if this post is in a wrong place.....)
Maurizio.

