Page for the program development DCC_Loco_Fn
//DCC_Loco_Fn.ino Application or client code#include "DCC_Loco_Fn.h"#define LOCO 3DCC_Loco_Fn Fn;void setup() { Serial.begin(112500); Fn.begin( );}void loop() { static byte saveActive; int active = Fn.Fn_State(LOCO); if (active < 256) { //valid reading if (active != saveActive){ //new reading Serial.println (active, HEX); saveActive = active; } //new reading } // valid reading}----------------------------------------//DCC_Loco_Fn.cpp Implementation File#include "DCC_Loco_Fn.h"DCC_Loco_Fn::DCC_Loco_Fn ( ) { };void DCC_Loco_Fn::begin ( ){ DCC_Probe::begin( ); }int DCC_Loco_Fn::Fn_State(int loco ){ if (!message_done()) return 256; //flags no new data static int pat; //pattern of functions to return byte command1 = get_result(1); byte command2 = get_result(2); clear_message_done( ); //information used if (command1 == 255) return 256; //ignore idle if (command1 >=128 ) return 256; //not a short loco if ((command1 & 0x7F) != loco) return 256; //not loco of interest if (command2 < 128) return 256; //not fn commands if (command2 >= 192) return 256; //not a function command command2 &= 0x2F; //mask light if (command2 < 32) pat = (pat&0xF0) | command2&0xF; else pat = ((command2&0xF)*16)|(pat&0xF); //patterns in higher bits return (pat);} ---------------------------------------------------//DCC_Loco_fn.h Header File#ifndef DCC_LOCO_FN_H#define DCC_LOCO_FN_H#include <DCC_Probe.h>class DCC_Loco_Fn : public DCC_Probe { public : DCC_Loco_Fn( ); void begin( ); int Fn_State(int loco ); }; //don't forget - error message gives no clue where problem lies#endif