int IRledPin = 13; // LED connected to digital pin 13
int _38HZ_Space=6; //38KHz interval
//定义按键的波形特征码
long PowerOnArray[][2]=
{
1,913,0,412,1,85,0,22,1,87,0,23,1,87,0,25,1,85,0,25,1,85,0,26,1,85,0,
27,1,83,0,27,1,84,0,27,1,84,0,138,1,83,0,138,1,83,0,138,1,82,0,138,1,
82,0,139,1,82,0,140,1,80,0,32,1,75,0,144,1,76,0,146,1,74,0,38,1,69,0,
153,1,66,0,156,1,64,0,46,1,64,0,47,1,63,0,48,1,61,0,50,1,59,0,51,1,59,
0,163,1,56,0,55,1,56,0,55,1,55,0,166,1,56,0,165,1,56,0,166,1,55,0,165,
1,56,0,4021,1,719,0,209,1,56,0,0
};
void setup() {
// initialize the IR digital pin as an output:
pinMode(IRledPin, OUTPUT);
Serial.begin(9600);
}
void loop()
{
//Serial.println("Sending IR signal");
char Recv;
if (Serial.available()>0)
{
//Serial.println("Has incoming chars");
Recv=Serial.read();
Serial.println(Recv);
switch (Recv)
{
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
{
Serial.println("Power On...");
_38HZ_Space = Recv - 48;
Serial.println(_38HZ_Space);
PowerOn();
break;
};
default:
{
};
}
}
//delay(60*1000); // wait one minute (60 seconds * 1000 milliseconds)
}
void PowerOn()
{
long i,c;
long cmd,value;
c=sizeof(PowerOnArray)/sizeof(PowerOnArray[0][0]);
for (i=0; i<=c; i++)
{
cmd=PowerOnArray
[0];
value=PowerOnArray[1];
if (cmd==1)
pulseIR(value*10,_38HZ_Space);
else
delayMicroseconds(value*10);
}
}
// This procedure sends a 38KHz pulse to the IRledPin
// for a certain # of microseconds. We'll use this whenever we need to send codes
void pulseIR(long microsecs, long Interval) {
// we'll count down from the number of microseconds we are told to wait
Serial.print(microsecs);
long i;
i= micros();
long c;
c=0; //
cli(); // this turns off any background interrupts
while (microsecs > 0) {
// 38 kHz is about 13 microseconds high and 13 microseconds low
digitalWrite(IRledPin, HIGH); // this takes about 3 microseconds to happen
delayMicroseconds(Interval); // hang out for 10 microseconds
digitalWrite(IRledPin, LOW); // this also takes about 3 microseconds
delayMicroseconds(Interval); // hang out for 10 microseconds
// so 26 microseconds altogether
microsecs -= 26;
c++;
}
sei(); // this turns them back on
i = micros() -i;
Serial.print(" ");
Serial.print(c );
Serial.print("cycles and takes ");
Serial.print(i);
Serial.println(" us");
}
后面部分怎么变成斜体了? 