SHARE
TWEET

Untitled

ambersy314 Jun 19th, 2017 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const int photoPin=A0;
  2. int photoValue=0;
  3. int lightVal=0;
  4. const int PinRed=9;
  5. const int PinGreen=10;
  6. const int PinBlue=11;
  7. const int pinButt=6;
  8. int newButt=0;
  9. int lastButt=0;
  10. int min = 1000;
  11. int max = -1000;
  12. unsigned long timeVal;
  13.  
  14. void setup()
  15. {
  16.   // put your setup code here, to run once:
  17.  
  18. Serial.begin(9600);
  19. pinMode(photoPin, INPUT);
  20. pinMode (PinRed, OUTPUT);
  21. pinMode (PinBlue, OUTPUT);
  22. pinMode(PinGreen, OUTPUT);
  23. analogWrite(PinRed, 255);
  24. analogWrite(PinGreen, 0);
  25. analogWrite(PinBlue, 0);
  26. delay (500);
  27. analogWrite(PinRed, 0);
  28. analogWrite(PinGreen, 255);
  29. analogWrite(PinBlue, 0);
  30. delay(500);
  31. analogWrite(PinRed, 0);
  32. analogWrite(PinGreen, 0);
  33. analogWrite(PinBlue, 255);
  34. }
  35. void calibrate ()
  36. {
  37.   min = 5000;
  38.   max = -5000;
  39.   analogWrite (PinRed, 0);
  40.   analogWrite (PinBlue, 0);
  41.  digitalWrite (PinGreen, LOW);
  42.  delay(200);
  43.  digitalWrite(PinRed, HIGH);
  44.  delay (200);
  45.  digitalWrite(PinRed, LOW);
  46.   timeVal =millis();
  47. while (millis ()-timeVal<5000)
  48. {
  49.   photoValue = analogRead(photoPin);
  50.   if (photoValue > max)
  51.   {
  52.     max = photoValue;
  53.   }
  54.   else if (photoValue < min)
  55.   {
  56.     min = photoValue;
  57.   }
  58. }
  59. Serial.println(min);
  60. Serial.println(max);
  61. digitalWrite (PinGreen, LOW);
  62. delay (200);
  63. digitalWrite (PinGreen, LOW);
  64. }
  65. boolean debounce (boolean last)
  66. {
  67.   boolean current = digitalRead(pinButt);
  68.   if (last != current)
  69.   {
  70.     delay(5);
  71.     current = digitalRead(pinButt);
  72.   }
  73.   return current;
  74. }
  75.  
  76. void loop()
  77. {
  78.   // put your main code here, to run repeatedly:
  79. newButt = debounce (lastButt);
  80.   if(newButt==HIGH && lastButt ==LOW)
  81.   {
  82.    calibrate();
  83.   }
  84.   lastButt=newButt;
  85.  
  86. photoValue=analogRead (photoPin);
  87. lightVal=map (photoValue, min, max, 255, 0);
  88. lightVal=constrain (lightVal, 0, 255);
  89.  
  90. analogWrite (PinRed, lightVal);
  91. analogWrite (PinGreen,0);
  92. analogWrite (PinBlue, lightVal);
  93. {
  94.  
  95. if
  96. (photoValue > (min && photoValue)< (max-min/3));
  97.   analogWrite (PinBlue, lightVal);
  98.   analogWrite (PinRed, lightVal);
  99.   analogWrite (PinGreen, 0);
  100.  
  101.  else if
  102. (photoValue > (min && photoValue) < (max-min/2));
  103.   analogWrite (PinBlue, lightVal*.25);
  104.   analogWrite (PinRed, lightVal * 71);
  105.   analogWrite (PinGreen, lightVal * .12);
  106.  
  107. else if
  108.  
  109.   (photoValue > (min && photoValue) < (max-min/1));
  110.   analogWrite (PinBlue, lightVal*50);
  111.   analogWrite (PinRed, 0);
  112.   analogWrite (PinGreen, lightVal * 90);
  113. }
RAW Paste Data
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top