Rev Author Line No. Line
3636 kakl 1 // Lamps controller
3494 kakl 2  
3636 kakl 3 #define LAG 400 // dellay in ms between lamp relay switching
3494 kakl 4  
3636 kakl 5 int t1 = 2; // PD2 - trafo for gas lamps
6 int t2 = 3; // PD3 - relay for switching between lamps
7 int t3 = 4; // PD4 - halogen lamp
8 int t4 = 5; // PD5 - focuser
9 int t5 = 6; // PD6
10 int t6 = 7; // PD7
11 int t7 = 8; // PB0
12 int t8 = 9; // PB1
13  
14 int n;
15  
3494 kakl 16 char state;
17  
18 // the setup routine runs once when you press reset:
19 void setup()
20 {
21 // initialize the digital pin as an output and switch off
3636 kakl 22 digitalWrite(t1, HIGH);
23 digitalWrite(t2, HIGH);
24 digitalWrite(t3, HIGH);
25 digitalWrite(t4, HIGH);
26 digitalWrite(t5, HIGH);
27 digitalWrite(t6, HIGH);
28 digitalWrite(t7, HIGH);
29 digitalWrite(t8, HIGH);
30 pinMode(t1, OUTPUT);
31 pinMode(t2, OUTPUT);
32 pinMode(t3, OUTPUT);
33 pinMode(t4, OUTPUT);
34 pinMode(t5, OUTPUT);
35 pinMode(t6, OUTPUT);
36 pinMode(t7, OUTPUT);
37 pinMode(t8, OUTPUT);
38 state = 'a';
3494 kakl 39  
40 // initialize the serial port
41 Serial.begin(9600);
42 }
43  
44 // the loop routine runs over and over again forever:
45 void loop()
46 {
47 byte inByte;
48  
49 if (Serial.available() > 0) // wait for a char
50 {
51 // get incoming byte:
52 inByte = Serial.read();
3636 kakl 53  
3494 kakl 54 switch (inByte)
55 {
3636 kakl 56  
57 case 'A': // Gas Lamp 1 ON
58 if (state != 'A')
3494 kakl 59 {
3636 kakl 60 digitalWrite(t1, HIGH);
3494 kakl 61 delay(LAG);
3636 kakl 62 digitalWrite(t2, LOW);
3494 kakl 63 delay(LAG);
3636 kakl 64 digitalWrite(t1, LOW);
3494 kakl 65 delay(LAG);
3636 kakl 66 state = 'A';
3494 kakl 67 }
68 break;
69  
3636 kakl 70 case 'B': // Gas Lamp 2 ON
71 if (state != 'B')
3494 kakl 72 {
3636 kakl 73 digitalWrite(t1, HIGH);
3494 kakl 74 delay(LAG);
3636 kakl 75 digitalWrite(t2, HIGH);
3494 kakl 76 delay(LAG);
3636 kakl 77 digitalWrite(t1, LOW);
3494 kakl 78 delay(LAG);
3636 kakl 79 state = 'B';
3494 kakl 80 }
81 break;
3636 kakl 82  
83 case 'a': // Gas Lamp 1 OFF
84 digitalWrite(t1, HIGH);
3494 kakl 85 delay(LAG);
3636 kakl 86 digitalWrite(t2, HIGH);
87 delay(LAG);
88 state = 'a';
3494 kakl 89 break;
3636 kakl 90  
91 case 'b': // Gas Lamp 2 OFF
92 digitalWrite(t1, HIGH);
93 delay(LAG);
94 digitalWrite(t2, HIGH);
95 delay(LAG);
96 state = 'b';
97 break;
98 }
99  
100 if ( (inByte >= 'c') and (inByte <= 'h')) // Switch OFF other triacs
101 {
102 digitalWrite(inByte-'a'+2,HIGH);
103 }
104  
105 if ( (inByte >= 'C') and (inByte <= 'H')) // Switch ON other triacs
106 {
107 digitalWrite(inByte-'A'+2, LOW);
108 }
109  
110  
111 for (n=1;n<=8;n++) // Send status to serial line
112 {
113 Serial.print('t');
114 Serial.print(n, DEC);
115 Serial.print('=');
116 Serial.print((~digitalRead(n+1))&1, DEC);
117 Serial.print(' ');
118 }
119 Serial.println();
120  
3494 kakl 121 }
3636 kakl 122 }