FrontPage

٤Ƴ٤Ĥ
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
-
|
|
!
 
-
|
|
!
 
 
-
!
-
!
 
 
 
-
|
|
!
-
|
|
|
|
!
 
-
|
|
!
-
-
-
|
|
!
|
-
!
!
 
-
|
|
!
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
!
!
 
-
|
|
!
-
-
-
|
|
!
|
-
!
|
|
|
-
!
|
|
|
|
!
 
-
|
|
!
-
-
!
|
|
|
-
|
-
|
|
|
|
-
|
|
|
|
|
|
!
|
!
|
!
 
-
|
|
!
-
-
!
|
|
|
|
-
-
|
|
|
!
|
-
!
|
-
!
|
|
|
|
-
!
|
-
-
|
-
-
|
|
|
!
|
-
!
|
|
!
!
 
-
|
-
|
!
|
!
 
-
|
|
|
|
!
 
-
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
// Include the IRremote library header
//
#include <IRremote.h>
 
//------------------------------------------------------------------------------
// Tell IRremote which Arduino pin is connected to the IR Receiver (TSOP4838)
//
int recvPin = 11;
IRrecv irrecv(recvPin);
 
//send
IRsend irsend;
// digital pin 2 has a pushbutton attached to it. Give it a name:
int pushButton1 = 2;
int pushButton2 = 4;
 
 
//+=============================================================================
// Configure the Arduino
//
void  setup ( )
{
  Serial.begin(115200);   // Status message will be sent to PC at 9600 baud
  irrecv.enableIRIn();  // Start the receiver
  pinMode(pushButton1, INPUT);
  pinMode(pushButton2, INPUT);
}
 
//+=============================================================================
// Display IR code
//
void  ircode (decode_results *results)
{
  // Panasonic has an Address
  if (results->decode_type == PANASONIC) {
    Serial.print(results->address, HEX);
    Serial.print(":");
  }
 
  // Print Code
  Serial.print(results->value, HEX);
}
 
//+=============================================================================
// Display encoding type
//
void  encoding (decode_results *results)
{
  switch (results->decode_type) {
    default:
    case UNKNOWN:      Serial.print("UNKNOWN");       break ;
    case NEC:          Serial.print("NEC");           break ;
    case SONY:         Serial.print("SONY");          break ;
    case RC5:          Serial.print("RC5");           break ;
    case RC6:          Serial.print("RC6");           break ;
    case DISH:         Serial.print("DISH");          break ;
    case SHARP:        Serial.print("SHARP");         break ;
    case JVC:          Serial.print("JVC");           break ;
    case SANYO:        Serial.print("SANYO");         break ;
    case MITSUBISHI:   Serial.print("MITSUBISHI");    break ;
    case SAMSUNG:      Serial.print("SAMSUNG");       break ;
    case LG:           Serial.print("LG");            break ;
    case WHYNTER:      Serial.print("WHYNTER");       break ;
    case AIWA_RC_T501: Serial.print("AIWA_RC_T501");  break ;
    case PANASONIC:    Serial.print("PANASONIC");     break ;
    case DENON:        Serial.print("Denon");         break ;
  }
}
 
//+=============================================================================
// Dump out the decode_results structure.
//
void  dumpInfo (decode_results *results)
{
  // Check if the buffer overflowed
  if (results->overflow) {
    Serial.println("IR code too long. Edit IRremoteInt.h and increase RAWBUF");
    return;
  }
 
  // Show Encoding standard
  Serial.print("Encoding  : ");
  encoding(results);
  Serial.println("");
 
  // Show Code & length
  Serial.print("Code      : ");
  ircode(results);
  Serial.print(" (");
  Serial.print(results->bits, DEC);
  Serial.println(" bits)");
}
 
//+=============================================================================
// Dump out the decode_results structure.
//
void  dumpRaw (decode_results *results)
{
  // Print Raw data
  Serial.print("Timing[");
  Serial.print(results->rawlen-1, DEC);
  Serial.println("]: ");
 
  for (int i = 1;  i < results->rawlen;  i++) {
    unsigned long  x = results->rawbuf[i] * USECPERTICK;
    if (!(i & 1)) {  // even
      Serial.print("-");
      if (x < 1000)  Serial.print(" ") ;
      if (x < 100)   Serial.print(" ") ;
      Serial.print(x, DEC);
    } else {  // odd
      Serial.print("     ");
      Serial.print("+");
      if (x < 1000)  Serial.print(" ") ;
      if (x < 100)   Serial.print(" ") ;
      Serial.print(x, DEC);
      if (i < results->rawlen-1) Serial.print(", "); //',' not needed for last one
    }
    if (!(i % 8))  Serial.println("");
  }
  Serial.println("");                    // Newline
}
 
//+=============================================================================
// Dump out the decode_results structure.
//
void  dumpCode (decode_results *results)
{
  // Start declaration
  Serial.print("unsigned int  ");          // variable type
  Serial.print("rawData[");                // array name
  Serial.print(results->rawlen - 1, DEC);  // array size
  Serial.print("] = {");                   // Start declaration
 
  // Dump data
  for (int i = 1;  i < results->rawlen;  i++) {
    Serial.print(results->rawbuf[i] * USECPERTICK, DEC);
    if ( i < results->rawlen-1 ) Serial.print(","); // ',' not needed on last one
    if (!(i & 1))  Serial.print(" ");
  }
 
  // End declaration
  Serial.print("};");  // 
 
  // Comment
  Serial.print("  // ");
  encoding(results);
  Serial.print(" ");
  ircode(results);
 
  // Newline
  Serial.println("");
 
  // Now dump "known" codes
  if (results->decode_type != UNKNOWN) {
 
    // Some protocols have an address
    if (results->decode_type == PANASONIC) {
      Serial.print("unsigned int  addr = 0x");
      Serial.print(results->address, HEX);
      Serial.println(";");
    }
 
    // All protocols have data
    Serial.print("unsigned int  data = 0x");
    Serial.print(results->value, HEX);
    Serial.println(";");
  }
}
 
String skipSpace(String in){
  String r="";
  while(in.indexOf(" ")==0) {
    in=in.substring(1);
  }
  return in;
}
 
boolean rKeyword(String in, String key, String rest[]){
   if(in.indexOf(key)!=0) return false;
   in=in.substring(key.length());
   rest[0]=in;
   return true;
}
 
boolean rStrConst(String in, String strc[], String rest[]){
  String r="";
   if(in.indexOf("\"")!=0) return  false;
   in=in.substring(1);
   while(in.indexOf("\"")!=0){
        if(in.length()<=0) return false;
        if(in.charAt(0)=='\\'){
            in=in.substring(1);
            if(in.length()<=0) return false;
            char x=in.charAt(0);
            if(x=='n'){
               r=r+"\n";
            }
            else
            if(x=='"'){
               r=r+"\"";
            }
            else
            {
              r=r+in.charAt(0);
            }
        }
        else{
          char x=in.charAt(0);
          r=r+in.charAt(0);
        }
        in=in.substring(1);
   }
   strc[0]=r;
   rest[0]=in;
   return true;
}
 
 
boolean rHex(String in, long hex[], String rest[]){
  String r;
  long lx;
  lx=0;
   if(in.indexOf("0x")!=0) return false;
    // Serial.println("rHex "+in+" ");
    in=in.substring(2);
   if(in.length()<=0) return false;
   char x=in.charAt(0);
   while(isHexadecimalDigit(x)){
      if(isDigit(x)){
        lx=lx*16+x-'0';
      }
      else
      if(('a'<=x) && x<='f'){
         lx=lx*16+x-'a'+10;
      }
      else
      if('A'<=x && x<='F'){
         lx=lx*16+x-'A'+10;
      }
       in=in.substring(1);
       if(in.length()<=0) break;
       x=in.charAt(0);
   }
   hex[0]=lx;
   rest[0]=in;
   //Serial.println(hex[0],HEX);
   return true;
}
 
boolean rInt(String in, long ri[], String rest[]){
  //Serial.print("rInt "+in+" ");
  String r;
  int sign;
  long lx;
  lx=0;
  sign=1;
  if(in.indexOf("-")==0){
     sign=-1;
     in=in.substring(1);
  }
  if(in.length()<=0) return false;
  char x=in.charAt(0);
  if(!isDigit(x)) return false;
  while(isDigit(x)){
     lx=lx*10+x-'0';
     in=in.substring(1);
     if(in.length()<=0) break;
     x=in.charAt(0);
  }
  ri[0]=sign*lx;
  //Serial.println(ri[0]);
  rest[0]=in;
   return true;
}
 
 
//+=============================================================================
// The repeating section of the code
//
 
 
void  loop ( )
{
  decode_results  results;        // Somewhere to store the results
 
  if (irrecv.decode(&results)) {  // Grab an IR code
    dumpInfo(&results);           // Output the results
    dumpRaw(&results);            // Output the results in RAW format
    dumpCode(&results);           // Output the results as source code
    Serial.println("");           // Blank line between entries
    irrecv.resume();              // Prepare for the next value
  }
 
  int buttonState = digitalRead(pushButton1);
  if(buttonState==HIGH){
//  for (int i = 0; i < 3; i++) {
//    irsend.sendSony(0xa90, 12);
    irsend.sendNEC(0xCF20D, 32);   //Power On the Projector...Benq MW612
    delay(10000);
  }
  buttonState = digitalRead(pushButton2);
  if(buttonState==HIGH){
    irsend.sendNEC(0xC728D, 32);   //Power Off the Projector...Benq MW612
    delay(10000);
  }
 
  while (Serial.available() > 0) {
    String str = Serial.readStringUntil(';');
    String rest[1];
    long ri[1];
     String rs[1];    
    Serial.println(str);
    str=skipSpace(str);
    if(str.indexOf("on-projector")==0){
      irsend.sendNEC(0xCF20D, 32);   //Power On the Projector...Benq MW612
      delay(1000);
    }
    else
    if(str.indexOf("off-projector")==0){
      irsend.sendNEC(0xC728D, 32);   //Power Off the Projector...Benq MW612
      delay(1000);
    }
    else
    if(rKeyword(str,"irCmd",rest)){
       str=skipSpace(rest[0]);
       String mkr="RAW";
       if(rKeyword(str,"NEC",rest)){
           mkr="NEC";
       }
       else
       if(rKeyword(str,"SONY",rest)){
          mkr="SONY";
       }
       else
       if(rKeyword(str,"RC5", rest)){
          mkr="RC5";
       }
       if(rKeyword(str,"RC6", rest)){
         mkr="RC6";
       }
       str=skipSpace(rest[0]);
       if(!rHex(str,ri,rest)){ Serial.print("error...hex is expected..."+str); return;}
        long  cmd=ri[0];
        str=skipSpace(rest[0]);
       if(!rInt(str,ri,rest)){Serial.print("error...int is expected..."+str); return;}
       long lx=ri[0];
       if(mkr.indexOf("NEC")==0){
           irsend.sendNEC(cmd,lx);
           Serial.print("irsend NEC ");
           Serial.print(cmd, HEX);
           Serial.print(" ");
           Serial.println(lx);
       }
       else
       if(mkr.indexOf("SONY")==0){
         irsend.sendSony(cmd,lx);
           Serial.print("irsend SONY ");
           Serial.print(cmd, HEX);
           Serial.print(" ");
           Serial.println(lx);
       }
       else
       if(mkr.indexOf("RC5")==0){
         irsend.sendRC5(cmd,lx);
           Serial.print("irsend RC5 ");
           Serial.print(cmd, HEX);
           Serial.print(" ");
           Serial.println(lx);
       }
       else
       if(mkr.indexOf("RC6")==0){
         irsend.sendRC6(cmd,lx);
            Serial.print("irsend RC6 ");
           Serial.print(cmd, HEX);
           Serial.print(" ");
           Serial.println(lx);
       }     
    }
  }
}

トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS