Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int photoPin=A0;
- int photoValue=0;
- int lightVal=0;
- const int PinRed=9;
- const int PinGreen=10;
- const int PinBlue=11;
- const int pinButt=6;
- int newButt=0;
- int lastButt=0;
- int min = 1000;
- int max = -1000;
- unsigned long timeVal;
- void setup()
- {
- // put your setup code here, to run once:
- Serial.begin(9600);
- pinMode(photoPin, INPUT);
- pinMode (PinRed, OUTPUT);
- pinMode (PinBlue, OUTPUT);
- pinMode(PinGreen, OUTPUT);
- analogWrite(PinRed, 255);
- analogWrite(PinGreen, 0);
- analogWrite(PinBlue, 0);
- delay (500);
- analogWrite(PinRed, 0);
- analogWrite(PinGreen, 255);
- analogWrite(PinBlue, 0);
- delay(500);
- analogWrite(PinRed, 0);
- analogWrite(PinGreen, 0);
- analogWrite(PinBlue, 255);
- }
- void calibrate ()
- {
- min = 5000;
- max = -5000;
- analogWrite (PinRed, 0);
- analogWrite (PinBlue, 0);
- digitalWrite (PinGreen, LOW);
- delay(200);
- digitalWrite(PinRed, HIGH);
- delay (200);
- digitalWrite(PinRed, LOW);
- timeVal =millis();
- while (millis ()-timeVal<5000)
- {
- photoValue = analogRead(photoPin);
- if (photoValue > max)
- {
- max = photoValue;
- }
- else if (photoValue < min)
- {
- min = photoValue;
- }
- }
- Serial.println(min);
- Serial.println(max);
- digitalWrite (PinGreen, LOW);
- delay (200);
- digitalWrite (PinGreen, LOW);
- }
- boolean debounce (boolean last)
- {
- boolean current = digitalRead(pinButt);
- if (last != current)
- {
- delay(5);
- current = digitalRead(pinButt);
- }
- return current;
- }
- void loop()
- {
- // put your main code here, to run repeatedly:
- newButt = debounce (lastButt);
- if(newButt==HIGH && lastButt ==LOW)
- {
- calibrate();
- }
- lastButt=newButt;
- photoValue=analogRead (photoPin);
- lightVal=map (photoValue, min, max, 255, 0);
- lightVal=constrain (lightVal, 0, 255);
- analogWrite (PinRed, lightVal);
- analogWrite (PinGreen,0);
- analogWrite (PinBlue, lightVal);
- {
- if
- (photoValue > (min && photoValue)< (max-min/3));
- analogWrite (PinBlue, lightVal);
- analogWrite (PinRed, lightVal);
- analogWrite (PinGreen, 0);
- else if
- (photoValue > (min && photoValue) < (max-min/2));
- analogWrite (PinBlue, lightVal*.25);
- analogWrite (PinRed, lightVal * 71);
- analogWrite (PinGreen, lightVal * .12);
- else if
- (photoValue > (min && photoValue) < (max-min/1));
- analogWrite (PinBlue, lightVal*50);
- analogWrite (PinRed, 0);
- analogWrite (PinGreen, lightVal * 90);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement