Bonsoir,
Je tente de "compiler" deux codes en un seul, pour réaliser une horloge composée d'un anneau de 60 leds RGB WS2812B et d'une matrice de leds rouges MAX7216 au centre.
Voici les sources des deux codes en question :
MAX7219 RTC DS1307 dht11 led matrix clock Arduino
Simple wall clock using Adafruit 1/4 60 Ring Neopixel
Je parviens à les faire fonctionner indépendamment l'un de l'autre.
C'est quand je rassemble les deux que ça pose problème.
// Use the DHT11 temp and humidity sensor
#define USE_DS1307
// Header file includes
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#include <Wire.h>
#include <MD_DS1307.h>
#include <RTClib.h>
#include "DHT.h"
DHT dht;
#include "Font_Data.h"
#include <Adafruit_NeoPixel.h>
// 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 11
#define DATA_PIN 12
#define CS_PIN 10
#define PIN 4
#define PIXEL 60
#define MAX_BRIGHTNESS 250
#define MIN_BRIGHTNESS 20
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL, PIN, NEO_GRB + NEO_KHZ800);
DateTime Clock; // Holds current clock time
// HARDWARE SPI
// MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
// SOFTWARE SPI
MD_Parola P = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is A0
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor
byte hourval, minuteval, secondval;
const int brightnessInPin = A2; // The Analog input pin that the brightness control potentiometer is attached to.
volatile boolean buttonA = false;
volatile boolean buttonB = false;
volatile boolean buttonC = false;
int StateOfbuttonA = 0;
int StateOfbuttonB = 0;
int StateOfbuttonC = 0;
int NewStateOfbuttonA = 0;
int NewStateOfbuttonB = 0;
int NewStateOfbuttonC = 0;
int temp;
int Humi;
int Mode = 0;
int contrast = 0;
int SPEED_TIME = 75;
#define PAUSE_TIME 0
#define MAX_MESG 20
// Global variables
char szTime[9]; // hh:mm
char szsecond[4]; // ss
char szMesg[MAX_MESG + 1] = "";
uint8_t degC[] = { 6, 3, 3, 56, 68, 68, 68 }; // Deg C
char *mon2str(uint8_t mon, char *psz, uint8_t len)
// Get a label from PROGMEM into a char array
{
static const __FlashStringHelper* str[] =
{
F("Janvier"), F("Février"), 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")
};
strncpy_P(psz, (const char PROGMEM *)str[code - 1], len);
psz[len] = '\0';
return (psz);
}
void getTime(char *psz, bool f = true)
// Code for reading clock time
{
RTC.readTime();
sprintf(psz, "%02d%c%02d", RTC.h, (f ? ':' : ' '), RTC.m);
}
void getTim(char *psz, bool f = true)
// Code for reading clock time
{
RTC.readTime();
sprintf(psz, "%02d%c%02d", RTC.h, ':', RTC.m);
}
void getDate(char *psz)
// Code for reading clock date
{
char szBuf[10];
RTC.readTime();
sprintf(psz, "%d %s %04d", RTC.dd, mon2str(RTC.mm, szBuf, sizeof(szBuf) - 1), RTC.yyyy);
}
void getTem(char *psz, bool f = true)
// Code for reading clock date
{
temp = dht.getTemperature();
sprintf(psz, "%02d", temp);
}
void getHumi(char *psz, bool f = true)
// Code for reading clock date
{
Humi = dht.getHumidity();
sprintf(psz, "%02d", Humi);
}
void getsecond(char *psz)
// Code for reading clock date
{
char szBuf[10];
RTC.readTime();
sprintf(psz, "%02d", RTC.s);
}
void gethh(char *psz, bool f = true)
// Code for reading clock time
{
RTC.readTime();
sprintf(psz, "%c%02d%c%02d", (f ? ':' : ' '), RTC.h, (f ? ':' : ' '), RTC.m);
}
void getmin(char *psz, bool f = true)
// Code for reading clock time
{
RTC.readTime();
sprintf(psz, "%02d%c%02d%c", RTC.h, (f ? ':' : ' '), RTC.m, (f ? ':' : ' '));
}
void getsec(char *psz)
// Code for reading clock date
{
char szBuf[10];
RTC.readTime();
sprintf(psz, "%02d", RTC.s);
}
void getdyy(char *psz)
{
char szBuf[10];
RTC.readTime();
sprintf(psz, "%02d", RTC.dd);
}
void getmon(char *psz)
// Code for reading clock date
{
char szBuf[10];
RTC.readTime();
sprintf(psz, "%s", mon2str(RTC.mm, szBuf, sizeof(szBuf) - 1));
}
void getyyyy(char *psz)
// Code for reading clock date
{
char szBuf[10];
RTC.readTime();
sprintf(psz, "%04d", RTC.yyyy);
}
void setup(void)
{
strip.begin();
uint32_t low = strip.Color(0, 0, 0);
uint32_t high = strip.Color(170, 0, 170);
// Turn them off
for ( int i = 0; i < PIXEL; i++) {
strip.setPixelColor(i, high);
delay(15);
strip.show();
}
for ( int i = 0; i < PIXEL; i++) {
strip.setPixelColor(i, low);
delay(15);
strip.show();
}
delay(500);
strip.show(); // Initialize all pixels to 'off'
// strip.setBrightness(50);
dht.setup(2); // data pin 2
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
P.begin(3);
P.setInvert(false);
P.setZone(2, 0, 3);
P.setZone(1, 1, 3);
P.setZone(0, 4, 1);
P.setFont(1, numeric7Se);
P.setFont(0, numeric7Seg);
P.displayZoneText(1, szTime, PA_LEFT, SPEED_TIME, PAUSE_TIME, PA_PRINT, PA_NO_EFFECT);
P.displayZoneText(0, szsecond, PA_LEFT, SPEED_TIME, 0, PA_PRINT, PA_NO_EFFECT);
P.displayZoneText(2, szMesg, PA_CENTER, SPEED_TIME, 0, PA_PRINT, PA_SCROLL_LEFT);
P.addChar('
(Je n'ai pas mis la fin du code, car le forum n'accepte pas la longueur du post)
A la compilation du code j'ai un message d'erreur dont voici le log :
\Arduino\libraries\RTClib/RTClib.h:30:7: note: no known conversion for argument 1 from 'void' to 'const DateTime&'
exit status 1
no match for 'operator=' (operand types are 'DateTime' and 'void')
C'est la ligne suivante qu'il n'aime pas :
Clock = RTC.now(); // get the RTC time
J'ai bien tenté des choses, mais je débute… (j'ai commencé le cours d'Eskimon) j'essaye de comprendre la logique, mais là je cale.
Auriez-vous une idée ??
, degC);
RTC.control(DS1307_CLOCK_HALT, DS1307_OFF);
RTC.control(DS1307_12H, DS1307_OFF);
getTime(szTime);
}
void loop()
{
// read the analog brightness value:
//int brightValue = analogRead(brightnessInPin);
// map it to the range of the FastLED brightness:
int mappedValue = map(analogRead(brightnessInPin), 0, 1023, 0, 255);
//int outputValue = constrain(mappedValue, MIN_BRIGHTNESS, MAX_BRIGHTNESS);
// now we set the brightness of the strip
strip.setBrightness(constrain(mappedValue, MIN_BRIGHTNESS, MAX_BRIGHTNESS));
Clock = RTC.now(); // get the RTC time
secondval = Clock.second(); // get seconds
minuteval = Clock.minute(); // get minutes
hourval = Clock.hour(); // get hours
if (hourval > 11) hourval -= 12; // This clock is 12 hour, if 13-23, convert to 0-11
hourval = (hourval * 60 + minuteval) / 12;
strip.setPixelColor(hourval, 0x0000FF); strip.setPixelColor(hourval - 1, 0x3B3BFB); strip.setPixelColor(hourval + 1, 0x3B3BFB);
// strip.setPixelColor(hourval-2, 0x001010);strip.setPixelColor(hourval+2, 0x001010);
strip.setPixelColor(minuteval, 0x800080);
// strip.setPixelColor(minuteval-1, 0x200020);strip.setPixelColor(minuteval+1, 0x200020);
strip.setPixelColor(secondval, 0x808000);//strip.setPixelColor(secondval-1, 0x002F00);strip.setPixelColor(secondval+1, 0x002F00);
strip.show();
strip.setPixelColor(hourval, 0x000000); strip.setPixelColor(hourval - 1, 0x000000); strip.setPixelColor(hourval + 1, 0x000000);
// strip.setPixelColor(hourval - 2, 0x000000); strip.setPixelColor(hourval + 2, 0x000000);
strip.setPixelColor(minuteval, 0x000000); strip.setPixelColor(minuteval - 1, 0x000000); strip.setPixelColor(minuteval + 1, 0x000000);
strip.setPixelColor(secondval, 0x000000);
//strip.setPixelColor(secondval-1, 0x000000);strip.setPixelColor(secondval+1, 0x000000);
delay(25);
(Je n'ai pas mis la fin du code, car le forum n'accepte pas la longueur du post)
A la compilation du code j'ai un message d'erreur dont voici le log :
\Arduino\libraries\RTClib/RTClib.h:30:7: note: no known conversion for argument 1 from 'void' to 'const DateTime&'
exit status 1
no match for 'operator=' (operand types are 'DateTime' and 'void')
C'est la ligne suivante qu'il n'aime pas :
Clock = RTC.now(); // get the RTC time
J'ai bien tenté des choses, mais je débute… (j'ai commencé le cours d'Eskimon) j'essaye de comprendre la logique, mais là je cale.
Auriez-vous une idée ??