Advertisement
rosea4

code for ch. 4 in white book

Mar 26th, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. const int GLED=9 ;
  2. const int RLED= 11 ;
  3. const int BLED= 10 ;
  4. const int REDSENSOR= A0 ;
  5. const int GREENSENSOR = A1 ;
  6. const int BLUESENSOR = A2;
  7.  
  8. int REDValue = 0;
  9. int GREENValue = 0;
  10. int BLUEValue = 0;
  11. int redsensorValue = 0;
  12. int greensensorValue = 0;
  13. int bluesensorValue= 0;
  14.  
  15. void setup ()
  16. {
  17. Serial.begin(9600);
  18. pinMode(REDSENSOR, INPUT) ;
  19. pinMode(GREENSENSOR, INPUT) ;
  20. pinMode(BLUESENSOR, INPUT) ;
  21. pinMode(GLED, OUTPUT) ;
  22. pinMode(RLED, OUTPUT) ;
  23. pinMode(BLED, OUTPUT) ;
  24. }
  25.  
  26. void loop ()
  27. {
  28. redsensorValue = analogRead(REDSENSOR);
  29. delay (50) ;
  30. greensensorValue = analogRead(GREENSENSOR) ;
  31. delay (50) ;
  32. bluesensorValue = analogRead(BLUESENSOR) ;
  33. delay (50) ;
  34. Serial.print("Raw Sensor Values \t Red: ");
  35. Serial.print(redsensorValue);
  36. Serial.print("\t Green: ");
  37. Serial.print(greensensorValue);
  38. Serial.print("\t Blue: ");
  39. Serial.println(bluesensorValue);
  40. REDValue = map(redsensorValue,550, 900, 255, 0);
  41. REDValue = constrain(REDValue, 0, 255) ;
  42. GREENValue = map(greensensorValue,650,900, 255, 0);
  43. GREENValue = constrain(GREENValue, 0, 255);
  44. BLUEValue = map(bluesensorValue,400, 800, 255, 0);
  45. BLUEValue = constrain(BLUEValue, 0, 255) ;
  46.  
  47. Serial.print("Mapped Sensor Values \t Red: ");
  48. Serial.print(REDValue);
  49. Serial.print("\t Green: ");
  50. Serial.print(GREENValue);
  51. Serial.print("\t Blue: ");
  52. Serial.println(BLUEValue);
  53. delay(50) ;
  54. analogWrite(RLED, REDValue) ;
  55. analogWrite(GLED, GREENValue);
  56. analogWrite(BLED, BLUEValue);
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement