Advertisement
sudoaptinstallname

Untitled

Sep 21st, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. const int photo_resist=A1;
  2.  
  3. const int Button = 2;
  4.  
  5. int PhotoVal;
  6. const int PinLed1 = 3;
  7. const int PinLed2 = 10;
  8. const int PinLed3 = 11;
  9.  
  10. unsigned long timeCount;
  11. int MinVal = 1000;
  12. int MaxVal = 0;
  13.  
  14. void setup() {
  15.  
  16. // put your setup code here, to run once:
  17.  
  18. Serial.begin(9600);
  19. pinMode (photo_resist, INPUT);
  20. pinMode (Button, INPUT);
  21.  
  22. pinMode(PinLed1, OUTPUT);
  23. pinMode(PinLed2, OUTPUT);
  24. pinMode(PinLed3, OUTPUT);
  25.  
  26. calibrate();
  27.  
  28. }
  29. void calibrate()
  30. {
  31. digitalWrite(PinLed1,HIGH);
  32. delay(50);
  33. digitalWrite(PinLed1,LOW);
  34. timeCount = millis();
  35. while(millis()-timeCount <= 5000)
  36. {
  37. PhotoVal = analogRead(photo_resist);
  38. if ( PhotoVal < MinVal)
  39. {
  40. MinVal = PhotoVal;
  41. }
  42. if (PhotoVal > MaxVal)
  43. {
  44. MaxVal = PhotoVal;
  45. }
  46. }
  47. Serial.println("End of Calibration.");
  48. Serial.println("MAXVAL");
  49. Serial.println(MaxVal);
  50.  
  51. digitalWrite(PinLed2,HIGH);
  52. delay(500);
  53. digitalWrite(PinLed2,LOW);
  54. Serial.println("MINVAL");
  55. Serial.println(MinVal);
  56. }
  57. void loop() {
  58. // put your main code here, to run repeatedly:
  59. PhotoVal = analogRead(photo_resist);
  60. Serial.println(PhotoVal);
  61. PhotoVal = map(PhotoVal, 228,579,255,0);
  62. PhotoVal = constrain(PhotoVal, 0,255);
  63. analogWrite(PinLed1, PhotoVal);
  64. analogWrite(PinLed2, PhotoVal);
  65. analogWrite(PinLed3, PhotoVal);
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement