5 codes for my light sockets:
7 1000100110110000000000010
8 1011001001011111000000010
13 int int_0 = 300; // ms
14 int int_1 = 900; // ms
15 int wait = 2000; // ms
16 int repeat = 5; // times
19 pinMode(LED_PIN, OUTPUT);
20 pinMode(TX_PIN, OUTPUT);
23 Serial.println("1 or 2 to turn light sockets");
24 Serial.println("q/a - 0 inteval +/- 100 ms");
25 Serial.println("w/s - 1 inteval +/- 100 ms");
26 Serial.println("e/d - wait +/- 100 ms");
27 Serial.println("r/f - repeat +/- 1");
31 void send(char *code) {
32 Serial.print("send ");
35 // we have to send same signal at least two times
36 for(int r = 0; r < repeat; r++ ) {
38 digitalWrite(LED_PIN, HIGH);
40 for(int i = 0; i < strlen(code); i++) {
43 if (code[i] == '1' ) {
47 digitalWrite(TX_PIN, HIGH);
48 delayMicroseconds(i1);
49 digitalWrite(TX_PIN, LOW);
50 delayMicroseconds(i2);
53 delayMicroseconds(wait); // guess
56 digitalWrite(LED_PIN, LOW);
60 if(Serial.available()) {
61 int in = Serial.read();
63 send("1000100110110000000000010");
64 } else if (in == '2') {
65 send("1011001001011111000000010");
67 } else if (in == 'q') {
69 Serial.print("inteval 0 = ");
70 Serial.println(int_0);
71 } else if (in == 'a') {
73 Serial.print("inteval 0 = ");
74 Serial.println(int_0);
76 } else if (in == 'w') {
78 Serial.print("inteval 1 = ");
79 Serial.println(int_1);
80 } else if (in == 's') {
82 Serial.print("inteval 1 = ");
83 Serial.println(int_1);
85 } else if (in == 'e') {
87 Serial.print("wait = ");
89 } else if (in == 'd') {
91 Serial.print("wait = ");
94 } else if (in == 'r') {
96 Serial.print("repeat = ");
97 Serial.println(repeat);
98 } else if (in == 'f') {
100 Serial.print("repeat = ");
101 Serial.println(repeat);
104 Serial.print("ignored ");