
See what you all think of this code - cobbled together over many hair pulling sessions, no hacking of libraries needed.
#include <SPI.h> //SPI.h must be included as DMD is written by SPI (the IDE complains otherwise)
#include <DMD.h> //
#include <TimerOne.h> //
#include "SystemFont5x7.h"
#include "Arial_black_16.h"
#include "DHT.h"
#define DHTPIN 2 // what pin we're connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)
#define DISPLAYS_ACROSS 1
#define DISPLAYS_DOWN 1
#define DISPLAYS_BPP 1
#define WHITE 0xFF
#define BLACK 0
DMD dmd(DISPLAYS_ACROSS, DISPLAYS_DOWN, DISPLAYS_BPP);
DHT dht(DHTPIN, DHTTYPE);
String outstring0, outstring1, outstring2, outstring3, outstring4, outstring5, outstring6, outstring7;
void ScanDMD()
{
dmd.scanDisplayBySPI();
}
void setup(void)
{
Timer1.initialize( 5000/DISPLAYS_BPP ); //period in microseconds to call ScanDMD. Anything longer than 5000 (5ms) and you can see flicker.
Timer1.attachInterrupt( ScanDMD ); //attach the Timer1 interrupt to ScanDMD which goes to dmd.scanDisplayBySPI()
//clear/init the DMD pixels held in RAM
dmd.clearScreen( BLACK ); //true is normal (all pixels off), false is negative (all pixels on)
Serial.begin(9600);
Serial.println("DHTxx test!");
dht.begin();
}
void loop(void)
{
outstring1 = "Temp : ";
int t = dht.readTemperature();
outstring2 = outstring1 + t;
outstring3 = outstring2 + "C ";
outstring4 = "Humidity : ";
int h = dht.readHumidity();
outstring5 = outstring4 + h;
outstring6 = outstring5 + "%";
outstring7 = outstring3 + outstring6;
char buf[46];
outstring7.toCharArray(buf, 46);
char* messages[] = {buf," Whatever messages You Want "," They can be any length, with any characters "," I do suggest putting a space at the front and back "};
for (int i = 0; i < 4; i++){
if (isnan(t) || isnan(h)) {
Serial.println("Failed to read from DHT");
} else {
Serial.println(buf);
Serial.print(dht.readTemperature());
Serial.print("C ");
Serial.print(dht.readHumidity());
Serial.println("%");
}
// stripe chaser
byte b1;
for( b1 = 0 ; b1 < 5 ; b1++ )
{
dmd.drawTestPattern( (b1&1)+PATTERN_STRIPE_0 );
delay( 200 );
}
delay( 200 );
dmd.clearScreen( BLACK );
dmd.selectFont(Arial_Black_16);
int txt2Displen = strlen(messages);
dmd.drawMarquee(messages,txt2Displen,(32*DISPLAYS_ACROSS)-1,0,WHITE,BLACK);
long start=millis();
long timer=start;
boolean ret=false;
while(!ret){
if ((timer+15) < millis()) {
ret=dmd.stepMarquee(-1,0);
timer=millis();
}
}
}
}
Binary sketch size: 16380 bytes (of a 32256 byte maximum)
Arduino IDE 1.0