3494 |
kakl |
1 |
|
|
|
2 |
// A lamp controller |
|
|
3 |
|
|
|
4 |
#define LAG 400 // dellay in ms between switching |
|
|
5 |
|
|
|
6 |
int trafo = 6; // PD6 - trafo for a lamp |
|
|
7 |
int rele = 8; // PB0 - relay for switching between lamps |
|
|
8 |
char state; |
|
|
9 |
|
|
|
10 |
// the setup routine runs once when you press reset: |
|
|
11 |
void setup() |
|
|
12 |
{ |
|
|
13 |
// initialize the digital pin as an output and switch off |
|
|
14 |
digitalWrite(trafo, HIGH); |
|
|
15 |
digitalWrite(rele, HIGH); |
|
|
16 |
pinMode(trafo, OUTPUT); |
|
|
17 |
pinMode(rele, OUTPUT); |
|
|
18 |
state = 'o'; |
|
|
19 |
|
|
|
20 |
// initialize the serial port |
|
|
21 |
Serial.begin(9600); |
|
|
22 |
} |
|
|
23 |
|
|
|
24 |
// the loop routine runs over and over again forever: |
|
|
25 |
void loop() |
|
|
26 |
{ |
|
|
27 |
byte inByte; |
|
|
28 |
|
|
|
29 |
if (Serial.available() > 0) // wait for a char |
|
|
30 |
{ |
|
|
31 |
// get incoming byte: |
|
|
32 |
inByte = Serial.read(); |
|
|
33 |
|
|
|
34 |
switch (inByte) |
|
|
35 |
{ |
|
|
36 |
case 'a': // Argon lamp ON |
|
|
37 |
if (state != 'a') |
|
|
38 |
{ |
|
|
39 |
digitalWrite(trafo, HIGH); |
|
|
40 |
delay(LAG); |
|
|
41 |
digitalWrite(rele, LOW); |
|
|
42 |
delay(LAG); |
|
|
43 |
digitalWrite(trafo, LOW); |
|
|
44 |
delay(LAG); |
|
|
45 |
state = 'a'; |
|
|
46 |
} |
|
|
47 |
break; |
|
|
48 |
|
|
|
49 |
case 'x': // Xenon lamp ON |
|
|
50 |
if (state != 'x') |
|
|
51 |
{ |
|
|
52 |
digitalWrite(trafo, HIGH); |
|
|
53 |
delay(LAG); |
|
|
54 |
digitalWrite(rele, HIGH); |
|
|
55 |
delay(LAG); |
|
|
56 |
digitalWrite(trafo, LOW); |
|
|
57 |
delay(LAG); |
|
|
58 |
state = 'x'; |
|
|
59 |
} |
|
|
60 |
break; |
|
|
61 |
|
|
|
62 |
default: // OFF all lamps |
|
|
63 |
state = 'o'; |
|
|
64 |
digitalWrite(trafo, HIGH); |
|
|
65 |
delay(LAG); |
|
|
66 |
digitalWrite(rele, HIGH); |
|
|
67 |
break; |
|
|
68 |
} |
|
|
69 |
Serial.write(inByte); // echo char |
|
|
70 |
} |
|
|
71 |
} |