Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- *Divya Inaganti
- *June 14, 2017
- *RGB and photoresistor activity
- */
- const int photoPin = A0;
- const int PinRed= 9;
- const int PinGreen=10;
- const int PinBlue= 11;
- int photoValue= 0;
- int lightVal= 0;
- const int pinButton = 4;
- void setup()
- {
- Serial.begin (9600);
- pinMode(photoPin, INPUT);
- pinMode (PinRed, OUTPUT);
- pinMode (PinGreen, OUTPUT);
- pinMode (PinBlue, OUTPUT);
- pinMode(pinButton, INPUT);
- analogWrite(PinRed, 255);
- analogWrite(PinGreen, 0);
- analogWrite(PinBlue,0);
- delay(200);
- analogWrite(PinRed, 0);
- analogWrite(PinGreen, 255);
- analogWrite(PinBlue,0);
- delay(200);
- analogWrite(PinRed, 0);
- analogWrite(PinGreen, 0);
- analogWrite(PinBlue,255);
- delay(200);
- analogWrite(PinRed, 0);
- analogWrite(PinGreen, 0);
- analogWrite(PinBlue,0);
- }
- void loop()
- {
- photoValue= analogRead (photoPin);
- lightVal= map(photoValue, 0, 730, 255, 0);
- lightVal= constrain(lightVal, 0, 255);
- Serial.print ("Photoresistor value = ");
- Serial.print(photoValue);
- Serial.print ("lightVal = ");
- Serial.println(lightVal);
- analogWrite(PinRed, lightVal);
- analogWrite(PinBlue, lightVal);
- analogWrite(PinGreen,0);
- delay(100);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement