Hey, I have a code that randomly picks between two texts to show them on my LED matrix. I would like to show the text in an order, one after the other.
Here's the code:
//temp test to run with ArduinoJson 6
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#include <ArduinoJson.h>
#include <WiFi.h>
#include <WiFiClientSecure.h>
//Wifi details
char wifiSSID[] = "BELL718";
char wifiPASS[] = "FD3925769C6A";
String on_currency = "BTCCAD";
String on_sub_currency = on_currency.substring(3);
char conversion[20];
const uint16_t WAIT_TIME = 1000;
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW //If your LEDs look odd try replacing ICSTATION_HW with one of these GENERIC_HW, FC16_HW, PAROLA_HW .
#define MAX_DEVICES 4
#define CLK_PIN 18
#define DATA_PIN 23
#define CS_PIN 5
MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
// Scrolling parameters
uint8_t scrollSpeed = 15; // default frame delay value
textEffect_t scrollEffect = PA_SCROLL_LEFT;
textPosition_t scrollAlign = PA_LEFT;
uint16_t scrollPause = 0; // in milliseconds
// Global message buffers shared by Serial and Scrolling functions
#define BUF_SIZE 75
char curMessage[BUF_SIZE] = { "" };
char newMessage[BUF_SIZE] = { "" };
bool newMessageAvailable = true;
void setup(void)
{
Serial.begin(115200);
//connect to local wifi
WiFi.begin(wifiSSID, wifiPASS);
while (WiFi.status() != WL_CONNECTED) {}
P.begin();
P.setIntensity(0);
P.displayText(curMessage, scrollAlign, scrollSpeed, scrollPause, scrollEffect, scrollEffect);
}
int counta = 0;
void loop(void)
{
if (P.displayAnimate())
{if (newMessageAvailable){
strcpy(curMessage, "BTC CAD");
}P.displayReset();}
if (P.displayAnimate())
{if (newMessageAvailable){
on_rates();
strcpy(curMessage, conversion);
}P.displayReset();}
}
// START OF BTC CODE
void on_rates(){
// Use WiFiClientSecure class to create TLS connection
WiFiClientSecure client;
if (!client.connect("api.opennode.co", 443)) {
return;
}
String url = "/v1/rates";
client.print(String("GET ") + url + " HTTP/1.1rn" +
"Host: " + "api.opennode.co" + "rn" +
"User-Agent: ESP32rn" +
"Connection: closernrn");
while (client.connected()) {
String line = client.readStringUntil('n');
if (line == "r") {
break;
}
}
String line = client.readStringUntil('n');
const size_t capacity = 169*JSON_OBJECT_SIZE(1) + JSON_OBJECT_SIZE(168) + 3800;
DynamicJsonDocument doc(capacity);
deserializeJson(doc, line);
String conversionn = doc["data"][on_currency][on_currency.substring(3)];
conversionn.toCharArray(conversion, conversionn.length());
Serial.println(conversion);
}
// END OF BTC CODE