Hi, I'm using this code for monitoring Bitcoin price, but the scrolling effect is too slow. Could you help me to get more speed, please?
//PARTE BITCOIN TICKER
#include <Arduino.h>
#include <ArduinoJson.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
const uint16_t WAIT_TIME = 1000;
// 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::FC16_HW
#define MAX_DEVICES 4
#define CLK_PIN D5
#define DATA_PIN D7
#define CS_PIN D2
#define MAX_MESG 20
// Hardware SPI connection
MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
// Arbitrary output pins
// MD_Parola P = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
const char* ssid = "xx";
const char* password = "xx";
const char* host = "api.coindesk.com";
float previousValue = 0.00;
float threshold = 0.05;
// SOFTWARE SPI
//MD_Parola P = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
uint8_t scrollSpeed = 10; // default frame delay value
textEffect_t scrollEffect = PA_SCROLL_LEFT;
textPosition_t scrollAlign = PA_LEFT;
uint16_t scrollPause = 1000; // in milliseconds
char szMesg[MAX_MESG + 1] = "";
void setup()
{
pinMode(D3, OUTPUT); //Price down
pinMode(D4, OUTPUT); //Price up
Serial.begin(115200);
delay(10);
WiFi.begin(ssid, password);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
P.begin();
P.displayText(szMesg, scrollAlign, scrollSpeed, scrollPause, scrollEffect, scrollEffect);
// P.addChar('
, degC);
}
void loop() {
// Connect to API
Serial.print("connecting to ");
Serial.println(host);
// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
// We now create a URI for the request
String url = "/v1/bpi/currentprice.json";
Serial.print("Requesting URL: ");
Serial.println(url);
// This will send the request to the server
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
delay(500); //geändert von 100
// Read all the lines of the reply from server and print them to Serial
String answer;
while(client.available()){
String line = client.readStringUntil('\r');
answer += line;
}
client.stop();
Serial.println();
Serial.println("closing connection");
// Process answer
Serial.println();
Serial.println("Answer: ");
Serial.println(answer);
// Convert to JSON
String jsonAnswer;
int jsonIndex;
for (int i = 0; i < answer.length(); i++) {
if (answer[i] == '{') {
jsonIndex = i;
break;
}
}
// Get JSON data
jsonAnswer = answer.substring(jsonIndex);
Serial.println();
Serial.println("JSON answer: ");
Serial.println(jsonAnswer);
jsonAnswer.trim();
// Get rate as float
int rateIndex = jsonAnswer.indexOf("rate_float");
String priceString = jsonAnswer.substring(rateIndex + 12, rateIndex + 18);
priceString.trim();
float price = priceString.toFloat();
// Print price
Serial.println();
Serial.println("Bitcoin price: ");
Serial.println(price);
dtostrf(price, 3, 0, szMesg);
strcat(szMesg, " $");
if (P.displayAnimate())
{
P.displayReset();
}
}