Bonjour à tous,
Voilà j'ai acheté une matrice de led rgb ws2812 en 8x32.
J'ai reussi avec les exemples à faire défiler du texte sans problème j'ai mm ajouté à mon projet une horloge rtc et une sonde dht11.
J'aimerais connaitre la longueur de ma matrice car pour l'instant je suis obligé de mettre un nombre au hasard. Ici le (-220)
Ci-dessous le code que j'ai fait :
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#include <Wire.h>
#include <RTClib.h>
#include "dht.h"
RTC_DS1307 RTC;
#define dht_apin A2 // Analog Pin sensor is connected to
dht DHT;
#define PIN 6
// MATRIX DECLARATION:
// Parameter 1 = width of NeoPixel matrix
// Parameter 2 = height of matrix
// Parameter 3 = pin number (most are valid)
// Parameter 4 = matrix layout flags, add together as needed:
// NEO_MATRIX_TOP, NEO_MATRIX_BOTTOM, NEO_MATRIX_LEFT, NEO_MATRIX_RIGHT:
// Position of the FIRST LED in the matrix; pick two, e.g.
// NEO_MATRIX_TOP + NEO_MATRIX_LEFT for the top-left corner.
// NEO_MATRIX_ROWS, NEO_MATRIX_COLUMNS: LEDs are arranged in horizontal
// rows or in vertical columns, respectively; pick one or the other.
// NEO_MATRIX_PROGRESSIVE, NEO_MATRIX_ZIGZAG: all rows/columns proceed
// in the same order, or alternate lines reverse direction; pick one.
// See example below for these values in action.
// Parameter 5 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(32, 8, PIN,
NEO_MATRIX_TOP + NEO_MATRIX_LEFT +
NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG,
NEO_GRB + NEO_KHZ800);
const uint16_t colors[] = {
matrix.Color(255, 0, 0), matrix.Color(0, 255, 0), matrix.Color(255, 255, 0),matrix.Color(0, 0, 255), matrix.Color(255, 0, 255), matrix.Color(0, 255, 255), matrix.Color(255, 255, 255)};
void setup() {
matrix.begin();
matrix.setTextWrap(false);
matrix.setBrightness(10);
matrix.setTextColor(colors[0]);
matrix.setTextSize(1);
Wire.begin();
RTC.begin();
Serial.begin(9600);
}
int x = matrix.width();
int pass = 0;
long currentMillis;
long previousMillisdht11 = 0;
long timedht11 = 5000;
long previousMillismatrix = 0;
long timematrix = 15;
long previousMillisrtc = 0;
long timertc = 500;
float temperature;
float humidity;
char heure[12];
char date[12];
void majtemp() {
DHT.read11(dht_apin);
temperature = DHT.temperature;
humidity = DHT.humidity;
}
void loop() {
currentMillis = millis();
if(currentMillis - previousMillisrtc > timertc) {
previousMillisrtc = currentMillis;
DateTime now = RTC.now();
sprintf(heure,"%02u:%02u:%02u",now.hour(),now.minute(),now.second());
sprintf(date,"%02u/%02u/%04u",now.day(),now.month(),now.year());
}
//dateheure = now.hour() + ':' + now.minute() + ':' + now.second();
// matrix.print('l');
// matrix.print(' ');
// matrix.print(now.hour());
// matrix.print(':');
// matrix.print(now.minute());
// matrix.print(':');
// matrix.print(now.second());
currentMillis = millis();
if(currentMillis - previousMillisdht11 > timedht11) {
previousMillisdht11 = currentMillis;
majtemp();
}
matrix.fillScreen(0);
matrix.setCursor(x, 0);
matrix.setTextColor(matrix.Color(255,0,0));
matrix.print("Il est :");
matrix.setTextColor(matrix.Color(0,255,0));
matrix.print(heure);
matrix.print(' ');
matrix.setTextColor(matrix.Color(255,255,255));
matrix.print(date);
matrix.print(' ');
matrix.print(temperature);
matrix.print('c');
matrix.print(' ');
matrix.print(humidity);
matrix.print('%');
matrix.show();
currentMillis = millis();
if(currentMillis - previousMillismatrix > timematrix) {
previousMillismatrix = currentMillis;
if(--x < -220 ) {
x = matrix.width();
// if(++pass >= 8) pass = 0;
// matrix.setTextColor(colors[pass]);
}
}
}
Bien à vous
bypbop
