Page 23 - S.Shafna (1B), 2207, Ass-1
P. 23

❖ Arduino codes




               //Colour Sensor  Dec 2019
               //

               const int Greenled  = 12;

               const int Redled  = 13;

               const int Blueled  = 11;

               int sensorpin  = A0;
               void setup(){

                //Set pins as outputs

                   pinMode(Greenled, OUTPUT);

                   pinMode(Redled, OUTPUT);

                   pinMode(Blueled, OUTPUT);

                  Serial.begin(9600);

               }
               void loop(){

                 digitalWrite(Greenled, HIGH);

                   for(int i = 0;i<=50;i++){

                       int lightlevel = analogRead(sensorpin);

                             lightlevel = map (lightlevel, 0,900,0,255);
                       lightlevel = constrain (lightlevel, 0, 255);

                        delay(1);

                         Serial.print("Green = "); Serial.println(lightlevel);

                 }

                 digitalWrite(Greenled, LOW);

                   delay (2000);

                   digitalWrite(Redled, HIGH);
   18   19   20   21   22   23   24   25   26   27   28