Hello all,
I'm trying to get deeper into learning rotary encoders. I have a learning disability and it's sometimes best for me to manually modify code and see the results to learn, versus just reading theory, which I find really hard to implement on my own.
I found some really great code I'm playing with from: https://create.arduino.cc/projecthub/mitov/save-rotary-encoder-value-in-arduino-eeprom-7dae69 All credit should go to this person!
The code works great, I can increment the value by 1 each time I turn the encoder, and the values save correctly to EEPROM.
However, I'm trying to learn how the original coder setup the increment routine, so I can change the code to increment by 100 each turn of the encoder. AKA 100, 200, 300, 400 instead of 100, 101, 102, 103, etc.
Can anyone help me understand how the increment by 1-per-turn works, so I can change this to 100-per-turn? Thanks greatly in advance! Code is listed below:
//------------------ Source --------------------
//
// VisuinoEEPROMRotaryEncoderTutorial.visuino
//
//----------------------------------------------
#define VISUINO_ARDUINO_NANO
#include <OpenWire.h>
#include <Mitov.h>
#include <Mitov_EEPROM.h>
#include <EEPROM.h>
#include <Mitov_Memory.h>
#include <Mitov_StandardSerial.h>
#include <Mitov_Counter.h>
#include <Mitov_RotaryEncoderSensor.h>
#include <Mitov_SetValueItems.h>
#include <Mitov_Button.h>
#include <Mitov_LogicGates.h>
#include <Mitov_Timing.h>
// Shared Component Member Variables
namespace ComponentVariables
{
class
{
public:
bool Value1 : 1;
bool Value2 : 1;
bool Value3 : 1;
uint32_t Value4 : 32;
bool Value5 : 1;
bool Value6 : 1;
bool Value7 : 1;
bool Value8 : 1;
bool Value9 : 1;
} BitFields;
class Variable1
{
public:
inline static bool GetValue() { return BitFields.Value1; }
inline static void SetValue( bool AValue ) { BitFields.Value1 = AValue; }
};
class Variable2
{
public:
inline static bool GetValue() { return BitFields.Value2; }
inline static void SetValue( bool AValue ) { BitFields.Value2 = AValue; }
};
class Variable3
{
public:
inline static bool GetValue() { return BitFields.Value3; }
inline static void SetValue( bool AValue ) { BitFields.Value3 = AValue; }
};
class Variable4
{
public:
inline static uint32_t GetValue() { return BitFields.Value4; }
inline static void SetValue( uint32_t AValue ) { BitFields.Value4 = AValue; }
};
class Variable5
{
public:
inline static bool GetValue() { return BitFields.Value5; }
inline static void SetValue( bool AValue ) { BitFields.Value5 = AValue; }
};
class Variable6
{
public:
inline static bool GetValue() { return BitFields.Value6; }
inline static void SetValue( bool AValue ) { BitFields.Value6 = AValue; }
};
class Variable7
{
public:
inline static bool GetValue() { return BitFields.Value7; }
inline static void SetValue( bool AValue ) { BitFields.Value7 = AValue; }
};
class Variable8
{
public:
inline static bool GetValue() { return BitFields.Value8; }
inline static void SetValue( bool AValue ) { BitFields.Value8 = AValue; }
};
class Variable9
{
public:
inline static bool GetValue() { return BitFields.Value9; }
inline static void SetValue( bool AValue ) { BitFields.Value9 = AValue; }
};
} // ComponentVariables
// Pin Call Declarations
namespace PinCalls
{
class PinCallerReceive0
{
public:
void Notify( void *_Data );
};
class PinCallerReceive1
{
public:
void Notify( void *_Data );
};
class PinCallerReceive2
{
public:
void Notify( void *_Data );
};
class PinCallerReceive3
{
public:
void Notify( void *_Data );
};
class PinCallerReceive4
{
public:
void Notify( void *_Data );
};
class PinCallerReceive5
{
public:
void Notify( void *_Data );
};
class PinCallerReceive6
{
public:
void Notify( void *_Data );
};
class PinCallerReceive7
{
public:
void Notify( void *_Data );
};
} // PinCalls
// Call Chains
namespace CallChains
{
class ProcessWrite1
{
public:
inline static uint32_t Count() { return 1; }
static void Call();
};
class InterruptRaising1
{
public:
inline static uint32_t Count() { return 1; }
static void Call();
};
class InterruptFalling1
{
public:
inline static uint32_t Count() { return 1; }
static void Call();
};
} // CallChains
// Arduino Board Declarations
namespace BoardDeclarations
{
namespace Types
{
typedef Mitov::ArduinoDigitalOutputChannel<
Mitov::ConstantProperty<22, bool, false>, // IsAnalog
Mitov::ConstantProperty<24, bool, false>, // IsCombinedInOut
Mitov::ConstantProperty<21, bool, false>, // IsOpenDrain
Mitov::ConstantProperty<26, bool, false>, // IsOutput
Mitov::ConstantProperty<20, bool, false>, // IsPullDown
Mitov::ConstantProperty<5, bool, false >, // IsPullUp
Mitov::ConstantProperty<23, bool, false>, // IsRawInput
Mitov::DigitalPin_NoImplementation<6 >, // OutputPin
2 // PIN
> ArduinoDigitalChannel_2;
} // Types
namespace Instances
{
Types::ArduinoDigitalChannel_2 ArduinoDigitalChannel_2;
} // Instances
namespace Types
{
typedef Mitov::ArduinoDigitalOutputChannel<
Mitov::ConstantProperty<22, bool, false>, // IsAnalog
Mitov::ConstantProperty<24, bool, false>, // IsCombinedInOut
Mitov::ConstantProperty<21, bool, false>, // IsOpenDrain
Mitov::ConstantProperty<26, bool, false>, // IsOutput
Mitov::ConstantProperty<20, bool, false>, // IsPullDown
Mitov::ConstantProperty<5, bool, false >, // IsPullUp
Mitov::ConstantProperty<23, bool, false>, // IsRawInput
Mitov::DigitalPin_NoImplementation<6 >, // OutputPin
3 // PIN
> ArduinoDigitalChannel_3;
} // Types
namespace Instances
{
Types::ArduinoDigitalChannel_3 ArduinoDigitalChannel_3;
} // Instances
namespace Types
{
typedef Mitov::ArduinoDigitalOutputChannel<
Mitov::ConstantProperty<22, bool, false>, // IsAnalog
Mitov::ConstantProperty<24, bool, false>, // IsCombinedInOut
Mitov::ConstantProperty<21, bool, false>, // IsOpenDrain
Mitov::ConstantProperty<26, bool, false>, // IsOutput
Mitov::ConstantProperty<20, bool, false>, // IsPullDown
Mitov::ConstantProperty<5, bool, true >, // IsPullUp
Mitov::ConstantProperty<23, bool, false>, // IsRawInput
Mitov::DigitalPin_EmbeddedPinImplementation<6, ::PinCalls::PinCallerReceive0 >, // OutputPin
4 // PIN
> ArduinoDigitalChannel_4;
} // Types
namespace Instances
{
Types::ArduinoDigitalChannel_4 ArduinoDigitalChannel_4;
} // Instances
namespace Types
{
typedef Mitov::SerialPort<
SERIAL_TYPE, // 0_T_TYPE
Serial, // 1_C_OBJECT
Mitov::ConstantProperty<4, uint32_t, 0 >, // AfterSendingDelay
Mitov::ConstantProperty<7, uint32_t, 8 >, // DataBits
Mitov::ConstantProperty<2, bool, true >, // Enabled
Mitov::ConstantProperty<12, uint32_t, 0 >, // FEndTime
Mitov::ConstantProperty<10, bool, false >, // FSending
Mitov::GenericPin_NoImplementation<5 >, // OutputPin
Mitov::ConstantProperty<9, Mitov::TArduinoStandardSerialParity, Mitov::spNone >, // Parity
Mitov::DigitalPin_NoImplementation<3 >, // SendingOutputPin
Mitov::ConstantProperty<6, uint32_t, 9600 >, // Speed
Mitov::ConstantProperty<8, uint32_t, 1 > // StopBits
> SerialPort0;
} // Types
namespace Instances
{
Types::SerialPort0 SerialPort0;
} // Instances
namespace Types
{
typedef Mitov::ArduinoSerialInput<BoardDeclarations::Types::SerialPort0, BoardDeclarations::Instances::SerialPort0, int32_t> SerialPort0_Input_IOWIntegerStream_1;
} // Types
namespace Instances
{
Types::SerialPort0_Input_IOWIntegerStream_1 SerialPort0_Input_IOWIntegerStream_1;
} // Instances
} // BoardDeclarations
// Interrupts
namespace Interrupts
{
void __ICACHE_RAM_ATTR__ Handler2();
OpenWire::PinChangeInterrupt<2, ::CallChains::InterruptRaising1, ::CallChains::InterruptFalling1> Pin2;
void __ICACHE_RAM_ATTR__ Handler2()
{
Pin2.InterruptHandler();
}
} // Interrupts
// Declarations
namespace Declarations
{
namespace Types
{
typedef Mitov::ArduinoEEPROM<
4, // C_SIZE
Mitov::EmbeddedCallChain<CallChains::ProcessWrite1 >, // Elements_ProcessWrite
Mitov::ConstantProperty<1, bool, true > // Enabled
> TArduinoEEPROMModule1;
} // Types
namespace Instances
{
Types::TArduinoEEPROMModule1 TArduinoEEPROMModule1;
} // Instances
namespace Types
{
typedef Mitov::TypedMemoryElement<
Declarations::Types::TArduinoEEPROMModule1, // 0_TYPE_OWNER
Declarations::Instances::TArduinoEEPROMModule1, // 1_NAME_OWNER
0, // C_Address
0, // C_Mask
Mitov::TypedVariable<9, bool, ::ComponentVariables::Variable1 >, // FModified
Mitov::TypedVariableValue<11, bool, ::ComponentVariables::Variable2, false >, // FRememberClocked
Mitov::TypedPin_EmbeddedPinImplementation<8, ::PinCalls::PinCallerReceive1, int32_t >, // OutputPin
Mitov::ConstantProperty<5, bool, true>, // RecallInputPin_o_IsConnected
Mitov::ConstantProperty<6, bool, false >, // RecallOnRemember
Mitov::ConstantProperty<3, bool, true>, // RememberInputPin_o_IsConnected
int32_t, // TYPE_DATA
int32_t // TYPE_PIN
> TArduinoMemoryIntegerElement1;
} // Types
namespace Instances
{
Types::TArduinoMemoryIntegerElement1 TArduinoMemoryIntegerElement1;
} // Instances
namespace Types
{
typedef Mitov::RotaryEncoderSensor_Interrupt_Debounce<
BoardDeclarations::Types::ArduinoDigitalChannel_3, // 0_B_0_TYPE
BoardDeclarations::Instances::ArduinoDigitalChannel_3, // 0_B_1_NAME
Mitov::ConstantProperty<20, Mitov::TArduinoClockMode::TArduinoClockMode, Mitov::TArduinoClockMode::Falling >, // ClockMode
Mitov::ConstantProperty<21, uint32_t, 5 >, // DebounceInterval
Mitov::ClockPin_EmbeddedPinImplementation<19, ::PinCalls::PinCallerReceive3 >, // DownOutputPin
Mitov::ConstantProperty<4, bool, true >, // Enabled
Mitov::ConstantProperty<22, int32_t, 0 >, // FCount
Mitov::ConstantProperty<6, int32_t, 0 >, // InitialValue
Mitov::NestedProperty<14, Mitov::GenericValueLimit<
Mitov::ConstantProperty<13, bool, true >, // RollOver
Mitov::ConstantProperty<12, int32_t, 2147483647 > // Value
> >, // Value_Max
Mitov::NestedProperty<10, Mitov::GenericValueLimit<
Mitov::ConstantProperty<9, bool, true >, // RollOver
Mitov::ConstantProperty<8, int32_t, -2147483648 > // Value
> >, // Value_Min
Mitov::TypedPin_NoImplementation<3, int32_t >, // OutputPin
Mitov::ClockPin_EmbeddedPinImplementation<18, ::PinCalls::PinCallerReceive2 > // UpOutputPin
> RotaryEncoderSensor1;
} // Types
namespace Instances
{
Types::RotaryEncoderSensor1 RotaryEncoderSensor1;
} // Instances
namespace Types
{
typedef Mitov::UpDownCounter<
Mitov::ConstantProperty<4, bool, true >, // Enabled
Mitov::TypedVariableMinMax<20, int32_t, ::ComponentVariables::Variable4, -2147483648, 2147483647 >, // FCount
Mitov::ConstantProperty<6, int32_t, 0 >, // InitialValue
Mitov::NestedProperty<14, Mitov::GenericValueLimit<
Mitov::ConstantProperty<13, bool, true >, // RollOver
Mitov::ConstantProperty<12, int32_t, 2147483647 > // Value
> >, // Value_Max
Mitov::NestedProperty<10, Mitov::GenericValueLimit<
Mitov::ConstantProperty<9, bool, true >, // RollOver
Mitov::ConstantProperty<8, int32_t, -2147483648 > // Value
> >, // Value_Min
Mitov::TypedVariable<18, bool, ::ComponentVariables::Variable3 >, // NeedsUpdate
Mitov::TypedPin_EmbeddedPinImplementation<3, ::PinCalls::PinCallerReceive4, int32_t > // OutputPin
> UpDownCounter1;
} // Types
namespace Instances
{
Types::UpDownCounter1 UpDownCounter1;
} // Instances
namespace Types
{
typedef Mitov::ArduinoSetValueElement<
Declarations::Types::UpDownCounter1, // 0_TYPE_OWNER
Declarations::Instances::UpDownCounter1, // 1_NAME_OWNER
Mitov::VariableProperty<2, int32_t, 0 > // Value
> TArduinoIntegerSetValueElement1;
} // Types
namespace Instances
{
Types::TArduinoIntegerSetValueElement1 TArduinoIntegerSetValueElement1;
} // Instances
namespace Types
{
typedef Mitov::Button<
Mitov::ConstantProperty<5, uint32_t, 50 >, // DebounceInterval
Mitov::TypedVariable<6, bool, ::ComponentVariables::Variable6 >, // FLastValue
Mitov::TypedVariable<8, bool, ::ComponentVariables::Variable7 >, // FValue
Mitov::DigitalPin_EmbeddedPinImplementation_ChangeOnly<3, ::PinCalls::PinCallerReceive5, Mitov::TypedVariable<0, bool, ::ComponentVariables::Variable5 > > // OutputPin
> Button1;
} // Types
namespace Instances
{
Types::Button1 Button1;
} // Instances
namespace Types
{
typedef Mitov::BooleanInverter<
Mitov::ConstantProperty<4, bool, true >, // Enabled
Mitov::DigitalPin_EmbeddedPinImplementation_ChangeOnly<3, ::PinCalls::PinCallerReceive6, Mitov::TypedVariable<0, bool, ::ComponentVariables::Variable8 > > // OutputPin
> Inverter1;
} // Types
namespace Instances
{
Types::Inverter1 Inverter1;
} // Instances
namespace Types
{
typedef Mitov::Start<
Mitov::ClockPin_EmbeddedPinImplementation<3, ::PinCalls::PinCallerReceive7 > // OutputPin
> Start1;
} // Types
namespace Instances
{
Types::Start1 Start1;
} // Instances
} // Declarations
// Type Converters
namespace TypeConverters
{
Mitov::Convert_BinaryToClock<Mitov::TypedVariable<0, bool, ::ComponentVariables::Variable9 >> Converter0;
} // TypeConverters
// Call Chains
namespace CallChains
{
void ProcessWrite1::Call()
{
Declarations::Instances::TArduinoMemoryIntegerElement1.ProcessWrite();
}
void InterruptRaising1::Call()
{
Declarations::Instances::RotaryEncoderSensor1.InterruptHandlerA( true );
}
void InterruptFalling1::Call()
{
Declarations::Instances::RotaryEncoderSensor1.InterruptHandlerA( false );
}
} // CallChains
// Pin Call Declarations
namespace PinCalls
{
void PinCallerConverterReceive1( void *_Data );
} // PinCalls
// Pin Call Implementations
namespace PinCalls
{
void PinCallerReceive1::Notify( void *_Data )
{
Declarations::Instances::TArduinoIntegerSetValueElement1.Value().InputPin_o_Receive( _Data );
}
void PinCallerReceive0::Notify( void *_Data )
{
Declarations::Instances::Button1.InputPin_o_Receive( _Data );
}
void PinCallerReceive2::Notify( void *_Data )
{
Declarations::Instances::UpDownCounter1.UpInputPin_o_Receive( _Data );
}
void PinCallerReceive3::Notify( void *_Data )
{
Declarations::Instances::UpDownCounter1.DownInputPin_o_Receive( _Data );
}
void PinCallerReceive4::Notify( void *_Data )
{
BoardDeclarations::Instances::SerialPort0_Input_IOWIntegerStream_1.InputPin_o_Receive( _Data );
Declarations::Instances::TArduinoMemoryIntegerElement1.InputPin_o_Receive( _Data );
}
void PinCallerReceive5::Notify( void *_Data )
{
Declarations::Instances::Inverter1.InputPin_o_Receive( _Data );
}
void PinCallerReceive6::Notify( void *_Data )
{
TypeConverters::Converter0.Convert( _Data, PinCallerConverterReceive1 );
}
void PinCallerConverterReceive1( void *_Data )
{
Declarations::Instances::TArduinoMemoryIntegerElement1.RememberInputPin_o_Receive( _Data );
}
void PinCallerReceive7::Notify( void *_Data )
{
Declarations::Instances::TArduinoMemoryIntegerElement1.RecallInputPin_o_Receive( _Data );
Declarations::Instances::TArduinoIntegerSetValueElement1.InputPin_o_Receive( _Data );
}
} // PinCalls
namespace ComponentsHardware
{
void SystemUpdateHardware()
{
Declarations::Instances::TArduinoEEPROMModule1.SystemLoopUpdateHardware();
}
} // ComponentsHardware
//The setup function is called once at startup of the sketch
void setup()
{
BoardDeclarations::Instances::SerialPort0.SystemInit();
BoardDeclarations::Instances::ArduinoDigitalChannel_2.SystemInit();
BoardDeclarations::Instances::ArduinoDigitalChannel_3.SystemInit();
BoardDeclarations::Instances::ArduinoDigitalChannel_4.SystemInit();
Declarations::Instances::TArduinoEEPROMModule1.SystemInit();
Declarations::Instances::RotaryEncoderSensor1.SystemInit();
Declarations::Instances::UpDownCounter1.SystemInit();
Interrupts::Pin2.Init( Interrupts::Handler2 );
BoardDeclarations::Instances::ArduinoDigitalChannel_2.SystemStart();
BoardDeclarations::Instances::ArduinoDigitalChannel_3.SystemStart();
BoardDeclarations::Instances::ArduinoDigitalChannel_4.SystemStart();
Declarations::Instances::RotaryEncoderSensor1.SystemStart();
Declarations::Instances::UpDownCounter1.SystemStart();
Declarations::Instances::Button1.SystemStart();
Declarations::Instances::Start1.SystemStart();
}
// The loop function is called in an endless loop
void loop()
{
BoardDeclarations::Instances::ArduinoDigitalChannel_2.SystemLoopBegin();
BoardDeclarations::Instances::ArduinoDigitalChannel_3.SystemLoopBegin();
BoardDeclarations::Instances::ArduinoDigitalChannel_4.SystemLoopBegin();
Declarations::Instances::RotaryEncoderSensor1.SystemLoopBegin();
Declarations::Instances::Button1.SystemLoopBegin();
ComponentsHardware::SystemUpdateHardware();
}