AM2301-MAX7219
Temperatuur en luchtvochtigheidsmeterprofessor
c_cpp
2 years ago
928 B
15
Indexable
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#include "DHT.h"
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4
#define CS_PIN 10
MD_Parola myDisplay = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
#define DHTPIN 6
#define DHTTYPE DHT21
DHT dht(DHTPIN, DHTTYPE);
void setup() {
  myDisplay.begin();
  myDisplay.setIntensity(3);
  myDisplay.displayClear();
  dht.begin();
}
void loop() {
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  char tempStr[10];
  char humidStr[10];
  dtostrf(t, 4, 1, tempStr);
  dtostrf(h, 4, 1, humidStr);
  myDisplay.setTextAlignment(PA_LEFT);
  char tempDisplayStr[20];
  sprintf(tempDisplayStr, "T: %s", tempStr);
  myDisplay.print(tempDisplayStr);
  delay(3000);
  myDisplay.setTextAlignment(PA_LEFT);
  char humidDisplayStr[20];
  sprintf(humidDisplayStr, "V: %s", humidStr);
  myDisplay.print(humidDisplayStr);
  delay(3000);
}Editor is loading...