Inicio » Example 4

Example 4

This program makes an LED, connected to pin number 12, turn on when there is a low level of light and turn off when the level of light is high:

int measure=0;

void setup(){

Serial.begin(9600);
pinMode(A2, INPUT);
pinMode(12,OUTPUT);

}

void loop(){

measure=analogRead(A2);
Serial.println(measure);
if(measure>350)digitalWrite(12,LOW);
if(measure<350)digitalWrite(12,HIGH);

}