SHARE
TWEET

Substituting a Photoresistor for a Potentiometer

jmyean Apr 2nd, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  *  Jung Min Yean
  3.  *  03/28/19
  4.  *  Learning How to Use a Photoresistor
  5.  */
  6.  
  7.  const int LedPin1 = 9;
  8.  const int LedPin2 = 10;
  9.  const int LedPin3 = 11;
  10.  const int PhotoPin = A0;
  11.  const int PotPin = A1;
  12.  int PotVal = 0;
  13.  int PhotoVal = 0;
  14.  
  15. void setup()
  16. {
  17.  pinMode(LedPin1, OUTPUT);
  18.  pinMode(LedPin2, OUTPUT);
  19.  pinMode(LedPin3, OUTPUT);
  20.  pinMode(PotPin, INPUT);
  21.  pinMode(PhotoPin, INPUT);
  22.  Serial.begin(9600);
  23. }
  24.  
  25. void loop()
  26. {
  27.   // test potentiometer
  28.   PotVal = analogRead(PotPin);
  29.   PhotoVal = analogRead(PhotoPin);
  30.   Serial.println(PhotoVal);
  31.   // Serial.print("      ");
  32.   // int MapValue = map(PotVal,0,1023,255,0);
  33.   // Serial.println(MapValue);
  34.   // analogWrite(LedPin1, PotVal);
  35.   // analogWrite(LedPin2, PotVal);
  36.   // analogWrite(LedPin3, PotVal);
  37. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top