Schupp icon

Nixie clock Siemens

Schupp | PRO | 04/21/21 02:07:42 PM UTC | 0 ⭐ | 706 👁️ | Never ⏰ | []
C++ |

2.52 KB

|

None

|

0 👍

/

0 👎

#include <DS3232RTC.h> //http://github.com/JChristensen/DS3232RTC
#include <Time.h> //http://www.arduino.cc/playground/Code/Time
#include <Wire.h> //http://arduino.cc/en/Reference/Wire (included withArduino IDE)
 
int latchPin = 10;
int clockPin = 11;
int dataPin = 12;
int enablePin = 9;
int hour_adjust=8;
int mylasthour=0;
int mylastminute=0;
int MeineFolge[9] = { 2, 1, 0, 3, 6, 5, 4, 7 };
 
 
void setup() {
  
  //RTC.set(1521872250);
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  pinMode(enablePin, OUTPUT);
  pinMode(hour_adjust, INPUT);
  digitalWrite(latchPin, 0);
  digitalWrite(enablePin, 1); 
  digitalWrite(hour_adjust, HIGH); 
  if(digitalRead(hour_adjust)==HIGH)
    setSyncProvider(summertime);
  else
    setSyncProvider(wintertime);
  if (timeStatus() != timeSet)
    Serial.println("Unable to sync with the RTC");
  else
    Serial.println("RTC has set the system time");
  setSyncInterval(30);
}
 
time_t wintertime(){
  time_t time=RTC.get()+3600;
  return time;
}
time_t summertime(){
  time_t time=RTC.get()+7200;
  return time;
}
 
void loop() {
 
  if(mylasthour!=hour()|| mylastminute!=minute())            
  {
    settime(hour(), minute(), 0);
    mylasthour=hour();
    mylastminute=minute();
  }
}
 
 
void settime(unsigned int Stunden, unsigned int Minuten, unsigned int temp) {
  shiftOut(dataPin, clockPin, LSBFIRST,swapNibbles(reverse(mysort(uint2bcd(Minuten)))));
  shiftOut(dataPin, clockPin, LSBFIRST,swapNibbles(reverse(mysort(uint2bcd(Stunden)))));
  digitalWrite(latchPin, 1);                // flick the latch to putthe data on the output pins
  delay(100);
  digitalWrite(latchPin, 0);
  delay(100);
}
 
static unsigned int uint2bcd(unsigned int ival)// macht aus einem zweistelligem Int ein B11110000 Doppelbcd
{
  return ((ival / 10) << 4) | (ival % 10);
}
 
unsigned char swapNibbles(unsigned char x) //macht aus B00001111 B11110000 Nibbles=halbes Byte
{
  return ( (x & 0x0F) << 4 | (x & 0xF0) >> 4 );
}
 
unsigned char reverse(unsigned char b) { //macht aus einem B0000001 ein B1000000
  b = (b & 0xF0) >> 4 | (b & 0x0F) << 4;
  b = (b & 0xCC) >> 2 | (b & 0x33) << 2;
  b = (b & 0xAA) >> 1 | (b & 0x55) << 1;
  return b;
}
 
unsigned int mysort(unsigned int ival) //sortiert BCD zu den Pins des Schieberegisters //Pins zu B ABCDABCD
{
  uint8_t mytempival = 0;
  for (int i = 0; i < 7; i++) {
    if (bitRead(ival, i) == 1) {
      bitWrite(mytempival, MeineFolge[i], 1);
 
    }
  }
 
  return mytempival;
}
 
 
 
 

Comments