forked from tobyrobb/Sensor_night_light
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSensor_PCB_Attiny85.ino
66 lines (47 loc) · 1.77 KB
/
Sensor_PCB_Attiny85.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// test of the attiny for the sensor widget.
#include <avr/wdt.h> // include the watchdog timer library
#define ldrPin A1 // LDR light sensor
#define irPin 1 // IR movement sensor pin
#define timerPin A2 // Pin the timer potentiometer is connected to
#define brightnessPin A3 // Pin the timer potentiometer is connected to
#define ledPin 0 // Output for LED
void setup(){
wdt_enable(WDTO_8S); // begin watchdog timer
pinMode(ledPin, OUTPUT); //out put for LED
pinMode(irPin, INPUT); //input sensor
pinMode(ldrPin, INPUT); // input for LDR
pinMode(timerPin, INPUT); // input for timer pot
pinMode(brightnessPin, INPUT); //input for brightness
wdt_reset(); //make sure we reset watchdog timer to prevent endless resetting
//lets flash the led
for(int i = 0; i <=255;i++){
analogWrite(ledPin,i);
delay(1);
}
for(int i = 255; i >=0;i--){
analogWrite(ledPin,i);
delay(1);
}
wdt_reset(); //make sure we reset watchdog timer to prevent endless resetting
}
void loop(){
wdt_reset(); //make sure we reset watchdog timer to prevent endless resetting
while(analogRead(ldrPin)<255){
if(digitalRead(irPin)){
analogWrite(ledPin,(analogRead(brightnessPin)/4));
int timer = analogRead(timerPin);
timer = timer * 100;
for(int i = 0; i <=timer; i++){
wdt_reset(); //make sure we reset watchdog timer to prevent endless resetting
delay(1);
}
}
else {
analogWrite(ledPin,0);
wdt_reset(); //make sure we reset watchdog timer to prevent endless resetting
}
analogWrite(ledPin,0);
wdt_reset(); //make sure we reset watchdog timer to prevent endless resetting
}
wdt_reset(); //make sure we reset watchdog timer to prevent endless resetting
}