Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int ledpin = 5;
- const int photopin = A0;
- unsigned long timeValue = 0;
- int minVal = 120;
- int maxVal = 0;
- int photoValue;
- void setup()
- {
- pinMode (photopin, INPUT);
- pinMode (ledpin, OUTPUT);
- Serial.begin (9600);
- digitalWrite (ledpin, HIGH);
- timeValue = millis();
- while(millis()-timeValue<5000)
- {
- photoValue = analogRead (photopin);
- if (photoValue<minVal)
- {
- minVal = photoValue;
- }
- if (photoValue>maxVal)
- {
- maxVal = photoValue;
- }
- }
- digitalWrite (ledpin, LOW);
- }
- void loop()
- {
- photoValue = analogRead (photopin);
- photoValue = constrain(photoValue, 0, 120);//makes min and max values 40 and 120
- photoValue = map (photoValue, 0, 120, 255, 0);//maps 255-0 along 40-120
- Serial.println (photoValue);
- analogWrite (ledpin, photoValue);
- // put your main code here, to run repeatedly:
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement