Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); //0x27 is the I2C address and the rest are pin assignments
- int red = 0;
- int green = 0;
- int blue = 0;
- void setup()
- {
- pinMode(8, OUTPUT);
- pinMode(9, OUTPUT);
- pinMode(12, OUTPUT);
- pinMode(11, OUTPUT);
- pinMode(10, INPUT);
- //setting up output frequency scaling of color sensor to 100%
- digitalWrite(8, HIGH); //pin S0 is set to high
- digitalWrite(9, HIGH); //pin S1 is set to high
- lcd.begin(16,2); //initializing the LCD display, 16x2 is the LCD dimensions
- Serial.begin(9600);
- }
- void loop()
- {
- // Setting the pins for the red photodiodes
- digitalWrite(12, LOW);
- digitalWrite(11, LOW);
- // Reading the output frequency from pin 10
- red = pulseIn(10, LOW);
- delay(100);
- // Setting the pins for the blue photodiodes
- digitalWrite(11, HIGH);
- // Reading the output frequency from pin 10
- blue = pulseIn(10, LOW);
- delay(100);
- // Setting the pins for the green photodiodes
- digitalWrite(12, HIGH);
- // Reading the output frequency from pin 10
- green = pulseIn(10, LOW);
- delay(100);
- lcd.clear();//clears LCD display
- if (red < blue && red < green)
- {
- Serial.println(" Red");
- lcd.print("Red");
- }
- else if (blue < red && blue < green)
- {
- Serial.println(" Blue");
- lcd.print("Blue");
- }
- else if (green < red && green < blue)
- {
- Serial.println(" Green");
- lcd.print("Green");
- }
- delay(500);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement