Advertisement
inagantid20

RGB and photoresistor- purple light turns off when light on

Jun 15th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. /*
  2. *Divya Inaganti
  3. *June 14, 2017
  4. *RGB and photoresistor activity
  5. */
  6. const int photoPin = A0;
  7. const int PinRed= 9;
  8. const int PinGreen=10;
  9. const int PinBlue= 11;
  10. int photoValue= 0;
  11. int lightVal= 0;
  12. const int pinButton = 4;
  13. void setup()
  14. {
  15. Serial.begin (9600);
  16. pinMode(photoPin, INPUT);
  17. pinMode (PinRed, OUTPUT);
  18. pinMode (PinGreen, OUTPUT);
  19. pinMode (PinBlue, OUTPUT);
  20. pinMode(pinButton, INPUT);
  21.  
  22.  
  23. analogWrite(PinRed, 255);
  24. analogWrite(PinGreen, 0);
  25. analogWrite(PinBlue,0);
  26. delay(200);
  27. analogWrite(PinRed, 0);
  28. analogWrite(PinGreen, 255);
  29. analogWrite(PinBlue,0);
  30. delay(200);
  31. analogWrite(PinRed, 0);
  32. analogWrite(PinGreen, 0);
  33. analogWrite(PinBlue,255);
  34. delay(200);
  35. analogWrite(PinRed, 0);
  36. analogWrite(PinGreen, 0);
  37. analogWrite(PinBlue,0);
  38. }
  39. void loop()
  40. {
  41. photoValue= analogRead (photoPin);
  42. lightVal= map(photoValue, 0, 730, 255, 0);
  43. lightVal= constrain(lightVal, 0, 255);
  44. Serial.print ("Photoresistor value = ");
  45. Serial.print(photoValue);
  46. Serial.print ("lightVal = ");
  47. Serial.println(lightVal);
  48. analogWrite(PinRed, lightVal);
  49. analogWrite(PinBlue, lightVal);
  50. analogWrite(PinGreen,0);
  51. delay(100);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement