Second attempt to post. My projects a LED matrix scrolling display. It has worked great for awhile. now the time is off. I think I need to reupload the program to get the time stamp off my pc. I tried to upload and it won't. I cant get it to compile either. I am still in the early stages of learning programing. this is a complex project. I modified an existing code to get it t work.
//Basically finished would like to play with messages at diffrent times
//got lunch time to work thinking add it to the time case so either display time or lunch time ect see project #8
//working good smooth transistions. changes formatting. added some case swithes to get mayas info in
// Code modded from MD_zone_time_message in exampls of MD_Parola
// also used code from DHT.h examples
// - DS1307 library (MD_DS1307) found at https://github.com/MajicDesigns/DS1307
// NOTE: MD_MAX72xx library must be installed and configured for the LED
// matrix type being used. Refer documentation included in the MD_MAX72xx
// library or see this link:
// https://majicdesigns.github.io/MD_MAX72XX/page_hardware.html
//
// connect real time clock to pins SCL to A5, SDA to A4, 5V, and GND.
// Connect pin 1 (on the left) of the Tempsensor to +5V
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 5V!
// Connect pin 2 of the Temp sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the Temp sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor
// Use the DS1307 clock module
//#define USE_DS1307 0
// Header file includes
#include <MD_Parola.h> //LED
#include <MD_MAX72xx.h> //LED
#include <SPI.h> //LED
#include "Font_Data.h" //LED
#include <MD_DS1307.h> //Clock
#include <Wire.h> //Clock
#include "DHT.h" //Temp sensor
// 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 MAX_DEVICES 8 // Max devices attached
#define CLK_PIN 13 // Pin for led clock
#define DATA_PIN 11 // pin for led data in
#define CS_PIN 10 // Pin for led chip select
#define DHTPIN 2 // Pin for Temp sensor
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
// Hardware SPI connection
MD_Parola P = MD_Parola(CS_PIN, MAX_DEVICES); //LED
DHT dht(DHTPIN, DHTTYPE); // Temp
#define SPEED_TIME 75 //LED
#define PAUSE_TIME 1000 //LED was 0
#define MAX_MESG 20 //LED
// Turn on debug statements to the serial output
#define DEBUG 0
// Global variables
float oldt =0;
float oldh =0;
float oldf =0;
float t=20;
float h=100;
float f=70;
int nan = nan;
int Red = 6; //Red led output pin
int Blue = 5; //Blue led output pin
int Green = 3; //Green led output pin
char szTime[9]; // mm:ss\0
char szMesg[MAX_MESG+1] = "";
uint8_t degC[] = { 6, 3, 3, 56, 68, 68, 68 }; // Deg C
uint8_t degF[] = { 6, 3, 3, 124, 20, 20, 4 }; // Deg F
char *mon2str(uint8_t mon, char *psz, uint8_t len)
// Get a label from PROGMEM into a char array
{
static const __FlashStringHelper* str[] =
{
F("Jan"), F("Feb"), F("Mar"), F("Apr"),
F("May"), F("Jun"), F("Jul"), F("Aug"),
F("Sep"), F("Oct"), F("Nov"), F("Dec")
};
strncpy_P(psz, (const char PROGMEM *)str[mon-1], len);
psz[len] = '\0';
return(psz);
}
char *dow2str(uint8_t code, char *psz, uint8_t len)
{
static const __FlashStringHelper* str[] =
{
F("Sunday"), F("Monday"), F("Tuesday"),
F("Wednesday"), F("Thursday"), F("Friday"),
F("Saturday"), F("Maya B Webb"), F("Radiochemist"),
F("Lunch Time")
};
strncpy_P(psz, (const char PROGMEM *)str[code-1], len);
psz[len] = '\0';
return(psz);
}
void getTemp(){
h = dht.readHumidity(); //read humidity
t = dht.readTemperature();//read temperature in Celsius ()
f = dht.readTemperature(true); //read tempeature in Fahrenheit (true)
//Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
analogWrite (Green,200);
}else{
analogWrite (Green,0);
}}
void getTime(char *psz, bool f = false)
// Code for reading clock time
{
//#if USE_DS1307
RTC.readTime();
sprintf(psz, "%02d%c%02d", RTC.h, (f ? ':' : ' '), RTC.m);
/*#else
uint16_t h, m, s;
s = millis()/1000;
m = s/60;
h = m/60;
m %= 60;
s %= 60;
sprintf(psz, "%02d%c%02d", h, (f ? ':' : ' '), m);
#endif*/
}
void getDate(char *psz)
// Code for reading clock date
{
//#if USE_DS1307
char szBuf[10];
RTC.readTime();
sprintf(psz, "%d %s %04d", RTC.dd, mon2str(RTC.mm, szBuf, sizeof(szBuf)-1), RTC.yyyy);
//#else
// strcpy(szMesg, "25 Dec 2017");
//#endif
}
void setup(void)
{
Serial.begin(9600);
pinMode (Red, OUTPUT); //red
pinMode (Blue, OUTPUT); //blue
pinMode (Green, OUTPUT); //green
dht.begin();
P.begin(1);
P.setInvert(false);
P.setZone(0, 0, MAX_DEVICES-1);
//P.setZone(1, MAX_DEVICES-4, MAX_DEVICES-1);
//P.setFont(1, numeric7Seg);
P.displayZoneText(0, szMesg, PA_CENTER, SPEED_TIME, PAUSE_TIME, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
P.addChar('
, degC);
P.addChar('&', degF);
//#if USE_DS1307
RTC.control(DS1307_CLOCK_HALT, DS1307_OFF);
RTC.control(DS1307_12H, DS1307_OFF);
//#endif
getTime(szMesg);
}
void loop(void)
{
static uint32_t lastTime = 0; // millis() memory
static uint8_t display = 0; // current display mode
static bool flasher = false; // seconds passing flasher
P.displayAnimate();
if (P.getZoneStatus(0))
{
switch (display)
{
case 0: // first message name
P.setTextEffect(0, PA_SCROLL_LEFT, PA_WIPE);
display++;
dow2str(8 , szMesg, MAX_MESG); //made up shit to work
break;
case 1: // second message title
P.setTextEffect(0, PA_SCROLL_LEFT, PA_FADE);
display++;
dow2str(9 , szMesg, MAX_MESG); //made up shit to work
break;
case 2: // Temperature deg F
P.setTextEffect(0, PA_SCROLL_UP, PA_SCROLL_LEFT);
display++;
if (f == nan){
dtostrf(oldf, 3, 0, szMesg);
strcat(szMesg, "&");
}else{
dtostrf(f, 3, 0, szMesg);
strcat(szMesg, "&");
oldf = f;
}
break;
case 3: // Temperature deg C
P.setTextEffect(0, PA_SCROLL_UP, PA_WIPE);
display++;
getTemp();
if (t == nan){
dtostrf(oldt, 3, 0, szMesg);
strcat(szMesg, "$");
}else{
dtostrf(t, 3, 0, szMesg);
strcat(szMesg, "$");
oldt = t;
}
break;
case 4: // Relative Humidity
P.setTextEffect(0, PA_SCROLL_LEFT, PA_SCROLL_DOWN);
display++;
if (h == nan){
dtostrf(oldh, 3, 0, szMesg);
strcat(szMesg, "%RH");
}else{
dtostrf(h, 3, 0, szMesg);
strcat(szMesg, "% RH");
oldh = h;
}
break;
/* case 5: // time
P.setTextEffect(0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
display++;
getTime(szMesg, flasher);
flasher = !flasher;
break;
case 6: //Lunch
if(RTC.h == 13 && RTC.m == 37){
P.setTextEffect (0, PA_SCROLL_UP, PA_SCROLL_UP);
display++;
dow2str(10 , szMesg, MAX_MESG); //made up shit to work
}else{
P.setTextEffect (0, PA_SCROLL_UP, PA_SCROLL_UP);
display++;
dow2str(8 , szMesg, MAX_MESG); //made up shit to work
}
break;*/
case 5: // day of week
P.setTextEffect(0, PA_SCROLL_LEFT, PA_SCROLL_UP);
display++;
dow2str(RTC.dow, szMesg, MAX_MESG);
break;
default: // Calendar
P.setTextEffect(0, PA_DISSOLVE, PA_DISSOLVE);
display = 0;
getDate(szMesg);
break;
}
P.displayReset(0);
}
//Serial.println (h);
if (RTC.h == 12 && RTC.m == 00){
analogWrite (Green, 100);
}else{
analogWrite (Green, 0);
}
if (f < 70){ // LED blue if too cold
analogWrite (Blue,200);
}else{
analogWrite (Blue,0);}
if (f > 85){ // LED red if too hot
analogWrite (Red, 200);
}else{
analogWrite (Red, 0);}
// Finally, adjust the time string if we have to
// if (millis() - lastTime >= 1000)
// {
// lastTime = millis();
// getTime(szTime, flasher);
// flasher = !flasher;
// P.displayReset(0);
// }
}