Hi,
I’ve been looking at the remote control. The following code shows that readIR() returns a button press even after the button has been released (no problem, and it might be useful to know) and shows the time between the controller sending out codes if a button is held down.
[code] /*
IR Remote
Sparki has a sensor that lets it receives commands from
the included remote control.
The remote control outputs codes periodically while a button is
pushed. If readIR() is called after a code is received it
outputs that code once then outputs -1 if ut is called again
until the next code is recieved. This sketch helps determine
information about the remote and the readIR() function.
Open serial monitor when robot beeps.
Written by Philip Martel. This code is in the public domain.
*/
#include <Sparki.h>
SparkiClass robot;
void setup() {
int I;
robot.begin();
robot.beep();
delay(5000);
Serial.println(“press a few buttons. Release them before 0”);
for ( I = 5; I >= 0; I-- )
{
Serial.println(I);
delay(1000);
}
I = robot.readIR();
Serial.print(“code read after button is released “);
Serial.println(I);
Serial.print(”\nnow press and hold buttons to see “);
Serial.println(” time between codes”);
}
// /------^-----
// | |
// | 69 70 71 |
// | 68 64 67 |
// | 7 21 9 |
// | 22 25 13 |
// | 12 24 94 |
// | 8 28 90 |
// | 66 82 74 |
// ____________/
// note about 107500 microseconds between valid code values
// with the button held down.
void loop() {
static long LastTime = 0;
long Now;
int code = robot.readIR();
char S[20];
if(code != -1)
{
Now = micros();
sprintf(S,"%d %ld",code,Now - LastTime);
Serial.println(S);
LastTime = Now;
}
}
[/code]
This code is placed in the public domain.