Wemos D1Mini Fertiger Code Verbesserungswunsch

Guten Tag zusammen,

ich habe einen Fertigen Code....dieser läuft auch sehr gut...

Im grunde geht es drum das der Wemos d1 mini über wlan eine API abfragt und diese dann über 8x32 Matrix LED anzeigt...

ich nutze dafür JSON...

ich hätte das gerne das die anzeige als Laufschrift (scroll) läuft....nur bin ich in JSON nicht so drin...

kann mir jemand helfen das die anzeige entweder die Komma stellen weg lässt (auf oder abrunden) oder eben die anzeige Scrollt?

hoffe es ist ok das ich den code hier drunter packe....

#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

// 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 = "UPCC954AEA";
const char* password = "**********";
const char* host = "api.coindesk.com";

float previousValue = 0.00;
float threshold = 0.05;


void setup() {

  pinMode(D3, OUTPUT); //Price down
  pinMode(D4, OUTPUT); //Price up


  Serial.begin(9600);
  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();

}



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(100); //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);




  P.print(String(price));






  // Init previous value
  if (previousValue == 0.00) {
    previousValue = price;
  }

  // Alert down ?
  if (price < (previousValue - threshold)) {

    // Flash LED
    digitalWrite(D3, LOW);
    digitalWrite(D4, HIGH);
  }

  // Alert up ?
  if (price > (previousValue + threshold)) {

    // Flash LED
    digitalWrite(D4, LOW);
    digitalWrite(D3, HIGH);
  }

  // Store value
  previousValue = price;

  // Wait 0,5 minute
  delay(500);
}

Beim überfliegen deines Programms sind mir ein paar Dinge aufgefallen.
Sie werden dir nicht konkret helfen, aber auf lange Sicht.....

Der Kommentar ist verwirrend

Der Kommentar ist falsch, es ist eine halbe Sekunde.

Tipp:
Der Code sagt schon ganz genau WAS getan wird.
Der Kommentar sagt WARUM, nennt den Grund.

Hier sollte man vermutlich besser mit sprechenden Bezeichnern arbeiten und nicht mit
Pinnummern.

Ein Test auf Gleichheit ist bei Float eine denkbar ungünstigen Nummer. Klappt meist nicht.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.