Arduino commences…

And so it begins. Not devastatingly exciting but you have to start somewhere. The sketch was originally for turning the LED on when the LDR picked up light and so I changed it to turn on the LED in low light. The ultimate aim is to run a sketch through to Processing and trigger an audio clip when a more direct light source (laser trip wire?) is broken.


// Example 02: Turn on LED when LDR low light

#define LED 13 // the pin for the LED
#define LDR 7 // the input pin where the
// LDR is connected
int val = 0; // val will be used to store the state
// of the input pin

void setup() {
pinMode(LED, OUTPUT); // tell Arduino LED is an output
pinMode(LDR, INPUT); // and LDR is an input
}

void loop(){
val = digitalRead(LDR); // read input value and store it

// check whether the input is HIGH (LDR covered)
if (val == HIGH) {
digitalWrite(LED, LOW); // turn LED ON
} else {
digitalWrite(LED, HIGH);
}
} // I THINK!!