Rev Author Line No. Line
4100 kakl 1 // Gas Discharge Lamps controller
2 #define VERSION "$Revision: 3654 $"
3  
4  
5 // Triacs
6 int t1 = 2; // PD2 - lamp 1
7 int t2 = 3; // PD3 - lamp 2
8 int t3 = 4; // PD4 -
9 int t4 = 5; // PD5 -
10 int t5 = 6; // PD6 -
11 int t6 = 7; // PD7
12 int t7 = 8; // PB0
13 int t8 = 9; // PB1
14  
15 int n; // Counter
16 char state; // State of Gas Lamps
17  
18 void info () // Print an information string
19 {
20 Serial.print("Gas Discharge Lamps Controller ");
21 Serial.println(VERSION);
22 Serial.println("Commands: abcdefghABCDEFGHitRS");
23 Serial.println("a = OFF lamp 1 / A = ON lamp 1");
24 Serial.println("i = info");
25 Serial.println("t = telemetry");
26 Serial.println("R = reset");
27 }
28  
29  
30 void pstatus() // Print status to serial line
31 {
32 for (n=1;n<=8;n++)
33 {
34 if(digitalRead(n+1))
35 {
36 Serial.print((char)('A'+n-1));
37 }
38 else
39 {
40 Serial.print((char)('a'+n-1));
41 }
42 }
43 Serial.println();
44 }
45  
46  
47 // the setup routine runs once when you press reset:
48 void setup()
49 {
50 // initialize the digital pin as an output and switch off
51 digitalWrite(t1, LOW);
52 digitalWrite(t2, LOW);
53 digitalWrite(t3, LOW);
54 digitalWrite(t4, LOW);
55 digitalWrite(t5, LOW);
56 digitalWrite(t6, LOW);
57 digitalWrite(t7, LOW);
58 digitalWrite(t8, LOW);
59 pinMode(t1, OUTPUT);
60 pinMode(t2, OUTPUT);
61 pinMode(t3, OUTPUT);
62 pinMode(t4, OUTPUT);
63 pinMode(t5, OUTPUT);
64 pinMode(t6, OUTPUT);
65 pinMode(t7, OUTPUT);
66 pinMode(t8, OUTPUT);
67 state = 'a';
68  
69 // initialize the serial port
70 Serial.begin(9600);
71 Serial.println();
72 Serial.println("Cvak.");
73  
74 Serial.println("Hmmm....");
75 info();
76 }
77  
78 // the loop routine runs over and over again forever:
79 void loop()
80 {
81 byte inByte; // Character from serial line
82  
83 if (Serial.available() > 0) // wait for a char
84 {
85 // get incoming byte:
86 inByte = Serial.read();
87  
88 switch (inByte)
89 {
90 case 'i': // Print Info
91 info();
92 break;
93  
94 case 'R': // Reset
95 asm volatile (" jmp 0");
96 break;
97  
98 }
99  
100 if ( (inByte >= 'a') and (inByte <= 'h')) // Switch OFF other triacs
101 {
102 digitalWrite(inByte-'a'+2,LOW);
103 }
104  
105 if ( (inByte >= 'A') and (inByte <= 'H')) // Switch ON other triacs
106 {
107 digitalWrite(inByte-'A'+2, HIGH);
108 }
109  
110 pstatus(); // Print states
111 }
112 }