It is required to process the text. I will not refuse help :)
Arduino voltage control library.
The class is template and uses 1 parameter: uint8_t _id = 0 . The first non -compulsory parameter transparently conveys uint8_t value to the caused flasks, which allows you to identify the class when using several copies of the class per one flask. For example PIN reading ADC:
VoltageControl < A1 > Volt1 ;
VoltageControl < A2 > Volt2 ;
//...
Volt1 . SetRequest ( OnRequestVoltage );
Volt2 . SetRequest ( OnRequestVoltage );
//...
int32_t OnRequestVoltage ( uint8_t id )
{
return analogRead ( id );
}For convenience, the class has two designers.
` VoltageControl ()` Class designer without parameters. When used, it is required to convey the settings through Set methods.
VoltageControl ( request_t callback_req , uint16_t interval_req , response_t callback_res , bool once , uint32_t coefficient , int32_t vmin , int32_t vmax )Class designer indicating all the settings.
SetResponse() , the translating coefficient of the ACP value, the minimum permissible voltage, the maximum permissible voltage. int32_t OnRequestVoltage ( uint8_t id ) When the class is necessary to read the value of the ADC, this flask function will be caused. You can perform or integrated method of reading ADC ( analogRead() ), directly work with registers or read an external ADC for any available tire.
void OnResponseVoltage ( uint8_t id , int32_t value , int8_t state )When you need to notify the main program about the changes, this tank-function will be an interchange. You can decide on the branching of the code and fulfill everything you need here.
GetValid() . void SetRequest ( request_t callback , uint16_t interval )The method indicates a tank-function of reading ADC.
void SetResponse ( response_t callback , bool once = false) The method indicates a voltage measurement of the voltage measurement result. If once = true , then a call of a flab rate of functions will occur only when the condition is changed (reduced, increased, normal voltage), otherwise the challenge will occur at each measurement of the ADC.
void SetCoefficient ( uint32_t coefficient )The method determines the coefficient of translation of the ACP value to microwaves.
void SetMin ( uint32_t vmin )The method determines the minimum allowable voltage.
void SetMax ( uint32_t vmax )The method determines the maximum permissible voltage.
void SetStart ()The method sets the class starting flag.
void SetStop ()The method sets the class stop flag.
int8_t GetValid ()The method checks the voltage and returns the result in the form of a number.
-1 is less than permissible, 0 - in the framework of permissible, 1 - more permissible. int32_t GetVoltage ()The method returns the current voltage.
void Processing ( uint32_t currentTime = millis ()) Number processing method. In the event that your loop has a definition of the current time, it is more advisable to pass this time as a parameter.
static inline uint32_t GetCoefficient ( float vref , float r1 = 0 , float r2 = 1 , float quantization = 1024 ) The utility that helps calculate the coefficient for SetCoefficient() method. If the divider is not used, then only Vref is indicated.