diff --git a/RMFT2.cpp b/RMFT2.cpp index 320d36f..4277f92 100644 --- a/RMFT2.cpp +++ b/RMFT2.cpp @@ -658,6 +658,14 @@ void RMFT2::loop2() { if (loco) DCC::setFn(loco,operand,false); break; + case OPCODE_DRIVE: + { + if (readSensor(operand)) break; + byte analogSpeed=IODevice::readAnalogue(GET_OPERAND(1)) *127 / 1024; + if (speedo!=analogSpeed) driveLoco(analogSpeed); + return; + } + case OPCODE_XFON: DCC::setFn(operand,GET_OPERAND(1),true); break; diff --git a/RMFT2.h b/RMFT2.h index 255fffd..6fed768 100644 --- a/RMFT2.h +++ b/RMFT2.h @@ -35,7 +35,7 @@ enum OPCODE : byte {OPCODE_THROW,OPCODE_CLOSE, OPCODE_IF,OPCODE_IFNOT,OPCODE_ENDIF,OPCODE_IFRANDOM,OPCODE_IFRESERVE, OPCODE_DELAY,OPCODE_DELAYMINS,OPCODE_RANDWAIT, OPCODE_FON,OPCODE_FOFF,OPCODE_XFON,OPCODE_XFOFF, - OPCODE_RED,OPCODE_GREEN,OPCODE_AMBER, + OPCODE_RED,OPCODE_GREEN,OPCODE_AMBER,OPCODE_DRIVE, OPCODE_SERVO,OPCODE_SIGNAL,OPCODE_TURNOUT,OPCODE_WAITFOR, OPCODE_PAD,OPCODE_FOLLOW,OPCODE_CALL,OPCODE_RETURN, OPCODE_JOIN,OPCODE_UNJOIN,OPCODE_READ_LOCO1,OPCODE_READ_LOCO2,OPCODE_POM, diff --git a/RMFTMacros.h b/RMFTMacros.h index 899b56a..af0683c 100644 --- a/RMFTMacros.h +++ b/RMFTMacros.h @@ -63,6 +63,7 @@ #define DEACTIVATE(addr,subaddr) #define ACTIVATEL(addr) #define DEACTIVATEL(addr) +#define DRIVE(analogpin,stopper) #define AMBER(signal_id) #define AT(sensor_id) #define AUTOSTART @@ -164,6 +165,7 @@ const int StringMacroTracker1=__COUNTER__; #undef AFTER #undef ACTIVATE #undef DEACTIVATE +#undef DRIVE #undef ACTIVATEL #undef DEACTIVATEL #undef AMBER @@ -253,7 +255,7 @@ const int StringMacroTracker1=__COUNTER__; #define DEACTIVATE(addr,subaddr) OPCODE_DCCACTIVATE,V(addr<<3 | subaddr<<1), #define ACTIVATEL(addr) OPCODE_DCCACTIVATE,V((addr+3)<<3 | 1), #define DEACTIVATEL(addr) OPCODE_DCCACTIVATE,V((addr+3)<<3), - +#define DRIVE(analogpin,stopper) OPCODE_DRIVE,V(stopper),OPCODE_PAD,V(analogpin), #define AFTER(sensor_id) OPCODE_AT,V(sensor_id),OPCODE_AFTER,V(sensor_id), #define AMBER(signal_id) OPCODE_AMBER,V(signal_id), #define AT(sensor_id) OPCODE_AT,V(sensor_id),