2.7k
In this example we will connect an LDR to an Attiny85, once the value read drops below a certain value we will switch an LED on.
For this example we used the Arduino IDE to write our code. We’ll post a different version using Atmel Studio or equivalent soon.
Schematic
Code
int analogPin = 3; //pin 2 int LEDPin = 1; //pin 6 int val = 0; void setup() { pinMode(LEDPin, OUTPUT); digitalWrite(LEDPin,LOW); delay(2000); digitalWrite(LEDPin,HIGH); } void loop() { val = analogRead(analogPin); // read the input pin if(val < 200) { digitalWrite(LEDPin,HIGH); delay(200); } else { digitalWrite(LEDPin,LOW); } }Links