Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int photo_resist=A1;
- const int Button = 2;
- int PhotoVal;
- const int PinLed1 = 3;
- const int PinLed2 = 10;
- const int PinLed3 = 11;
- unsigned long timeCount;
- int MinVal = 1000;
- int MaxVal = 0;
- void setup() {
- // put your setup code here, to run once:
- Serial.begin(9600);
- pinMode (photo_resist, INPUT);
- pinMode (Button, INPUT);
- pinMode(PinLed1, OUTPUT);
- pinMode(PinLed2, OUTPUT);
- pinMode(PinLed3, OUTPUT);
- calibrate();
- }
- void calibrate()
- {
- digitalWrite(PinLed1,HIGH);
- delay(50);
- digitalWrite(PinLed1,LOW);
- timeCount = millis();
- while(millis()-timeCount <= 5000)
- {
- PhotoVal = analogRead(photo_resist);
- if ( PhotoVal < MinVal)
- {
- MinVal = PhotoVal;
- }
- if (PhotoVal > MaxVal)
- {
- MaxVal = PhotoVal;
- }
- }
- Serial.println("End of Calibration.");
- Serial.println("MAXVAL");
- Serial.println(MaxVal);
- digitalWrite(PinLed2,HIGH);
- delay(500);
- digitalWrite(PinLed2,LOW);
- Serial.println("MINVAL");
- Serial.println(MinVal);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- PhotoVal = analogRead(photo_resist);
- Serial.println(PhotoVal);
- PhotoVal = map(PhotoVal, 228,579,255,0);
- PhotoVal = constrain(PhotoVal, 0,255);
- analogWrite(PinLed1, PhotoVal);
- analogWrite(PinLed2, PhotoVal);
- analogWrite(PinLed3, PhotoVal);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement