Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Manvi Mittal
- * Photoresistor Project
- */
- const int pinPhoto = A0;
- const int pinLedRed = 9; // red
- const int pinLedGreen = 10; // green
- const int pinLedBlue = 11; // blue
- int lightLevel = 0;
- int brightness = 0;
- void setup() {
- // put your setup code here, to run once:
- pinMode (pinPhoto, INPUT);
- pinMode (pinLedRed, OUTPUT);
- pinMode (pinLedGreen, OUTPUT);
- pinMode (pinLedBlue, OUTPUT);
- Serial.begin (9600);
- analogWrite (pinLedRed, 100);
- delay (500);
- analogWrite (pinLedRed, 0);
- delay (500);
- analogWrite (pinLedGreen, 100);
- delay (500);
- analogWrite (pinLedGreen, 0);
- delay (500);
- analogWrite (pinLedBlue, 100);
- delay (500);
- analogWrite (pinLedBlue, 0);
- delay (500);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- lightLevel = analogRead (pinPhoto);
- brightness = map(lightLevel, 1, 150, 255, 0);
- //NEW FUNCTION: map -- map (variable, minimum of variable, maximum of variable, corresponding value to minimum of variable, corresponding valuable to maximum of variable)
- brightness = constrain (brightness, 0, 255);
- // NEW FUNCTION: constrain -- constrain (variable, min, max) -- so that there are no negative numbers
- analogWrite (pinLedRed, brightness/2);
- analogWrite (pinLedBlue, brightness*3);
- analogWrite (pinLedGreen, brightness/20);
- Serial.print (" Light Level = ");
- Serial.print (lightLevel);
- Serial.print (" Brightness = ");
- Serial.println (brightness);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement