Advertisement
Guest User

Untitled

a guest
Jun 24th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. #include <Wire.h>
  2. #include <LiquidCrystal_I2C.h>
  3.  
  4. LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); //0x27 is the I2C address and the rest are pin assignments
  5.  
  6. int red = 0;
  7. int green = 0;
  8. int blue = 0;
  9.  
  10. void setup()
  11. {
  12. pinMode(8, OUTPUT);
  13. pinMode(9, OUTPUT);
  14. pinMode(12, OUTPUT);
  15. pinMode(11, OUTPUT);
  16. pinMode(10, INPUT);
  17.  
  18. //setting up output frequency scaling of color sensor to 100%
  19. digitalWrite(8, HIGH); //pin S0 is set to high
  20. digitalWrite(9, HIGH); //pin S1 is set to high
  21.  
  22.  
  23. lcd.begin(16,2); //initializing the LCD display, 16x2 is the LCD dimensions
  24.  
  25. Serial.begin(9600);
  26. }
  27.  
  28. void loop()
  29. {
  30. // Setting the pins for the red photodiodes
  31. digitalWrite(12, LOW);
  32. digitalWrite(11, LOW);
  33. // Reading the output frequency from pin 10
  34. red = pulseIn(10, LOW);
  35. delay(100);
  36.  
  37. // Setting the pins for the blue photodiodes
  38. digitalWrite(11, HIGH);
  39. // Reading the output frequency from pin 10
  40. blue = pulseIn(10, LOW);
  41. delay(100);
  42.  
  43. // Setting the pins for the green photodiodes
  44. digitalWrite(12, HIGH);
  45. // Reading the output frequency from pin 10
  46. green = pulseIn(10, LOW);
  47. delay(100);
  48.  
  49. lcd.clear();//clears LCD display
  50.  
  51. if (red < blue && red < green)
  52. {
  53. Serial.println(" Red");
  54. lcd.print("Red");
  55. }
  56.  
  57. else if (blue < red && blue < green)
  58. {
  59. Serial.println(" Blue");
  60. lcd.print("Blue");
  61. }
  62.  
  63. else if (green < red && green < blue)
  64. {
  65. Serial.println(" Green");
  66. lcd.print("Green");
  67. }
  68.  
  69. delay(500);
  70.  
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement