Example of using "Canvas" form "Graphics" library to display 3D graphics.
Dependencies: BSP_DISCO_F746NG Graphics mbed
Diff: HardwareAccess/Scale.cpp
- Revision:
- 2:ef3093a7a43e
- Parent:
- 0:8acbce46eede
diff -r 4a5e329e617b -r ef3093a7a43e HardwareAccess/Scale.cpp --- a/HardwareAccess/Scale.cpp Thu Nov 10 15:38:50 2016 +0000 +++ b/HardwareAccess/Scale.cpp Fri Nov 11 15:30:07 2016 +0000 @@ -5,7 +5,7 @@ #include "Scale.h" #include "mbed.h" // for AnalogIn -#ifdef ARDUINO +#ifdef ARDUINO int scalePin = 1; #else AnalogIn scaleRead(A1); @@ -13,44 +13,61 @@ Scale::Scale() { - Setup(1.f, 0.4f, 1.f, 8.f); + // Set ScaleFixed as default + SetScale(ScaleFixed, 1.f, 1.f, 8.f, 0.4f); } -Scale::Scale(float min, float max) +void Scale::SetScale(ScaleType type, float initialValue, float minValue, float maxValue, float delta) { - Setup(1.f, 0.4f, min, max); + _type = type; + + _scale = initialValue; + _delta = delta; + _minScale = minValue; + _maxScale = maxValue; } -void Scale::Setup(float scale, float delts, float min, float max) -{ - scale = scale; - delta = delta; - minScale = min; - maxScale = max; -} -// Simulate scale changing float Scale::GetScale() { - scale += delta; + switch(_type) { + + case ScaleReal: - if(scale > maxScale) - delta *= -1.f; + // Get real value + _scale = ReadScale(); + break; + + case ScaleSham: + + // Simulate changes + _scale += _delta; - if(scale < minScale) - delta *= -1.f; + if(_scale > _maxScale) + _delta *= -1.f; + + if(_scale < _minScale) + _delta *= -1.f; - return scale; + break; + + default: + break; + } + + return _scale; } /// Read the scale from a potentiometer attached to analog pin float Scale::ReadScale() { + float scale = _scale; + #ifdef ARDUINO scale = analogRead(scalePin); #else scale = scaleRead; #endif - return minScale + scale * (maxScale - minScale)/1024.f; + return _minScale + scale * (_maxScale - _minScale)/1024.f; } \ No newline at end of file