Advertisement
jaclyngoldstein00

Final program 6/28

Jun 28th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.67 KB | None | 0 0
  1. /*
  2. * Jaclyn Goldstein
  3. * Photoresistor stuff
  4. * Version 1
  5. */
  6.  
  7.  
  8. #include <Wire.h>
  9. #include <DS3231.h>
  10. DS3231 clock;
  11. RTCDateTime dt;
  12.  
  13.  
  14. #include <LiquidCrystal.h>
  15. LiquidCrystal lcd (11,10,2,3,4,5);
  16.  
  17. #include <Servo.h>
  18.  
  19. const int photoPin= A5; // change to data from RTC
  20. int photoVal=0; //change to time
  21.  
  22. const int pinPhoto= A2;
  23. int lightLevel=0;
  24. const int pinLEDred=9; //red
  25. const int pinLEDgreen=10; //green
  26. const int pinLEDblue=11; //blue
  27. int brightness=0;
  28. const int pinButt=A1;
  29. int lastButt= 0;
  30. int newButt=0;
  31. unsigned long timeStart;
  32. int minimum=5000;
  33. int maximum=-5000;
  34.  
  35. Servo miServito;
  36. const int PotPin=A0;
  37. int PotVal;
  38. int angle;
  39.  
  40. int ledPin = 9; // choose the pin for the LED
  41. int inputPin = 7; // choose the input pin (for PIR sensor)
  42. int pirState = LOW; // we start, assuming no motion detected
  43. int val = 0; // variable for reading the pin status
  44. //still dont know variables its fine literawuihdsofik
  45.  
  46. const int pinLED1=13;
  47. const int pinLED2=12;
  48.  
  49.  
  50. void setup() {
  51. // put your setup code here, to run once:
  52. pinMode (pinPhoto, INPUT);
  53. Serial.begin (9600);
  54. pinMode (pinButt, INPUT);
  55.  
  56. pinMode(inputPin, INPUT); // declare sensor as input
  57. Serial.begin(9600);
  58. pinMode (PotPin, INPUT);
  59. miServito.attach (9);
  60.  
  61. pinMode (photoPin, INPUT);
  62. Serial.begin (9600);
  63. // Initialize DS3231
  64. Serial.println("Initialize DS3231");;
  65. clock.begin();
  66.  
  67. // Set sketch compiling time
  68. clock.setDateTime(__DATE__, __TIME__);
  69. lcd.begin (16,2);
  70. lcd.print ("Hello");
  71. lcd.setCursor (12,0);
  72. lcd.print ("...");
  73. delay (1000);
  74. lcd.clear ();
  75. lcd.setCursor (4,1);
  76. lcd.print ("Human");
  77. delay (2000);
  78. lcd.clear ();
  79.  
  80. pinMode (pinLED1, OUTPUT);
  81. pinMode (pinLED2, OUTPUT);
  82. }
  83.  
  84. void loop()
  85. {
  86. newButt= debounce (lastButt);
  87. if (newButt== HIGH && lastButt==LOW)
  88. {
  89. Serial.println ("Calibrating...");
  90. lcd.print ("Calibrating...");
  91. calibrate ();
  92. }
  93. lastButt=newButt;
  94.  
  95. //FOR NIGHT LIGHT:
  96. lightLevel= analogRead (pinPhoto);
  97. brightness=map (lightLevel,minimum, maximum,255,0);
  98. brightness= constrain (brightness,0,255);
  99.  
  100. //constrain--> keeps variable within set of values
  101.  
  102. if (lightLevel>minimum)
  103. //&& lightLevel< (maximum-minimum)/3)
  104. {
  105. angle = 180;
  106. miServito.write (angle);
  107. delay (100);
  108. angle = 0;
  109. miServito.write (angle);
  110. delay (50);
  111. angle = 180;
  112. miServito.write (angle);
  113. delay (100);
  114. angle = 0;
  115. miServito.write (angle);
  116. delay (50);
  117.  
  118. lcd.begin (16,2);
  119. lcd.print ("Hello");
  120. lcd.setCursor (12,0);
  121. lcd.print ("...");
  122. delay (1000);
  123. lcd.clear ();
  124. lcd.setCursor (4,1);
  125. lcd.print ("Human");
  126. delay (2000);
  127. lcd.clear ();
  128.  
  129.  
  130. dt = clock.getDateTime();
  131. photoVal=analogRead (photoPin);
  132. lcd.print ("The time is:");
  133. lcd.setCursor (6,1);
  134. if(dt.hour<10)
  135. {
  136. lcd.print (0);
  137. lcd.print (dt.hour);
  138. if (dt.minute<10)
  139. {
  140. lcd.print (":");
  141. lcd.print (0);
  142. lcd.print (dt.minute);
  143. }
  144. else
  145. {
  146. lcd.print (":");
  147. lcd.print (dt.minute);
  148. }
  149. }
  150. else
  151. {
  152. if (dt.hour>12)
  153. {
  154. lcd.print (dt.hour-12);
  155. if (dt.minute<10)
  156. {
  157. lcd.print (":");
  158. lcd.print (0);
  159. lcd.print (dt.minute);
  160. }
  161. else
  162. {
  163. lcd.print (":");
  164. lcd.print (dt.minute);
  165. }
  166. }
  167. else
  168. {
  169. lcd.print (dt.hour);
  170. }
  171. }
  172. delay (1000);
  173. lcd.clear ();
  174.  
  175. digitalWrite (pinLED1, HIGH);
  176. digitalWrite (pinLED2, HIGH);
  177. delay (700);
  178. }
  179. else
  180. {
  181. angle = 0;
  182. miServito.write (angle);
  183. digitalWrite (pinLED1, LOW);
  184. digitalWrite (pinLED2, LOW);
  185. delay (200);
  186. }
  187. }
  188. boolean debounce(boolean last)
  189. {
  190. boolean current = digitalRead(pinButt);
  191. if (last != current);
  192. {
  193. delay(5);
  194. current = digitalRead(pinButt);
  195. }
  196. return current;
  197. }
  198.  
  199. void calibrate()
  200. {
  201. maximum= -5000;
  202. minimum=5000;
  203.  
  204. //^use to know when calibrate starts and ends
  205.  
  206. timeStart= millis();
  207. while (millis()-timeStart<5000)
  208. {
  209. lightLevel=analogRead (pinPhoto);
  210. if (lightLevel>maximum)
  211. {
  212. maximum=lightLevel;
  213. }
  214. else if (lightLevel<minimum)
  215. {
  216. minimum=lightLevel;
  217. }
  218. }
  219. Serial.println (minimum);
  220. // lcd.print (minimum);
  221. Serial.println (maximum);
  222. // lcd.print (maximum);
  223.  
  224.  
  225. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement