Rev 3637 Rev 3651
Line 1... Line 1...
1 // Lamps controller 1 // Lamps controller
-   2 #define VERSION "$Revision: 3651 $"
-   3  
2   4  
3 #include <OneWire.h> 5 #include <OneWire.h>
-   6 #include <EEPROM.h>
-   7  
4   8  
5 #define LAG 400 // dellay in ms between lamp relay switching 9 #define LAG 400 // dellay in ms between lamp relay switching
6   10  
7 // Triacs 11 // Triacs
8 int t1 = 2; // PD2 - trafo for gas lamps 12 int t1 = 2; // PD2 - trafo for gas lamps
9 int t2 = 3; // PD3 - relay for switching between lamps 13 int t2 = 3; // PD3 - relay for switching between lamps
10 int t3 = 4; // PD4 - halogen lamp 14 int t3 = 4; // PD4 - halogen lamp
11 int t4 = 5; // PD5 - focuser 15 int t4 = 5; // PD5 - focuser
12 int t5 = 6; // PD6 16 int t5 = 6; // PD6 - COLORES
13 int t6 = 7; // PD7 17 int t6 = 7; // PD7
14 int t7 = 8; // PB0 18 int t7 = 8; // PB0
15 int t8 = 9; // PB1 19 int t8 = 9; // PB1
16   20  
17 // DS18S20 Temperature chip 21 // DS18S20 Temperature chip
Line 21... Line 25...
21 int n; // Counter 25 int n; // Counter
22 char state; // State of Gas Lamps 26 char state; // State of Gas Lamps
23   27  
24 char deleni16[16]={'0','1','1','2','3','3','4','4','5','6','6','7','7','8','9','9'}; 28 char deleni16[16]={'0','1','1','2','3','3','4','4','5','6','6','7','7','8','9','9'};
25   29  
-   30 void info () // Print an information string
-   31 {
-   32 Serial.print("Lamps Controller ");
-   33 Serial.println(VERSION);
-   34 Serial.println("Commands: abcdefghABCDEFGHiS");
-   35 }
-   36  
26 int temperature () 37 int temperature () // Read temperature from Dallas
27 { 38 {
28 int i, temp; 39 int i, temp;
29 byte data[12]; 40 byte data[12];
30 41
31 if (OneWire::crc8 (addr, 7) != addr[7]) 42 if (OneWire::crc8 (addr, 7) != addr[7])
Line 53... Line 64...
53 // temp = temp >> 4; //divide by 16 to get pure celcius readout 64 // temp = temp >> 4; //divide by 16 to get pure celcius readout
54 65
55 return temp; 66 return temp;
56 } 67 }
57   68  
-   69 void pstatus() // Print status to serial line
-   70 {
-   71 int t; // Temperature
-   72  
-   73 t=temperature(); // Read temperature
-   74 Serial.print (t >> 4);
-   75 Serial.print (".");
-   76 Serial.print (deleni16[t & 0xf]);
-   77 Serial.print (' ');
-   78 for (n=1;n<=8;n++)
-   79 {
-   80 if(digitalRead(n+1))
-   81 {
-   82 Serial.print('t');
-   83 }
-   84 else
-   85 {
-   86 Serial.print('T');
-   87 }
-   88 Serial.print(n, DEC);
-   89 Serial.print(' ');
-   90 }
-   91 Serial.println();
-   92 }
-   93  
-   94  
58 // the setup routine runs once when you press reset: 95 // the setup routine runs once when you press reset:
59 void setup() 96 void setup()
60 { 97 {
61 // initialize the digital pin as an output and switch off 98 // initialize the digital pin as an output and switch off
62 digitalWrite(t1, HIGH); 99 digitalWrite(t1, HIGH);
Line 90... Line 127...
90 ds.reset_search(); 127 ds.reset_search();
91 delay(250); 128 delay(250);
92 return; 129 return;
93 } 130 }
94 131
-   132 for (n=1;n<=8;n++)
-   133 {
-   134 digitalWrite(n+1,EEPROM.read(n)); // Read saved states from EEPROM
-   135 }
-   136  
95 Serial.println("Hmmm...."); 137 Serial.println("Hmmm....");
-   138 info();
-   139 pstatus();
96 } 140 }
97   141  
98 // the loop routine runs over and over again forever: 142 // the loop routine runs over and over again forever:
99 void loop() 143 void loop()
100 { 144 {
101 byte inByte; // Character from serial line 145 byte inByte; // Character from serial line
102 int t; // Temperature -  
103 146
104 if (Serial.available() > 0) // wait for a char 147 if (Serial.available() > 0) // wait for a char
105 { 148 {
106 // get incoming byte: 149 // get incoming byte:
107 inByte = Serial.read(); 150 inByte = Serial.read();
Line 144... Line 187...
144 digitalWrite(t1, HIGH); 187 digitalWrite(t1, HIGH);
145 delay(LAG); 188 delay(LAG);
146 digitalWrite(t2, HIGH); 189 digitalWrite(t2, HIGH);
147 state = 'b'; 190 state = 'b';
148 break; 191 break;
-   192  
-   193 case 'i': // Print Info
-   194 info();
-   195 break;
-   196  
-   197 case 'S': // Save states to EEPROM
-   198 for (n=1;n<=8;n++)
-   199 {
-   200 EEPROM.write(n,digitalRead(n+1));
-   201 }
-   202 break;
149 } 203 }
150 204
151 if ( (inByte >= 'c') and (inByte <= 'h')) // Switch OFF other triacs 205 if ( (inByte >= 'c') and (inByte <= 'h')) // Switch OFF other triacs
152 { 206 {
153 digitalWrite(inByte-'a'+2,HIGH); 207 digitalWrite(inByte-'a'+2,HIGH);
Line 156... Line 210...
156 if ( (inByte >= 'C') and (inByte <= 'H')) // Switch ON other triacs 210 if ( (inByte >= 'C') and (inByte <= 'H')) // Switch ON other triacs
157 { 211 {
158 digitalWrite(inByte-'A'+2, LOW); 212 digitalWrite(inByte-'A'+2, LOW);
159 } 213 }
160 214
161 // Send status to serial line 215 pstatus(); // Print states
162 t=temperature(); // Read temperature -  
163 Serial.print (t >> 4); -  
164 Serial.print ("."); -  
165 Serial.print (deleni16[t & 0xf]); -  
166 Serial.print (' '); -  
167 for (n=1;n<=8;n++) -  
168 { -  
169 if(digitalRead(n+1)) -  
170 { -  
171 Serial.print('t'); -  
172 } -  
173 else -  
174 { -  
175 Serial.print('T'); -  
176 } -  
177 Serial.print(n, DEC); -  
178 Serial.print(' '); -  
179 } -  
180 Serial.println(); -  
181 -  
182 } 216 }
183 } 217 }