summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2015-06-12 10:37:13 +0200
committerPeter Wu <peter@lekensteyn.nl>2015-06-12 10:40:15 +0200
commit8ca108d2e6f8a1eaeabc410eb1fcbb43b701b6eb (patch)
treeec197ef4de850ae83f2e35ea33395726091f6c70
parent485d18357a476a45bcce30835b12143e4133c8e5 (diff)
downloadcode-8ca108d2e6f8a1eaeabc410eb1fcbb43b701b6eb.tar.gz
Try to fix IR remote routine
Documented at https://github.com/shirriff/Arduino-IRremote/wiki/IRremote-library-API
-rw-r--r--Venus_Skeleton/Venus_Skeleton.ino38
1 files changed, 15 insertions, 23 deletions
diff --git a/Venus_Skeleton/Venus_Skeleton.ino b/Venus_Skeleton/Venus_Skeleton.ino
index 99be3fb..1a38c3e 100644
--- a/Venus_Skeleton/Venus_Skeleton.ino
+++ b/Venus_Skeleton/Venus_Skeleton.ino
@@ -389,26 +389,21 @@ void sensSampleGripper() {
// sensor IR, beacon detection and recognition
int sensIRRemote() {
- int x = 0;
- int LabFound = LOW;
- for (int i = 1; i <= 10; i++)
- {
- x = 0;
- do
- {
- if(irrecv.decode(&results))
- {
- irrecv.resume();
- }
- x++;
- if( x == 5 )
- {
- LabFound = HIGH;
- return LabFound;
+ int matches = 0;
+ for (int i = 0; i < 10; i++) {
+ if (irrecv.decode(&results)) {
+ // check for the parameters sent by IRbeacon.ino
+ if (results->decode_type == SONY &&
+ results->bits == 12 && results->value != 0xa90) {
+ matches++;
}
- } while(results.value, DEC == LCode);
+ irrecv.resume();
+ }
}
- return LabFound;
+ DEBUG_PRINT(matches);
+ DEBUG_PRINT(" IRRemote matches\n");
+ // accept when half of the probes resulted in a match.
+ return matches >= 5;
}
void sensBeaconTurret() {
@@ -416,12 +411,9 @@ void sensBeaconTurret() {
// (creates triangle with centerOfRobot, centerOfSensor and Obstacle as its corners)
if (timerTurret == 0) {
- int i;
- bool beacon = false;
+ bool beacon;
- i = sensIRRemote(); // SENSORDATA HERE
- if (i == HIGH)
- beacon = true;
+ beacon = sensIRRemote(); // SENSORDATA HERE
if (data.beacon_detected[counterTurret] != beacon) {
data.beacon_detected[counterTurret] = beacon;