/
Strobe_light_program.ino
50 lines (47 loc) · 1 KB
/
Strobe_light_program.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
const int light1pin = 12;
const int laser = 8;
const int potpin = A1;
const int auxpin = A0;
int fspeed, scaledspeed, aux, auxscaled; // analogRead values go from 0 to 1023, analogWrite values from 0 to 255
int ptr=0;
#define AVG_VALS 1
#define CUTOFF 20
int vals[AVG_VALS];
int i;
int avg;
void setup () {
//Serial.begin(9600);
}
void loop () {
fspeed = analogRead(potpin);
scaledspeed = fspeed/2;
aux = analogRead(auxpin);
auxscaled = aux/5;
vals[ptr] = aux;
ptr++;
ptr %= AVG_VALS;
avg=0;
for(i=0; i<AVG_VALS; i++){
avg+= vals[i];
}
avg/=AVG_VALS;
//Serial.println(avg);
if(avg>CUTOFF) {
digitalWrite(laser, HIGH);
//Serial.println("laser is on");
}
else if(avg<=CUTOFF) {
digitalWrite(laser, LOW);
//Serial.print("laser is off");
}
//delay(20);
/*
digitalWrite(light1pin, HIGH);
digitalWrite(light2pin, HIGH);
delay(scaledspeed);
digitalWrite(light1pin, LOW);
digitalWrite(light2pin, LOW);
Serial.println(brightness);
delay(scaledspeed);
*/
}