Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #ifdef __AVR__
  2. #include <avr/power.h>
  3. #endif
  4.  
  5. int led1 = 11;
  6. int led2 = 10;
  7. int led3 = 9;
  8.  
  9. void setup() {
  10. Serial.begin(9600);
  11. }
  12.  
  13. void loop() {
  14.  
  15. if(Serial.available())
  16. {
  17. int incomingVal = Serial.read();
  18. Serial.print(incomingVal);
  19. if(incomingVal <= 85)
  20. {
  21. analogWrite(led1, incomingVal);
  22. analogWrite(led2, LOW);
  23. analogWrite(led3, LOW);
  24. }
  25. if(incomingVal > 85 && incomingVal<= 170)
  26. {
  27. analogWrite(led1, LOW);
  28. analogWrite(led2, incomingVal);
  29. analogWrite(led3, LOW);
  30. }
  31. if(incomingVal > 170 && incomingVal <= 255)
  32. {
  33. analogWrite(led1, LOW);
  34. analogWrite(led2, LOW);
  35. analogWrite(led3, incomingVal);
  36. }
  37. if(incomingVal < 0 || incomingVal > 255)
  38. {
  39. analogWrite(led1, LOW);
  40. analogWrite(led2, LOW);
  41. analogWrite(led3, LOW);
  42. }
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement