// Program to exercise the MD_MAX72XX library
//
// Test the library transformation functions
#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);
// Arbitrary pins
//MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, DATA_PIN, CLK_PIN, 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(115200);
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);
//mx.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.update();
// delay(DELAYTIME*2);
mx.control(MD_MAX72XX::UPDATE, MD_MAX72XX::ON);
//mx.update(MD_MAX72XX::ON);
}
void runArrows(void)
{
if (diffcent > 10 ) {
mx.control(MD_MAX72XX::UPDATE, MD_MAX72XX::OFF);
mx.setChar(28, 27);
mx.control(MD_MAX72XX::UPDATE, MD_MAX72XX::ON);
mx.transform(3,3,MD_MAX72XX::TSL);
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, 24);
mx.setChar (29, 24);
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) / 10 ;
Serial.println(diffcent);
if (millis() - lastTime >= DELAYTIME)
{
showCharset();
runArrows();
//delay(200);
lastTime = millis();
}
}