/* * Coke Bottle Head * Photocell Values on LED * by John Douglas * */ #include #include //PhotoResistor Pin int PCPin0 = 0; //the analog pin the photoresistor is int PCPin1 = 1; //connected to int PCPin2 = 2; //the photoresistor is not calibrated to any units so //this is simply a raw sensor value (relative light) int LED1 = 7; int LED2 = 8; LiquidCrystal_I2C lcd(0x27,16,2); //Connect SDA (Rightmost, #4) to Analog 4, and SCL (#3) to Analog 5 void setup() { pinMode(LED1, OUTPUT); //sets the led pin to output pinMode(LED2, OUTPUT); //sets the led pin to output lcd.init(); // initialize the lcd lcd.backlight(); lcd.print("Coke Bottle Head"); lcd.setCursor(0, 1); lcd.print("by John Douglas"); delay(1000); } /* * loop() - this function will start after setup * finishes and then repeat */ void loop() { int lightLevel0 = analogRead(PCPin0); int lightLevel1 = analogRead(PCPin1); int lightLevel2 = analogRead(PCPin2); //Map input value (0-900) to 0-100 int mapLL0 = map(lightLevel0, 0, 1023, 0, 100); int mapLL1 = map(lightLevel1, 0, 1023, 0, 100); int mapLL2 = map(lightLevel2, 0, 1023, 0, 100); mapLL0 = constrain(mapLL0, 0, 100); mapLL1 = constrain(mapLL1, 0, 100); mapLL2 = constrain(mapLL2, 0, 100); //lcd.clear(); lcd.scrollDisplayLeft(); lcd.setCursor(0, 0); lcd.print("PC1:"); lcd.print(lightLevel0); lcd.print(" PC2:"); lcd.print(lightLevel1); lcd.print(" PC3:"); lcd.print(lightLevel2); lcd.setCursor(0, 1); lcd.print("MP1:"); lcd.print(mapLL0); lcd.print("MP2:"); lcd.print(mapLL1); lcd.print("MP3:"); lcd.print(mapLL2); delay(100); }