Advertisement
Guest User

Dựng

a guest
Sep 25th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <string.h>
  2. #include <Wire.h>
  3. #include <DS1307.h>
  4.  
  5. #define CB_AS A0 /// cảm biến này trả về giá trị 0 ~ 5v - tín hiệu tương tự
  6. #define CB_CD 2 /// cảm biến này trả về giá trị 0 và 1 - tín hiệu số
  7. #define LED 3
  8. int val_cd;
  9. int val_as;
  10. int RTCValues[7];
  11. void setup() {
  12.   pinMode(CB_AS, INPUT);
  13.   pinMode(CB_CD, INPUT);
  14.   pinMode(LED, OUTPUT);
  15.   DS1307.begin();
  16.   DS1307.setDate(18, 09, 25, 3, 22, 40, 30); // set ngày giờ tháng năm
  17. }
  18.  
  19. void loop() {
  20.   DS1307.getDate(RTCValues); /// RTCValues[4] là giờ
  21.  
  22.   if (RTCValues[4] > 21)
  23.   {
  24.     val_as = analogRead(CB_AS); /// vì độ phân giải adc của arduino là 10-bit ~ 2^10 = 1024  ... Vì vậy 0 ~ 0v, 1024 ~ 5v -------- đọc tín hiệu tương tự
  25.     val_cd = digitalRead(CB_CD); /// đọc tín hiệu số
  26.     if(val_cd == 1)
  27.     {
  28.       analogWrite(LED, 255);
  29.       delay(1000); /// delay giữa các lần có người
  30.     }
  31.     else
  32.     {
  33.       analogWrite(LED, 125); /// cho đèn tối hơn
  34.     }
  35.   }
  36. }
  37. ///// chưa thấy tác dụng của thằng cảm biến ánh sáng :))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement