Non Synced Key Fob causing id issues

Hello,

I am currently having an issue with the photon system where if a non synced key fob button is hit the device will give a 0 (unidentified ID) on the next button press from a synced key fob. Once you hit the synced key fobs button again you will get the correct ID of 1. Is there a way to keep this from happening so the button presses are not missed? We are using 4 remotes that are synced to one base station so we are using the ID’s to tell a c++ software what to do off the id and then button.

Any help is greatly appreciated.

Cheers,

What code are you using?

#include "KeyFob.h"

KeyFob fob;
SYSTEM_MODE(SEMI_AUTOMATIC);
bool checkFob = false;

void setup() {
    //Setup communication to KeyFob interface module
    pinMode(A3, INPUT);
    attachInterrupt(A3, evalFob, CHANGE);
    Serial.begin(9600);
    Serial1.begin(9600);
}

void loop() {
    //If an interrupt has fired on A3 which is connected to the fob module then a button has been pressed or released so we need to determine what button was pressed or released.
    	delay(10);

   	    
    if(checkFob){
		checkFob = false;
		fob.evalFob();
		String action;
    
        // say what you got:
        
    		switch(fob.recentAction){
    		case(fob.button1release):
    			Serial.print(fob.recentFobID);
    			Serial.print("1");
    		break;
    		case(fob.button2release):
    		    Serial.print(fob.recentFobID);
    			Serial.print("2");
    		break;
    		case(fob.button3release):
    		    Serial.print(fob.recentFobID);
    			Serial.print("3");
    		break;
    		case(fob.button4release):
    		    Serial.print(fob.recentFobID);
    			Serial.print("4");
    		break;
    		case(fob.button5release):
    		    Serial.print(fob.recentFobID);
    			Serial.print("5");
    		break;
    		case(fob.button6release):
    		    Serial.print(fob.recentFobID);
    			Serial.print("6");
    		break;
    		case(fob.button7release):
    		    Serial.print(fob.recentFobID);
    			Serial.print("7");
    		break;
    		case(fob.button8release):
    		    Serial.print(fob.recentFobID);
    			Serial.print("8");
    		break;
    		}

	}

}

void evalFob(){
	checkFob = true;
}
/*
 * KeyFob.cpp
 *
 */
#include "KeyFob.h"

//KeyFob Buttons
int kfb1 = A0;
int kfb2 = A1;
int kfb3 = D2;
int kfb4 = D3;
int kfb5 = D4;
int kfb6 = D5;
int kfb7 = D6;
int kfb8 = D7;

//RSSI
int rssiPin = A2;
//KeyFob Interrupt function

KeyFob::KeyFob(){
}

void KeyFob::evalFob(){

	recentFobID = Serial1.read();
	 
	    int newStatus = 0;
	    
    	if(digitalRead(kfb1) == 1)	{
    		newStatus = newStatus | 1;
    	}else{
    		newStatus = newStatus & ~1;
    	}
    	if(digitalRead(kfb2) == 1)	{
    		newStatus = newStatus | 2;
    	}else{
    		newStatus = newStatus & ~2;
    	}
    	if(digitalRead(kfb3) == 1)	{
    		newStatus = newStatus | 4;
    	}else{
    		newStatus = newStatus & ~4;
    	}
    	if(digitalRead(kfb4) == 1)	{
    		newStatus = newStatus | 8;
    	}else{
    		newStatus = newStatus & ~8;
    	}
    	if(digitalRead(kfb5) == 1)	{
    		newStatus = newStatus | 16;
    	}else{
    		newStatus = newStatus & ~16;
    	}
    	if(digitalRead(kfb6) == 1)	{
    		newStatus = newStatus | 32;
    	}else{
    		newStatus = newStatus & ~32;
    	}
    	if(digitalRead(kfb7) == 1)	{
    		newStatus = newStatus | 64;
    	}else{
    		newStatus = newStatus & ~64;
    	}
    	if(digitalRead(kfb8) == 1)	{
    		newStatus = newStatus | 128;
    	}else{
    		newStatus = newStatus & ~128;
    	}
    
    	//off
    	if(newStatus < previousStatus){
    		int statusChange = previousStatus - newStatus;
    		if((statusChange & 1) == 1){
    			recentAction = button1release;
    		}
    		if((statusChange & 2) == 2){
    			recentAction = button2release;
    		}
    		if((statusChange & 4) == 4){
    			recentAction = button3release;
    		}
    		if((statusChange & 8) == 8){
    			recentAction = button4release;
    		}
    		if((statusChange & 16) == 16){
    			recentAction = button5release;
    		}
    		if((statusChange & 32) == 32){
    			recentAction = button6release;
    		}
    		if((statusChange & 64) == 64){
    			recentAction = button7release;
    		}
    		if((statusChange & 128) == 128){
    			recentAction = button8release;
    		}
    
    	}
    	if(previousStatus < newStatus){
    		int statusChange = newStatus - previousStatus;
    		if((statusChange & 1) == 1){
    			recentAction = button1press;
    		}
    		if((statusChange & 2) == 2){
    			recentAction = button2press;
    		}
    		if((statusChange & 4) == 4){
    			recentAction = button3press;
    		}
    		if((statusChange & 8) == 8){
    			recentAction = button4press;
    		}
    		if((statusChange & 16) == 16){
    			recentAction = button5press;
    		}
    		if((statusChange & 32) == 32){
    			recentAction = button6press;
    		}
    		if((statusChange & 64) == 64){
    			recentAction = button7press;
    		}
    		if((statusChange & 128) == 128){
    			recentAction = button8press;
    		}
    	}
    	previousStatus = newStatus;

}

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.