• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Pomoc w dopisaniu sterowania przyciskami ustawienia godzin minut i sekund w zegarze
#1
Witam.
Szukam osoby chętnej która dopisze mi do programu sterowanie i ustawienie przyciskami godzin minut i sekund.
Zegar zrobiony na bazie arduino nano, DS3231, MAX1719 i sześciu wyświetlaczy 7 segmentowych.
Poniżej kod programu
Kod:
#include <DS3231.h>         

// define pins attached to MAX7219 (and also see notes above)
#define MAX7219_DIN          12
#define MAX7219_CS            10
#define MAX7219_CLK          11

// enumerate the MAX7219 registers
// See MAX7219 Datasheet, Table 2, page 7
enum {  MAX7219_REG_DECODE    = 0x09,
        MAX7219_REG_INTENSITY = 0x0A,
        MAX7219_REG_SCANLIMIT = 0x0B,
        MAX7219_REG_SHUTDOWN  = 0x0C,
        MAX7219_REG_DISPTEST  = 0x0F
    };

// enumerate the SHUTDOWN modes
// See MAX7219 Datasheet, Table 3, page 7
enum  { OFF = 0,
        ON  = 1
      };



// create an instance of the DS3231 called 'rtc',
// and specify the hardware interface PINS
DS3231 rtc(SDA, SCL);


const static byte charTable [] PROGMEM  =
{
  B01111110, B00110000, B01101101, B01111001, B00110011, B01011011, B01011111, B01110000,
  B01111111, B01111011, B01110111, B00011111, B01001110, B00111101, B01001111, B01000111,
};

// ... setup code here, to run once
void setup()
{
  // initialize the serial port:
  Serial.begin(115200);          // initialize serial communication

  // define type of pin
  pinMode(MAX7219_DIN, OUTPUT);  // serial data-in
  pinMode(MAX7219_CS, OUTPUT);    // chip-select, active low
  pinMode(MAX7219_CLK, OUTPUT);  // serial clock
  digitalWrite(MAX7219_CS, HIGH);

  resetDisplay();                // reset the MAX2719 display

  rtc.begin();                    // init. the DS3231 RTC interface

  // Uncomment the following lines to set the RTC
//  rtc.setTime(13, 43, 0);      // Set the time to 4:20pm
}

void loop()
{
  String str;                    // scratch or working string

  // ... display Time, hh-mm-ss
  for ( int i = 0; i < 6; i++ )
  {
    // read the time as a string from the RTC
    str = rtc.getTimeStr(FORMAT_LONG);
    Serial.println(str);        // debug
    displayTime(str);          // display on the 7-segment
    delay(1000);
  }
}

// ... write a value into a max7219 register
// See MAX7219 Datasheet, Table 1, page 6
void set_register(byte reg, byte value)
{
  digitalWrite(MAX7219_CS, LOW);
  shiftOut(MAX7219_DIN, MAX7219_CLK, MSBFIRST, reg);
  shiftOut(MAX7219_DIN, MAX7219_CLK, MSBFIRST, value);
  digitalWrite(MAX7219_CS, HIGH);
}

// ... reset the max7219 chip
void resetDisplay()
{
  set_register(MAX7219_REG_SHUTDOWN, OFF);  // turn off display
  set_register(MAX7219_REG_DISPTEST, OFF);  // turn off test mode
  set_register(MAX7219_REG_INTENSITY, 0x0A); // display intensity
}

// ... display the TIME on the 7-segment display
void displayTime(String timeString)
{
  set_register(MAX7219_REG_SHUTDOWN, OFF);  // turn off display
  set_register(MAX7219_REG_SCANLIMIT, 7);  // scan limit 8 digits
  set_register(MAX7219_REG_DECODE, 0b11111111); // decode all digits

    set_register(5, timeString.charAt(6));  //sekundy
    set_register(6, timeString.charAt(7));  //dziesiątki sekund
    set_register(4, timeString.charAt(4));  //minuty
    set_register(3, timeString.charAt(3));  //dziesiątki minut
    set_register(2, timeString.charAt(1));  //godziny
    set_register(1, timeString.charAt(0));  //dziesiątki godzin
    //  set_register(3, timeString.charAt(2));  //minus po godzinach
    //  set_register(6, timeString.charAt(5));  //minus po minutach

  set_register(MAX7219_REG_SHUTDOWN, ON);  // Turn on display
}
 
Odpowiedź
  


Wiadomości w tym wątku
Pomoc w dopisaniu sterowania przyciskami ustawienia godzin minut i sekund w zegarze - przez ALIBABA-125 - 04-08-2022, 15:19

Skocz do:


Przeglądający: 1 gości