Example #1
0
/*
 * Read (and debounce) the current state of the attached relays.
 * Note that when a relay is closed, we treat that as true or 1,
 * and when it's open, we treat that as false or 0.
 */
void serviceRelays() {
  int i;
  uint16_t oldState = state;
  uint16_t readState = 0;

  // Read the active pins  
  for (i=0; i<PIN_COUNT; i++) {
	uint16_t mask = (1 << i);
	if (mask & activePins) {
	  // lines go to ground when relays close. (closed = 1, open = 0)
	  if (LOW == digitalRead(i)) {
        readState |= mask;
      }
	}
  }

  // Add the latest sample to our ring buffer, giving us the last
  // n samples so we can debounce
  ringIndex = ++ringIndex % RING_SIZE;
  stateRing[ringIndex] = readState;

  // Debounce - each bit needs to be stable across all n samples
  // before we consider it valid.  
  uint16_t andBits = stateRing[0];  // andBits tells us what bits are stable at a value of 1
                                    // (each 1 bit in andBits indicates a stable value of 1)
  uint16_t orBits = stateRing[0];   // orBits will tell us what bits are stable at a value of 0
                                    // (each 0 bit in orBits indicate a stable value of 0)

  // combine our samples and see what's stable									
  for (i=1;i<RING_SIZE;i++) {
    andBits &= stateRing[i];
    orBits |= stateRing[i];
  }
                
  // Set bits that are stable at 1
  state |= andBits;

  // clear bits that are stable at 0
  state &= orBits;
  
  if (state != oldState) {
    time_t t = now();
    Serial.print(hour(t));  
    Serial.print(":");
    Serial.print(minute(t));
    Serial.print(":");
    Serial.println(second(t));
    Serial.print("Relay state: ");
    Serial.println(state);
  }

}
void loop()
{

	// digital clock display of the time
	sprintf(msg_buff,"%02d:%02d:%02d  %s",hour(),minute(),second(),  dayStr(weekday()));
		sprintf(msg_buff,"%s %d %s %d\r\n",msg_buff, day(),monthStr(month()), year());

	//Send the data
	uart_printf(msg_buff);

	// 1 sec delay
   delay(1000);
}
Example #3
0
void digitalClockDisplay() {
  // digital clock display of the time
  print_dbg(hour());
  printDigits(minute());
  printDigits(second());
  print_dbg(" ");
  print_dbg(day());
  print_dbg(".");
  print_dbg(month());
  print_dbg(".");
  print_dbg(year());
  println_dbg();
}
 inline BTime dateTimeToBTime(QDateTime dateTime)
 {
     auto date = dateTime.date();
     auto time = dateTime.time();
     BTime btime;
     btime.year = date.year();
     btime.day = date.dayOfYear();
     btime.hour = time.hour();
     btime.min = time.minute();
     btime.sec = time.second();
     btime.fract = time.msec();
     return btime;
 }
Example #5
0
void digitalClockDisplayLCD() {
  // digital clock display of the time
  // Serial /w Debug
  sprintf(buffer, "$FT,Y0,X0#%04d-%02d-%02d ", year(), month(), day());
  Serial.print(buffer);
  sprintf(buffer, "$FT,Y1,X0#%s W%02d D%03d", dow2String(weekday()), WN, DN);
  Serial.print(buffer);
  sprintf(buffer, "$Y5,X0#%02d:%02d:", hour(), minute());
  Serial.print(buffer);
  sprintf(buffer, "$FN,Y5,X35#%02d", second());
  Serial.print(buffer);
  Serial.print(F("$FT#"));
  // I2C LCD
  LcdSetCursor(0, 0);
  sprintf(buffer, "%04d-%02d-%02d %s", year(), month(), day(),
          dow2String(weekday()));
  LcdPrint(buffer);
  sprintf(buffer, "%02d:%02d:%02d W%02d %03d", hour(), minute(), second(), WN,
          DN);
  LcdSetCursor(0, 1);
  LcdPrint(buffer);
}
Example #6
0
void Time() {
    lastCount = count;
    ++count;
    // digital clock display of the time
    Serial.print("Cycle: ");
    Serial.print(hour());
    Serial.print(minute());
    Serial.print(second());
    Serial.print(day());
    Serial.print(month());
    Serial.print(year());
    Serial.println();

}
Example #7
0
void digitalClockDisplay()
{
	time_t t = now();
	printDigits(hour(t)  ,' ');
	printDigits(minute(t),':');
	printDigits(second(t),':');
	Serial.print(" ");
	Serial.print(day(t));
	Serial.print(" ");
	Serial.print(month(t));
	Serial.print(" ");
	Serial.print(year(t)); 
	Serial.println(); 
}
Example #8
0
void updateAlarm()
{
	time_t almTime = wkAlarm.getAlarmTime();
	int h = hour(almTime);
	int m = minute(almTime);

	digitValues[0] = h / 10;
	digitValues[1] = h % 10;
	digitValues[2] = m / 10;
	digitValues[3] = m % 10;

	for (int i = 0; i < N; i++)
		display.writeDigit(i, digitValues[i]);
}
Example #9
0
// ---------------------- //
//  Display Update fnc
// ---------------------- //
void updateTime()
{
	time_t t = now();
	int h = hour(t);
	int m = minute(t);

	digitValues[0] = h / 10;
	digitValues[1] = h % 10;
	digitValues[2] = m / 10;
	digitValues[3] = m % 10;

	for (int i = 0; i < N; i++)
		display.writeDigit(i, digitValues[i]);
}
Example #10
0
void printAlarmStatus()
{
	time_t almSet = wkAlarm.getAlarmTime();
	byte h, m, rtcOn;
	h = hour(almSet);
	m = minute(almSet);
	printDigits(h,' ');
	printDigits(m,':');
	rtcOn = isRtcAlarmOn();
	if (rtcOn)
		Serial.println(" -- ON");
	else
		Serial.println(" -- OFF");

}
Example #11
0
void RRTime::digitalClockDisplay(){
  // digital clock display of the time
  DEBUGPRINT.print(hour());
  DEBUGPRINT.print(":");
  DEBUGPRINT.print(getDigits(minute()));
  DEBUGPRINT.print(":");
  DEBUGPRINT.print(getDigits(second()));
  DEBUGPRINT.print(" ");
  DEBUGPRINT.print(day());
  DEBUGPRINT.print(".");
  DEBUGPRINT.print(month());
  DEBUGPRINT.print(".");
  DEBUGPRINT.print(year()); 
  DEBUGPRINT.println(); 
}
/**
 * \brief Returns the value of the digital input
 *
 * \returns 1 if input is HIGH or 0 if input is LOW.
 */
double SerialAtlasEC::read()
{
    Sensor* sensor;
    // Serial.println("EC");
    // Serial.println(actualEC);

    // init Sensor
    if (initCounter < 10000)
        initCounter++;
    if (initCounter == 10000)
    {
        __aquaduino->resetSensorIterator();
        while (__aquaduino->getNextSensor(&sensor) != -1)
        {
            if (sensor->getType() == SENSOR_DS18S20)
            {
                tempSensorID=__aquaduino->getSensorID(sensor);
            }
        }

        Serial1.print("25.00,C\r");
        Serial.println("EC set to send continuous data");
        initCounter++;
    }
    //set Temperature every Minute
    if (minute() != curMin)
        {
            curMin = minute();
            Serial.print(__aquaduino->getSensorValue(tempSensorID));
            Serial.println((" Set new Temperature to EC"));
            Serial1.print(__aquaduino->getSensorValue(tempSensorID));
            Serial1.print(",C\r");

        }
    return actualEC;
}
Example #13
0
String hourString(){
//	String s;
//	appendLong(s,hour(),2);
//	s+= ':';
//	appendLong(s,minute(),2);
//	s+= ':';
//	appendLong(s,second(),2);

	XString s;
	s.formatLong(hour(),2);
	s+= ':';
	s.formatLong(minute(),2);
	s+= ':';
	s.formatLong(second(),2);
	return s;
}
Example #14
0
byte PWMParabola(byte startHour, byte startMinute, byte endHour, byte endMinute, byte startPWM, byte endPWM, byte oldValue)
{
	int Now = NumMins(hour(), minute());
	int Start = NumMins(startHour, startMinute);
	int End = NumMins(endHour, endMinute);
	byte PWMDelta = endPWM-startPWM;
	byte ParabolaPhase=constrain(map(Now,Start,End,0,180),0,180);

	if ( Now <= Start || Now >= End)
		return oldValue;
	else
	{
		return startPWM+(PWMDelta*sin(radians(ParabolaPhase)));
	}

}
Example #15
0
void Clock::display()
{
   Serial.print(hour());
   Serial.print(':');
   Serial.print(minute());
   Serial.print(':');
   Serial.println(second());
   
   Serial.print(' ');
   Serial.print(day());
   Serial.print('/');
   Serial.print(month());
   Serial.print('/');
   Serial.println(year());
   
};
// Print time to a given line
void OSLocalUI::lcd_print_time(byte line)
{
  time_t t=nntpTimeServer.LocalNow();
  lcd.setCursor(0, line);
  lcd_print_2digit(hour(t));

  lcd_print_pgm( t%2 > 0 ? PSTR(":") : PSTR(" ") );                     // flashing ":" in the time display

  lcd_print_2digit(minute(t));
  lcd_print_pgm(PSTR("  "));
  lcd_print_pgm(days_str[weekday_today()]);
  lcd_print_pgm(PSTR(" "));
  lcd_print_2digit(month(t));
  lcd_print_pgm(PSTR("-"));
  lcd_print_2digit(day(t));
}
Example #17
0
void printTime(time_t t, char *tz) {
    sPrintI00(hour(t));
    sPrintDigits(minute(t));
    sPrintDigits(second(t));
    Serial.print(' ');
    Serial.print(weekday(t));
    Serial.print(' ');
    sPrintI00(day(t));
    Serial.print(' ');
    Serial.print(month(t));
    Serial.print(' ');
    Serial.print(year(t));
    Serial.print(' ');
    Serial.print(tz);
    Serial.println();
}
void TimeState::renderClockType1(){
   Serial.println(F("render time type 1"));
  _screen->clearDisplay();
  _screen->setTextSize(5);
  _screen->setCursor(0, 0);
  _screen->setTextWrap(false);
  int8_t hour_time = hour();
  if(hour_time==0)
    hour_time = (uint8_t) 12;
  else if(hour_time>=13)
    hour_time -= (uint8_t) 12;
    
  if(hour_time<=9)
  {
    _screen->setCursor(30, 0);
    _screen->print(hour_time);
  }
  else
    _screen->print(hour_time);
    
  _screen->setCursor(50, 0);
  _screen->print(":");
  _screen->setCursor(70, 0);
  int8_t minute_time = minute();
  
  if(minute_time<=9){ 
    _screen->print("0");
    _screen->setCursor(99, 0);
    _screen->print(minute_time);
  }
  else
    _screen->print(minute_time);
    
    
  _screen->setTextSize(2);

  char *wkdy[7] = {"SUN", "MON", "TUE", "WED", "THR", "FRI", "SAT"};
  _screen->setCursor(5, 43);
  _screen->print(wkdy[weekday()-1]);
  _screen->setCursor(60, 43);
  _screen->print(month());
  _screen->setCursor(78, 43);
  _screen->print("/");
  _screen->setCursor(95, 43);
  _screen->print(day());
  _screen->display();
}
Example #19
0
void timeSync() {
  uint16_t s = (uint32_t)4 * (PWMRANGE + 1) * (hour() * 3600 + minute() * 60 + second()) / (24 * 60 * 60);
  uint16_t setValue;
  if (s < (PWMRANGE + 1)) {
    setValue = 0;
  } else if (s < 2 * (PWMRANGE + 1)) {
    setValue = s - (PWMRANGE + 1);
  } else if (s < 3 * (PWMRANGE + 1)) {
    setValue = 3 * (PWMRANGE + 1) - (s + 1);
  } else {
    setValue = 0;
  }
  red.set(setValue);
  green.set(setValue);
  blue.set(setValue);
  white.set(setValue);
}
Example #20
0
void main()
{
	ANSEL = 0x00;
	TRISA = 0xFF;
	TRISB = 0b00000100;

	// Structure that holds human readable time information;
	struct tm tinfo;

	// Local time to get
	time_t now;

	// Store last time we sent the information
	uint32_t last = 0;

	// Set time manually to 13:55:30 Jan 1st 2014
	tinfo.tm_year = 14;
	tinfo.tm_mon = 1;
	tinfo.tm_mday = 1;
	tinfo.tm_hour = 13;
	tinfo.tm_min = 55;
	tinfo.tm_sec = 30;

	// Tick Initialization
	tick_init();
	// Convert time structure to timestamp
	initialt = time_make(&tinfo);
	// Set system time counter
	time_set(initialt);
	// Set the function to get accurate time
	time_set_provider(&time_provider, TIME_SECS_PER_DAY);

	printf("TimeLib Test Program\r\n");

	E_

	for (;;) {
		// Display the time every second
		if (tick_get() - last > TICK_SECOND) {
			last = tick_get();
			// Send to serial port
			printf("Time: %02d:%02d:%02d Date: %02d/%02d/%02d\r\n", hour(), minute(), second(), day(), month(), year());
		}
	}

}
Example #21
0
void loop() {
  Serial.print(year(), DEC);
  Serial.print('/');
  Serial.print(month(), DEC);
  Serial.print('/');
  Serial.print(day(), DEC);
  Serial.print(" (");
  Serial.print(monthStr(month()));
  Serial.print(") ");
  Serial.print(hour(), DEC);
  Serial.print(':');
  Serial.print(minute(), DEC);
  Serial.print(':');
  Serial.print(second(), DEC);
  Serial.println();

  delay(5000);
}
Example #22
0
void DateTime::format(std::string& str, const std::string& fmt, int timeZoneDifferential)
{
    std::string::const_iterator it  = fmt.begin();
    std::string::const_iterator end = fmt.end();
    while (it != end)
    {
        if (*it == '%')
        {
            if (++it != end)
            {
                switch (*it)
                {
                case 'w': str.append(WEEKDAY_NAMES[dayOfWeek()], 0, 3); break;
                case 'W': str.append(WEEKDAY_NAMES[dayOfWeek()]); break;
                case 'b': str.append(MONTH_NAMES[month() - 1], 0, 3); break;
                case 'B': str.append(MONTH_NAMES[month() - 1]); break;
                case 'd': NumberFormatter::append0(str, (int32_t)day(), 2); break;
                case 'e': NumberFormatter::append(str, (int32_t)day()); break;
                case 'f': NumberFormatter::append(str, (int32_t)day(), 2); break;
                case 'm': NumberFormatter::append0(str, (int32_t)month(), 2); break;
                case 'n': NumberFormatter::append(str, (int32_t)month()); break;
                case 'o': NumberFormatter::append(str, (int32_t)month(), 2); break;
                case 'y': NumberFormatter::append0(str, (int32_t)year() % 100, 2); break;
                case 'Y': NumberFormatter::append0(str, (int32_t)year(), 4); break;
                case 'H': NumberFormatter::append0(str, (int32_t)hour(), 2); break;
                case 'h': NumberFormatter::append0(str, (int32_t)hourAMPM(), 2); break;
                case 'a': str.append(isAM() ? "am" : "pm"); break;
                case 'A': str.append(isAM() ? "AM" : "PM"); break;
                case 'M': NumberFormatter::append0(str, (int32_t)minute(), 2); break;
                case 'S': NumberFormatter::append0(str, (int32_t)second(), 2); break;
                case 'i': NumberFormatter::append0(str, (int32_t)millisecond(), 3); break;
                case 'c': NumberFormatter::append(str, (int32_t)millisecond()/100); break;
                case 'F': NumberFormatter::append0(str, (int32_t)millisecond()*1000 + microsecond(), 6); break;
                case 'z': tzdISO(str, timeZoneDifferential); break;
                case 'Z': tzdRFC(str, timeZoneDifferential); break;
                default:  str += *it;
                }
                ++it;
            }
        }
        else str += *it++;
    }
}
Example #23
0
void setup() {
    Serial.begin(115200);
    delay(2000);

    // We start by connecting to a WiFi network
    WiFi.mode (WIFI_STA);
    WiFi.begin (SETTINGS_NETWORK_SSID, SETTINGS_NETWORK_PASS);

    Serial.println();
    Serial.println();
    Serial.print("Wait for WiFi... ");

    while ( WiFi.status() != WL_CONNECTED ) {
      delay ( 500 );
      Serial.print ( "." );
    }

    if (! rtc.begin()) {
      Serial.println("Couldn't find RTC");
      while (1);
    }

    timeClient.begin();
    Serial.println("");
    Serial.println("WiFi connected");
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());
    Serial.println(__DATE__);
    Serial.println(__TIME__);

    // load time from network if rtc has lost power...
    if (rtc.lostPower()) {
        Serial.println("RTC lost power- set time from NTP");
        timeClient.update();
        setTime(timeClient.getEpochTime());
        rtc.adjust(DateTime(year(), month(), day(), hour(), minute(), second()));
    }


    DateTime now = rtc.now();
    setTime(now.unixtime());
    delay(500);
}
Example #24
0
string VSTime::toStringforWeb() const
{
	string result = "";
	char   buf1[10] = {0,};
	char   buf2[10] = {0,};

	sprintf(buf1, "%d", hour());
	sprintf(buf2, "%d", minute());

	string hour   = string(buf1);
	string minute = string(buf2);

	if (hour.size() == 1)   hour   = "0"  + hour;
	if (minute.size() == 1) minute = "0"  + minute;

	result += hour; // hour
	result += minute; // minute

	return result;
}
Example #25
0
byte PWMSlope(byte startHour, byte startMinute, byte endHour, byte endMinute, byte startPWM, byte endPWM, byte Duration, byte oldValue)
{
	int Now = NumMins(hour(), minute());
	int Start = NumMins(startHour, startMinute);
	int StartD = Start + Duration;
	int End = NumMins(endHour, endMinute);
	int StopD = End - Duration;

	if ( Now >= Start && Now <= StartD )
		return constrain(map(Now, Start, StartD, startPWM, endPWM),startPWM, endPWM);
	else if ( Now >= StopD && Now <= End )
	{
		byte v = constrain(map(Now, StopD, End, startPWM, endPWM),startPWM, endPWM);
		return endPWM-v+startPWM;
	}
	else if ( Now > StartD && Now < StopD )
		return endPWM;

    // lastly return the existing value
    return oldValue;
}
void Clock::printTime() {
	static boolean printColon = true;

	// 12:25 PM
	printLeadingCharacter(hourFormat12(currentTime), ' ');
	if (printColon)
		lcd.print(':');
	else
		lcd.print(' ');
	printColon = !printColon;
	printLeadingCharacter(minute(currentTime), '0');

	lcd.print(' ');
	if (isPM(currentTime))
	{
		lcd.print(F("PM"));
	}
	else
	{
		lcd.print(F("AM"));
	}
}
Example #27
0
//display the given time (if different from time given with prior call)
void GoldieClock::displayClock(time_t utc)
{
    static time_t utcLast;
    if ( utc != utcLast )
    {
        utcLast = utc;
        time_t local = (*tz).toLocal(utc, &tcr);
        uint8_t h = hour(local);
        uint8_t m = minute(local);
        uint8_t s = second(local);
        uint8_t hourHand = ( h >= 12 ? h - 12 : h ) * 5;
        hourHand = hourHand + m / 12;      //adjust hour hand between hours

        //one rainbow on the quarter hour, two on the half, four on the hour
        if ( s == 0  && _showRainbows )
        {
            if ( m == 15 || m == 45 ) rainbowCycle(2, 1);
            else if ( m == 30 ) rainbowCycle(2, 2);
            else if ( m == 0 ) rainbowCycle(2, 4);
        }

        clear();

        //hour hand (3 pixels wide)
        setPixelColor( LAST_PIXEL - hourHand, HOUR_HAND );
        setPixelColor( LAST_PIXEL - (hourHand + 1U > LAST_PIXEL ? FIRST_PIXEL : hourHand + 1U), HOUR_HAND_DIM );
        setPixelColor( LAST_PIXEL - (hourHand - 1U > LAST_PIXEL ? LAST_PIXEL : hourHand - 1U), HOUR_HAND_DIM );

        //minute hand & second hand -- additive colors
        setPixelColor( LAST_PIXEL - m, getPixelColor(LAST_PIXEL - m) + MINUTE_HAND );
        setPixelColor( LAST_PIXEL - s, getPixelColor(LAST_PIXEL - s) + SECOND_HAND );

        //hour markers (do not overlay hands)
        for (uint16_t i = 0; i <= LAST_PIXEL; i += 5)
            if ( getPixelColor(LAST_PIXEL - i) == 0 ) setPixelColor(LAST_PIXEL - i, HOUR_MARKER);

        show();
    }
}
Example #28
0
char* UTC(char* TimeSep){

  String utcDate = "";

  utcDate+= year();
  utcDate+= "-";
  utcDate+= month();
  utcDate+= "-";
  utcDate+= day();
  utcDate+= TimeSep;
  utcDate+= (hour());
  utcDate+= (":");
  utcDate+= (minute());
  utcDate+= (":");
  utcDate+= (second());

  for (int i=0; i < utcDate.length(); i++){      
      buffer[i] = utcDate[i];
  }
  
  buffer[utcDate.length()] = 0; 

  return buffer;
}
int minute() {
  return minute(now()); 
}
Example #30
-1
boolean Clock::parseDate(String t)
{ 
  // dd/mm/yyyy
  int d;
  int m;
  int y;
  if (t.length() != 10) return false;
  if (t.charAt(2) != '/' || t.charAt(5) != '/') return false;
  d=t.substring(0,2).toInt();
  m=t.substring(3,5).toInt();
  y=t.substring(6,10).toInt();
  if (d ==0 || m==0 || y==0) return false;

  //Todo adjust for local time?
  set(y,m,d,hour(),minute(),second());

  return true;
}