Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Jung Min Yean
- * 04/02/19
- * Learning How to Use a Photoresistor with LEDs
- */
- const int LedPin1 = 9;
- const int LedPin2 = 10;
- const int LedPin3 = 11;
- const int PhotoPin = A0;
- const int PotPin = A1;
- int PotVal = 0;
- int PhotoVal = 0;
- void setup()
- {
- pinMode(LedPin1, OUTPUT);
- pinMode(LedPin2, OUTPUT);
- pinMode(LedPin3, OUTPUT);
- pinMode(PhotoPin, INPUT);
- Serial.begin(9600);
- }
- void loop()
- {
- // test potentiometer
- // PotVal = analogRead(PotPin);
- PhotoVal = analogRead(PhotoPin);
- Serial.println(PhotoVal);
- delay (200);
- // Serial.print(" ");
- int MapVal = map(PhotoVal,0,173,255,0);
- MapVal = constrain(MapVal, 0,255);
- Serial.println(MapVal);
- analogWrite(LedPin1, MapVal);
- analogWrite(LedPin2, MapVal);
- analogWrite(LedPin3, MapVal);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement