/* Example code for scrolling text effect on MAX7219 LED dot matrix display with Arduino. more info https://diyprojectslab.com/*/
// Include the required Arduino libraries:
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
// Define hardware type, size, and output pins:
#define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW
#define MAX_DEVICES 8
#define CS_PIN 10
#define DATA_PIN 11
#define CLK_PIN 13
// these constants won't change. They are the lowest and highest readings you
// get from your sensor:
const int sensorMin = 0; // sensor minimum, discovered through experiment
const int sensorMax = 1023; // sensor maximum, discovered through experiment
// Create a new instance of the MD_Parola class with hardware SPI connection:
//MD_Parola myDisplay = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
// Setup for software SPI:
MD_Parola myDisplay = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
void setup() {
// Intialize the object:
myDisplay.begin();
// Set the intensity (brightness) of the display (0-15):
myDisplay.setIntensity(0);
// Clear the display:
myDisplay.displayClear();
// read the sensor:
int sensorReading = analogRead(A0);
// map the sensor range to a range of four options:
int range = map(sensorReading, sensorMin, sensorMax, 0, 3);
// do something different depending on the range value:
switch (range) {
case 0: // your hand is on the sensor
myDisplay.displayText("Low", PA_CENTER, 40, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT); //(Text, Letak, speed)
break;
case 1: // your hand is close to the sensor
myDisplay.displayText("Medium", PA_CENTER, 40, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT); //(Text, Letak, speed)
break;
case 2: // your hand is a few inches from the sensor
myDisplay.displayText("High", PA_CENTER, 40, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT); //(Text, Letak, speed)
break;
case 3: // your hand is nowhere near the sensor
myDisplay.displayText("Upper", PA_CENTER, 40, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT); //(Text, Letak, speed)
break;
}
}
void loop() {
if (myDisplay.displayAnimate()) {
myDisplay.displayReset();
}
}