Werte Gemeinde, ich nutze einen Wemos d1 mini und ein 32x8 Max 7219 8x8 Display für den folgenden Sketch
#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 D1
// 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 = "xxx";
const char* password = "xxxx";
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(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);
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 1 minute
delay(60000);
}
Meine Fragen: Ist es möglich den Preis auf ganze Zahlen zu Beschränken (Als Bitcoinpreis 4021 und nicht 4021,50) oder die Anzeige mit dem Preis scrollen zu lassen?
Ich habe nur den P.print befehl wirklich als Anzeige reinbekommen. Mit dem Rest der MD_Parola stehe ich auf Kriegsfuß.
Wäre Klasse wenn ihr mir helfen könntet.