Advertisement
brownj

Untitled

Jun 22nd, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. /*
  2. * James Brown
  3. * Version 1
  4. *
  5. *
  6. */
  7.  
  8. const int pinPhoto = A0;
  9. const int pinred= 9;
  10. const int pingreen = 10;
  11. const int pinblue = 11;
  12. int lightLevel = 0;
  13. int bright = 0;
  14.  
  15.  
  16. void setup() {
  17. // put your setup code here, to run once:
  18.  
  19. pinMode (pinPhoto, INPUT);
  20. pinMode (pinred, OUTPUT);
  21. pinMode (pingreen, OUTPUT);
  22. pinMode (pinblue, OUTPUT);
  23. Serial.begin (9600);
  24.  
  25. analogWrite (pinred, 255);
  26. delay (500);
  27. analogWrite (pinred, 0);
  28. analogWrite (pingreen, 255);
  29. delay (500);
  30. analogWrite (pingreen, 0);
  31. analogWrite (pinblue, 255);
  32. delay (500);
  33. analogWrite (pinblue, 0);
  34. }
  35.  
  36. void loop() {
  37. // put your main code here, to run repeatedly:
  38.  
  39. lightLevel = analogRead(pinPhoto);
  40. bright = map (lightLevel, 1, 118, 255, 0);
  41. bright = constrain(bright, 0, 255);
  42.  
  43. analogWrite (pinred, bright);
  44.  
  45. Serial.print (" Light Level = ");
  46. Serial.print (lightLevel);
  47. Serial.print ("bright = ");
  48. Serial.println (bright);
  49.  
  50.  
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement