10-11-2022, 16:47
Arduino UNO + DS3132 + MAX7219.
Jest to mój pierwszy kontakt z Arduino, więc proszę o wyrozumialość i podpowiedzi
Co mam źle w kodzie ? Co jakiś czas blokuje się przy wyświetlaniu godziny w róznych odstępach czasowych. Pomaga tylko reset.
Jest to mój pierwszy kontakt z Arduino, więc proszę o wyrozumialość i podpowiedzi
Co mam źle w kodzie ? Co jakiś czas blokuje się przy wyświetlaniu godziny w róznych odstępach czasowych. Pomaga tylko reset.
Kod:
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#include <DS3231.h>
DS3231 rtc(SDA,SCL);
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4
#define CS_PIN 10
#define MAX_MESG 20
MD_MAX72XX mx = MD_MAX72XX(CS_PIN, MAX_DEVICES);
MD_Parola mojWyswietlacz = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
int vart= 1;
uint8_t dega[] = { 5, 32, 84, 84, 248, 64, }; // Dega &=ą
uint8_t degC[] = { 4, 6, 9, 9, 6 }; // DegC $=stopnie
uint8_t degZ[] = { 3, 81, 127, 68, }; // DegZ Z=ł
uint8_t degQ[] = { 5, 38, 73, 75, 73, 50, }; // DegQ Q=Ś
uint8_t degY[] = { 5, 124, 8, 4, 6, 121, }; // DegY Y=ń
uint8_t degX[] = { 5, 68, 100, 84, 78, 69, }; // DegX X=ź
const uint8_t F_PMAN1 = 6;
const uint8_t W_PMAN1 = 8;
const uint8_t PROGMEM pacman1[F_PMAN1 * W_PMAN1] = // pacman animation
{
0x00, 0x81, 0xc3, 0xe7, 0xff, 0x7e, 0x7e, 0x3c,
0x00, 0x42, 0xe7, 0xe7, 0xff, 0xff, 0x7e, 0x3c,
0x24, 0x66, 0xe7, 0xff, 0xff, 0xff, 0x7e, 0x3c,
0x3c, 0x7e, 0xff, 0xff, 0xff, 0xff, 0x7e, 0x3c,
0x24, 0x66, 0xe7, 0xff, 0xff, 0xff, 0x7e, 0x3c,
0x00, 0x42, 0xe7, 0xe7, 0xff, 0xff, 0x7e, 0x3c,
};
const uint8_t F_PMAN2 = 6;
const uint8_t W_PMAN2 = 18;
const uint8_t PROGMEM pacman2[F_PMAN2 * W_PMAN2] = // pacman pursued by a ghost
{
0x00, 0x81, 0xc3, 0xe7, 0xff, 0x7e, 0x7e, 0x3c, 0x00, 0x00, 0x00, 0xfe, 0x7b, 0xf3, 0x7f, 0xfb, 0x73, 0xfe,
0x00, 0x42, 0xe7, 0xe7, 0xff, 0xff, 0x7e, 0x3c, 0x00, 0x00, 0x00, 0xfe, 0x7b, 0xf3, 0x7f, 0xfb, 0x73, 0xfe,
0x24, 0x66, 0xe7, 0xff, 0xff, 0xff, 0x7e, 0x3c, 0x00, 0x00, 0x00, 0xfe, 0x7b, 0xf3, 0x7f, 0xfb, 0x73, 0xfe,
0x3c, 0x7e, 0xff, 0xff, 0xff, 0xff, 0x7e, 0x3c, 0x00, 0x00, 0x00, 0xfe, 0x7b, 0xf3, 0x7f, 0xfb, 0x73, 0xfe,
0x24, 0x66, 0xe7, 0xff, 0xff, 0xff, 0x7e, 0x3c, 0x00, 0x00, 0x00, 0xfe, 0x7b, 0xf3, 0x7f, 0xfb, 0x73, 0xfe,
0x00, 0x42, 0xe7, 0xe7, 0xff, 0xff, 0x7e, 0x3c, 0x00, 0x00, 0x00, 0xfe, 0x7b, 0xf3, 0x7f, 0xfb, 0x73, 0xfe,
};
const uint8_t F_WALKER = 5;
const uint8_t W_WALKER = 7;
const uint8_t PROGMEM walker[F_WALKER * W_WALKER] = // walking man
{
0x00, 0x48, 0x77, 0x1f, 0x1c, 0x94, 0x68,
0x00, 0x90, 0xee, 0x3e, 0x38, 0x28, 0xd0,
0x00, 0x00, 0xae, 0xfe, 0x38, 0x28, 0x40,
0x00, 0x00, 0x2e, 0xbe, 0xf8, 0x00, 0x00,
0x00, 0x10, 0x6e, 0x3e, 0xb8, 0xe8, 0x00,
};
void setup() {
rtc.begin(); //zegar
mojWyswietlacz.begin();
mojWyswietlacz.setIntensity(0);
mojWyswietlacz.displayClear();
mojWyswietlacz.addChar('$', degC); // stopne celcjusza
mojWyswietlacz.addChar('&', dega); // ą
mojWyswietlacz.addChar('Z', degZ); // ł
mojWyswietlacz.addChar('Q', degQ); // Ś
mojWyswietlacz.addChar('Y', degY); // ń
mojWyswietlacz.addChar('X', degX); // ź
}
void loop() {
String dzien1 = rtc.getDateStr();
dzien1.remove(2,8);
char datadluga[80];
String msggg = "test tekstu";
msggg+= dzien1.c_str();
msggg+=" ";
msggg+=String(rtc.getMonthStr(FORMAT_LONG));
char godzinapacman[80];
String msh = "";
msh+= rtc.getTimeStr(1);
msggg.toCharArray(datadluga,100);
msh.toCharArray(godzinapacman,100);
String godzina = rtc.getTimeStr(1);
String data = rtc.getDateStr();
String dzien = rtc.getDOWStr();
String miesiac = rtc.getMonthStr(FORMAT_LONG);
mojWyswietlacz.displayAnimate();
if(mojWyswietlacz.displayAnimate()){
switch (vart){
case 1: // GODZINA
mojWyswietlacz.setSpriteData(pacman1, W_PMAN1, F_PMAN2, pacman2, W_PMAN2, F_PMAN2);
mojWyswietlacz.displayText(godzinapacman, PA_CENTER, 50, 1000, PA_SPRITE, PA_SPRITE);
mojWyswietlacz.displayReset();
vart=2;
break;
case 2: // DATA
mojWyswietlacz.displayText(data.c_str(), PA_CENTER, 70, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
mojWyswietlacz.displayReset();
vart=3;
break;
case 3: // GODZINA drugie wejscie
mojWyswietlacz.displayText(godzina.c_str(), PA_CENTER, 30, 3000, PA_WIPE_CURSOR, PA_CLOSING);
mojWyswietlacz.displayReset();
vart=4;
break;
case 4: // DZIEN TYGODNIA
mojWyswietlacz.displayText(dzien.c_str(), PA_CENTER, 70, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
mojWyswietlacz.displayReset();
vart=5;
break;
case 5: // GODZINA trzecie wejscie
mojWyswietlacz.setSpriteData(walker, W_WALKER, F_WALKER, walker, W_WALKER, F_WALKER);
mojWyswietlacz.displayText(godzinapacman, PA_CENTER, 50, 1000, PA_SPRITE, PA_SPRITE);
mojWyswietlacz.displayReset();
vart=6;
break;
case 6: // Dzisiaj jest
mojWyswietlacz.displayText(datadluga, PA_CENTER, 50, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
mojWyswietlacz.displayReset();
vart=1;
break;
}}}