Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. //sensors
  2. const int pressPin = A1;
  3. const int photoPin = A2;
  4. int pressValue = 0;
  5. int photoValue = 0;
  6. int pressBrightness = 0;
  7. int photoBrightness = 0;
  8.  
  9. //LEDs
  10. const int redLED = 3;
  11. const int yellowLED = 6;
  12. const int greenLED = 9;
  13. const int blueLED = 10;
  14.  
  15. void setup() {
  16. // put your setup code here, to run once:
  17. pinMode(pressPin, INPUT);
  18. pinMode(photoPin, INPUT);
  19. pinMode(redLED, OUTPUT);
  20. pinMode(yellowLED, OUTPUT);
  21. pinMode(greenLED, OUTPUT);
  22. pinMode(blueLED, OUTPUT);
  23.  
  24. //initialize serial communication
  25. Serial.begin(9600);
  26.  
  27. }
  28.  
  29. void loop() {
  30. // put your main code here, to run repeatedly:
  31. pressValue = analogRead(pressPin);
  32. photoValue = analogRead(photoPin);
  33. pressBrightness = map(pressValue, 0, 540, 0, 255);
  34. photoBrightness = map(photoValue, 140, 960, 0, 255);
  35. Serial.println(pressBrightness);
  36. Serial.println(photoBrightness);
  37.  
  38. analogWrite(redLED, photoBrightness);
  39. analogWrite(yellowLED, photoBrightness);
  40. analogWrite(greenLED, pressBrightness);
  41. analogWrite(blueLED, pressBrightness);
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement