DFRobot DFR0274 Schnellstart-Handbuch - Seite 8
Blättern Sie online oder laden Sie pdf Schnellstart-Handbuch für Mikrocontroller DFRobot DFR0274 herunter. DFRobot DFR0274 12 Seiten. Rgb led strip driver shield
while(pulseIn(IR_PIN, HIGH) < BIT_START);
read_pulse(pulse);
pulse_to_bits(pulse, bits);
RemoteVerify(bits);
return bits_to_int(bits);
}
/*
use pulseIn to receive IR pulses from the remote.
Record the length of these pulses (in ms) in an array
*/
void read_pulse(int pulse[])
{
for (int i = 0; i < IR_BIT_LENGTH; i++)
{
pulse[i] = pulseIn(IR_PIN, HIGH);
}
}
/*
IR pulses encode binary "0" as a short pulse, and binary "1"
as a long pulse.
convert this to an array containing binary values
*/
void pulse_to_bits(int pulse[], int bits[])
{
if (debug) { Serial.println("-----"); }
for(int i = 0; i < IR_BIT_LENGTH; i++)
{
if (debug) { Serial.println(pulse[i]); }
if(pulse[i] > BIT_1) //is it a 1?
{
bits[i] = 1;
}
else if(pulse[i] > BIT_0) //is it a 0?
{
bits[i] = 0;
}
else //data is invalid...
{
Serial.println("Error");
}
}
}
/*
check returns proper first 14 check bits
*/
void RemoteVerify(int bits[])
{
int result = 0;
int seed = 1;
Arrow.com.
Arrow.com.
Arrow.com.
Arrow.com.
Arrow.com.
Arrow.com.
Arrow.com.
Arrow.com.
Downloaded from
Downloaded from
Downloaded from
Downloaded from
Downloaded from
Downloaded from
Downloaded from
Downloaded from
Given an array containing pulse lengths,