Rev 3494 Rev 3636
Line 1... Line -...
1 -  
2 // A lamp controller 1 // Lamps controller
3   2  
4 #define LAG 400 // dellay in ms between switching 3 #define LAG 400 // dellay in ms between lamp relay switching
-   4  
-   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;
5   15  
6 int trafo = 6; // PD6 - trafo for a lamp -  
7 int rele = 8; // PB0 - relay for switching between lamps -  
8 char state; 16 char state;
9   17  
10 // the setup routine runs once when you press reset: 18 // the setup routine runs once when you press reset:
11 void setup() 19 void setup()
12 { 20 {
13 // initialize the digital pin as an output and switch off 21 // initialize the digital pin as an output and switch off
-   22 digitalWrite(t1, HIGH);
14 digitalWrite(trafo, 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);
15 digitalWrite(rele, 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);
16 pinMode(trafo, OUTPUT); 36 pinMode(t7, OUTPUT);
17 pinMode(rele, OUTPUT); 37 pinMode(t8, OUTPUT);
18 state = 'o'; 38 state = 'a';
19 39
20 // initialize the serial port 40 // initialize the serial port
21 Serial.begin(9600); 41 Serial.begin(9600);
22 } 42 }
23   43  
Line 28... Line 48...
28 48
29 if (Serial.available() > 0) // wait for a char 49 if (Serial.available() > 0) // wait for a char
30 { 50 {
31 // get incoming byte: 51 // get incoming byte:
32 inByte = Serial.read(); 52 inByte = Serial.read();
33 53
34 switch (inByte) 54 switch (inByte)
35 { 55 {
-   56
36 case 'a': // Argon lamp ON 57 case 'A': // Gas Lamp 1 ON
37 if (state != 'a') 58 if (state != 'A')
38 { 59 {
39 digitalWrite(trafo, HIGH); 60 digitalWrite(t1, HIGH);
40 delay(LAG); 61 delay(LAG);
41 digitalWrite(rele, LOW); 62 digitalWrite(t2, LOW);
42 delay(LAG); 63 delay(LAG);
43 digitalWrite(trafo, LOW); 64 digitalWrite(t1, LOW);
44 delay(LAG); 65 delay(LAG);
45 state = 'a'; 66 state = 'A';
46 } 67 }
47 break; 68 break;
48   69  
49 case 'x': // Xenon lamp ON 70 case 'B': // Gas Lamp 2 ON
50 if (state != 'x') 71 if (state != 'B')
51 { 72 {
52 digitalWrite(trafo, HIGH); 73 digitalWrite(t1, HIGH);
53 delay(LAG); 74 delay(LAG);
54 digitalWrite(rele, HIGH); 75 digitalWrite(t2, HIGH);
55 delay(LAG); 76 delay(LAG);
56 digitalWrite(trafo, LOW); 77 digitalWrite(t1, LOW);
57 delay(LAG); 78 delay(LAG);
58 state = 'x'; 79 state = 'B';
59 } 80 }
60 break; 81 break;
-   82  
61 83 case 'a': // Gas Lamp 1 OFF
62 default: // OFF all lamps 84 digitalWrite(t1, HIGH);
63 state = 'o'; 85 delay(LAG);
64 digitalWrite(trafo, HIGH); 86 digitalWrite(t2, HIGH);
65 delay(LAG); 87 delay(LAG);
66 digitalWrite(rele, HIGH); 88 state = 'a';
67 break; 89 break;
-   90  
-   91 case 'b': // Gas Lamp 2 OFF
-   92 digitalWrite(t1, HIGH);
-   93 delay(LAG);
-   94 digitalWrite(t2, HIGH);
-   95 delay(LAG);
68 } 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 {
69 Serial.write(inByte); // echo char 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
70 } 121 }
71 } 122 }