Advertisement
Guest User

Untitled

a guest
Mar 25th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. int ledPin=9; //Variable to store pin of LED
  2. int potentPin=A0; //Variable to store pin of photoresistor
  3. int potentValue=0; //Variable to store last known value of photoresistor
  4. int brightnessValue=0; //Variable to store LED brightness
  5.  
  6. void setup() {
  7. // put your setup code here, to run once:
  8. pinMode(ledPin, OUTPUT); //Setup LED pin for output
  9. }
  10.  
  11. void loop() {
  12. // put your main code here, to run repeatedly:
  13. potentValue=analogRead(potentPin); //Read the value of the photoresistor pin
  14. brightnessValue=map(potentValue,0,1023,0,255); //Map the photoresistor value to a brightness
  15. analogWrite(ledPin,brightnessValue); //Set the brightness of the ledPin
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement