/***********************************************************************************
यह Arduino स्केच स्क्रॉलिंग चार्ट प्रदर्शित करने के लिए MD_MAX72XX लाइब्रेरी का उपयोग करता है। चार्ट को MODE_SWITCH पिन से
जुड़े स्विच का उपयोग करके लाइन चार्ट और बार चार्ट के बीच स्विच किया जा सकता है। स्विच इनपुट को संभालने के
लिए MD_UIswitch लाइब्रेरी का उपयोग किया जाता है।
कोड में डिबगिंग विकल्प शामिल हैं, जिन्हें डीबग चर को बदलकर सक्षम या अक्षम किया जा सकता है। यदि डीबग 1 पर सेट है,
तो डीबगिंग आउटपुट सीरियल मॉनिटर पर मुद्रित किया जाएगा।
हार्डवेयर कॉन्फ़िगरेशन MD_MAX72xx हार्डवेयर परिभाषाओं और ऑब्जेक्ट का उपयोग कर निर्दिष्ट किया गया है।
श्रृंखला में उपकरणों की संख्या, साथ ही एसपीआई पिन (CLK_PIN, DATA_PIN और CS_PIN), स्केच में परिभाषित किए गए हैं।
स्केच में कई कार्य शामिल हैं:
graphDisplay: यह फ़ंक्शन स्क्रॉलिंग चार्ट प्रदर्शित करने के लिए जिम्मेदार है। यह दो पैरामीटर लेता है,
(एक बूलियन इंगित करता है कि क्या प्रदर्शन शुरू किया जा रहा है) और (चार्ट प्रकार का प्रतिनिधित्व करने वाला
एक पूर्णांक: निरंतर प्रदर्शन के लिए 0, यादृच्छिक ऊंचाई के लिए 1,
और बार चार्ट के लिए 2)। यह निर्दिष्ट प्रकार के आधार पर चार्ट प्रदर्शन को नए बिंदुओं या पट्टियों के साथ
अद्यतन करता है.bInitnType
resetDisplay: यह फ़ंक्शन डिस्प्ले को रीसेट करता है, तीव्रता को अधिकतम मान के आधे पर सेट करता है,
डिस्प्ले अपडेट चालू करता है, और डिस्प्ले को साफ़ करता है।
runAnimation: यह फ़ंक्शन एनिमेशन को शेड्यूल करता है और MODE_SWITCH दबाए जाने पर लाइन और बार चार्ट
मोड के बीच स्विच िंग को संभालता है।
सेटअप फ़ंक्शन MD_MAX72XX और MD_UISwitch_Digital ऑब्जेक्ट्स को प्रारंभ करता है, साथ ही यदि
डीबगिंग सक्षम है तो सीरियल संचार भी।
लूप फ़ंक्शन स्क्रॉलिंग चार्ट को लगातार अपडेट और प्रदर्शित करने के लिए फ़ंक्शन को बार-बार कॉल करता है।
runAnimation
नोट: कोड में उपयोग किए गए विशिष्ट पिन नंबर सभी हार्डवेयर कॉन्फ़िगरेशन के साथ काम नहीं कर सकते हैं
और तदनुसार समायोजित करने की आवश्यकता हो सकती है। इसके अतिरिक्त, स्केच को संकलित करने और
ठीक से चलाने के लिए उपयोग की जाने वाली लाइब्रेरी (MD_MAX72xx और MD_UIswitch) को
स्थापित करने की आवश्यकता है।
by arvind patil india 2/7/23
********************************************************************************/
// Use the MD_MAX72XX library to Display a Scrolling Chart
//
// Scroll Chart Style can be changed from line to bar chart, triggered
// by a switch on the MODE_SWITCH pin.
//
// Uses the MD_UIswitch library found at https://github.com/MajicDesigns/MD_UISwitch
#include <MD_MAX72xx.h>
#include <SPI.h>
#include <MD_UISwitch.h>
#define DEBUG 0 // Enable or disable (default) debugging output
#if DEBUG
#define PRINT(s, v) { Serial.print(F(s)); Serial.print(v); } // Print a string followed by a value (decimal)
#define PRINTX(s, v) { Serial.print(F(s)); Serial.print(v, HEX); } // Print a string followed by a value (hex)
#define PRINTB(s, v) { Serial.print(F(s)); Serial.print(v, BIN); } // Print a string followed by a value (binary)
#define PRINTC(s, v) { Serial.print(F(s)); Serial.print((char)v); } // Print a string followed by a value (char)
#define PRINTS(s) { Serial.print(F(s)); } // Print a string
#else
#define PRINT(s, v) // Print a string followed by a value (decimal)
#define PRINTX(s, v) // Print a string followed by a value (hex)
#define PRINTB(s, v) // Print a string followed by a value (binary)
#define PRINTC(s, v) // Print a string followed by a value (char)
#define PRINTS(s) // Print a string
#endif
// --------------------
// MD_MAX72xx hardware definitions and object
// 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 11
#define CLK_PIN 13 // or SCK
#define DATA_PIN 11 // or MOSI
#define CS_PIN 10 // or SS
MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, CS_PIN, MAX_DEVICES); // SPI hardware interface
//MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES); // Arbitrary pins
// --------------------
// Mode keyswitch parameters and object
//
#define MODE_SWITCH 9 // Digital Pin
MD_UISwitch_Digital ks = MD_UISwitch_Digital(MODE_SWITCH, HIGH);
// --------------------
// Constant parameters
//
// Various delays in milliseconds
#define Next_POINT_DELAY 40
// ========== General Variables ===========
//
uint32_t prevTime = 0; // Used for remembering the mills() value
// ========== Graphic routines ===========
//
bool graphDisplay(bool bInit, uint8_t nType)
{
static int8_t curPoint = 0;
uint8_t curCol = 0;
// are we initializing?
if (bInit)
{
resetDisplay();
curPoint = 4;
bInit = false;
}
else if (millis() - prevTime >= Next_POINT_DELAY)
{
prevTime = millis(); // rest for next time
// work out the new value for the height depending on the chart type
switch (nType)
{
case 0: // continuous display next point should be +/-1 or 0
curPoint += random(3) - 1;
if (curPoint < 0) curPoint = 0;
if (curPoint > 7) curPoint = 7;
break;
case 1: // random height
case 2:
curPoint = random(8);
break;
}
// now work out the new column value
switch (nType)
{
case 0: // just a dot
case 1:
curCol = (1 << curPoint);
break;
case 2: // bar chart
for (uint8_t i=0; i<8; i++)
curCol |= (i<curPoint ? 0 : 1) << i;
break;
}
// Shift over and insert the new column
mx.transform(MD_MAX72XX::TSL);
mx.setColumn(0, curCol);
}
return(bInit);
}
// ========== Control routines ===========
//
void resetDisplay(void)
{
mx.control(MD_MAX72XX::INTENSITY, MAX_INTENSITY/2);
mx.control(MD_MAX72XX::UPDATE, MD_MAX72XX::ON);
mx.clear();
prevTime = 0;
}
void runAnimation(void)
// Schedule the animations, switching to the next one when the
// the mode switch is pressed.
{
static uint8_t state = 0;
static bool bRestart = true;
// check if the switch is pressed and handle that first
if (ks.read() == MD_UISwitch::KEY_PRESS)
{
state = (state + 1) % 3;
bRestart = true;
};
// now do whatever we do in the current state
bRestart = graphDisplay(bRestart, state);
}
void setup(void)
{
mx.begin();
ks.begin();
#if DEBUG
Serial.begin(9600);
#endif
PRINTS("\n[MD_MAX72XX Scroll Chart]");
}
void loop(void)
{
runAnimation();
}