2015-01-01 4 views
1

내 프로젝트 및 RTC 용 Real-Time Clock 모듈 인 Arduino mini 5V를 사용하고 있습니다. DS1307 특정 시간에 보드를 깨우고 기능을 실행하고 싶습니다. 혼자 수동으로 TimeAlarm를 사용 설정하면Arduino 미니를 사용하는 RTC + Scheduler

은 시간 모든 작동합니다 (부저가 D3에 연결) : 나는 RTC를 사용하는 경우에는 부저 함수가 호출되지 것


#include "Time.h" 
#include "TimeAlarms.h" 

void setup(){ 
    setTime(22,29,55,12,31,14); // set time to Saturday 8:29:00am Jan 1 2011 

    Alarm.alarmRepeat(10,30,0,buzz); // 10:30am every day 
    Alarm.alarmRepeat(16,30,0,buzz); // 4:30pm every day 
    Alarm.alarmRepeat(22,30,0,buzz); // 10:30pm every day 

    Serial.begin(9600); 
} 

void loop(){ 
    digitalClockDisplay(); 
    Alarm.delay(1000); 
} 

void buzz(){ 
    tone(3, 220, 1000); 
} 

void digitalClockDisplay(){ 
    // digital clock display of the time 
    Serial.print(hour()); 
    printDigits(minute()); 
    printDigits(second()); 
    Serial.println(); 
} 

void printDigits(int digits){ 
    Serial.print(":"); 
    if(digits < 10) 
    Serial.print('0'); 
    Serial.print(digits); 
} 
,

첫 페이지 : 여전히

#include <Wire.h> 
#include "RTClib.h" 
#include "Time.h" 
#include "TimeAlarms.h" 

RTC_Millis rtc; 

void setup(){ 
    rtc.begin(DateTime(F(__DATE__), F(__TIME__))); 

    Alarm.alarmRepeat(10,30,0,buzz); // 10:30am every day 
    Alarm.alarmRepeat(16,30,0,buzz); // 4:30pm every day 
    Alarm.alarmRepeat(22,30,0,buzz); // 10:30pm every day -- modify this to your current time when running the example 

    Serial.begin(9600); 
} 

void loop(){ 
    //printing the current time 
    DateTime now = rtc.now(); 

    Serial.print(now.year()); 
    Serial.print('/'); 
    Serial.print(now.month()); 
    Serial.print('/'); 
    Serial.print(now.day()); 
    Serial.print(' '); 
    Serial.print(now.hour()); 
    Serial.print(':'); 
    Serial.print(now.minute()); 
    Serial.print(':'); 
    Serial.print(now.second()); 
    Serial.println(); 
    Alarm.delay(1000); // wait one second between clock display 
} 

void buzz(){ 
    tone(3, 220, 1000); 
} 
+0

에 같은 변경,하지만 난 참조를 참조하지 마십시오 주석의 일부임을 발견 하단 스 니펫에서 '부저'로 ... –

+0

개인 정보 보호를 위해이 예를 편집해야했습니다. 그래서 여기에서 나는 그것을 바로 고쳤다. 언급 해 주셔서 감사합니다! –

+0

익명화 된 축소 버전을 실행할 수 있습니까? 위의 코드는 –

답변

2

OK 그래서 난 대답을 발견하지만 시간을 인쇄 문제는 RTC_Millis 대신 RTC_DS1307을 사용하는 것입니다.

RTC ds1307은 Arduino mini에서 A3 및 VCC보다 높은 12C 핀을 말합니다. 그들은 납땜이 필요합니다.

#include <Wire.h> 
#include "RTClib.h" 
#include "Time.h" 
#include "TimeAlarms.h" 

RTC_DS1307 rtc; 
const int output = 3; 

uint32_t syncProvider()//function which sets up the RTC as the source of external time{ 
    return rtc.now().unixtime(); 
} 


void setup(){ 
    Wire.begin(); 
    rtc.begin(); 
    rtc.adjust(DateTime(__DATE__, __TIME__));//comment this out when the RTC has been set 
    setSyncProvider(syncProvider); // the function to get the time from the RTC 


    Alarm.alarmRepeat(10,30,0,buzzer); // 10:30am every day 
    Alarm.alarmRepeat(16,30,0,buzzer); // 4:30pm every day 
    Alarm.alarmRepeat(22,30,00,buzzer); // 10:30pm every day 

    pinMode(output , OUTPUT);//new line 
    Serial.begin(9600); 
} 

void loop(){ 

    //printing the current time 
    DateTime now = rtc.now(); 

    Serial.print(now.year()); 
    Serial.print('/'); 
    Serial.print(now.month()); 
    Serial.print('/'); 
    Serial.print(now.day()); 
    Serial.print(' '); 
    Serial.print(now.hour()); 
    Serial.print(':'); 
    Serial.print(now.minute()); 
    Serial.print(':'); 
    Serial.print(now.second()); 
    Serial.println(); 
    Alarm.delay(1000); // wait one second between clock display 
} 

void buzzer(){ 
//Do Stuff 
} 
0

그냥 나처럼 멍청한 놈 도움이 시도 않은 : 그 그들이 M/F 와이어

다음
SDA -> to the pin above A3 
SCL -> to the pin above VCC 

을 사용하여 SDA 및 SCL에 연결해야 할 일단 난 다음에 코드를 변경 복사 붙여 넣기를 사용하여 코드 오류 발생

명명 된 반환 값은 더 이상 지원되지 않습니다. 오류 컴파일. 인터넷을 통해 검색 한 후

{ 악명 높은 중괄호 그래서 내가 잘못 될 수

uint32_t syncProvider() { //function which sets up the RTC as the source of external time  
     return rtc . now() . unixtime(); 
    }