Advertisement
rosea4

code 3-2 in black book

Mar 24th, 2015
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. const int BLED=9 ;
  2. const int GLED=10 ;
  3. const int RLED=11 ;
  4. const int TEMP=0 ;
  5. const int LOWER_BOUND=146 ;
  6. const int UPPER_BOUND=167 ;
  7. int val = 0 ;
  8. int color=0;
  9. void setup ()
  10. {
  11. pinMode (BLED, OUTPUT) ;
  12. pinMode (GLED, OUTPUT) ;
  13. pinMode (RLED, OUTPUT) ;
  14. Serial.begin (9600) ;
  15. }
  16. void loop()
  17. {
  18. val = analogRead(TEMP) ;
  19. Serial.println(val);
  20. delay(50) ;
  21. if (val < LOWER_BOUND+5)
  22. {
  23. digitalWrite(RLED, LOW) ;
  24. digitalWrite(GLED, LOW) ;
  25. digitalWrite(BLED, HIGH) ;
  26. }
  27. else
  28. {
  29. color = (val-46)*1.5 ;
  30. analogWrite(RLED, color) ;
  31. analogWrite(GLED, 0) ;
  32. analogWrite(BLED,255-color ) ;
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement