Arduino Polska Forum

Pełna wersja: Projekt RTC
Aktualnie przeglądasz uproszczoną wersję forum. Kliknij tutaj, by zobaczyć wersję z pełnym formatowaniem.
Witam,
mam pewien problem z moim kodem a mianowicie chciałbym, żeby po wyzwoleniu się alarmu dioda zaświeciła się tylko na 0,5s. Ma ktoś propozycje jak można by zmodyfikować ten kod? Chodzi mi o funkcję " LightOn "
-Arduino Pro mini 
-DS1307 RTC

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

RTC_DS1307 rtc;
const int output = 6;
volatile byte state = LOW;

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


void setup() {
 // put your setup code here, to run once:
 pinMode(output,OUTPUT); // LED output
 pinMode(2,INPUT); // Button input
 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(dowMonday,6,30,00,LightOn);
Alarm.alarmRepeat(dowTuesday,7,30,LightOn);
Alarm.alarmRepeat(dowWednesday,6,30,00,LightOn);
Alarm.alarmRepeat(dowThursday,7,30,00,LightOn);
Alarm.alarmRepeat(dowFriday,7,30,00,LightOn);
Alarm.alarmRepeat(dowSaturday,8,00,00,LightOn);
Alarm.alarmRepeat(dowSunday,8,00,00,LightOn);
}

void loop() {
 // put your main code here, to run repeatedly:
 static unsigned char ledState = LOW;
 static unsigned char buttonState = LOW;
 static unsigned char lastButtonState = LOW;
 static unsigned long ledCameOn = 0;
  //printing the current time
 DateTime now = rtc.now();
 Alarm.delay(1000);
 // If the button's state has changed, then turn the LED on IF it is not on already.
 buttonState = digitalRead(2);
 if(buttonState != lastButtonState)
 {
   lastButtonState = buttonState;
   if((buttonState == HIGH) && (ledState == LOW))
   {
     digitalWrite(output,HIGH);
     ledState = HIGH;
     ledCameOn = millis();
   }
 }

 
 
 // If the LED has been on for at least 5 seconds then turn it off.
 if(ledState == HIGH)
 {
   if(millis()- ledCameOn > 500)
   {
     digitalWrite(output,LOW);
     ledState = LOW;
   }
 }
}
void LightOn(){
 digitalWrite(output, HIGH);
}