Example of using "Canvas" form "Graphics" library to display 3D graphics.
Dependencies: BSP_DISCO_F746NG Graphics mbed
HardwareAccess/Scale.cpp@3:aca7fe2d44b3, 2016-11-11 (annotated)
- Committer:
- karpent
- Date:
- Fri Nov 11 17:06:53 2016 +0000
- Revision:
- 3:aca7fe2d44b3
- Parent:
- 2:ef3093a7a43e
New 3d models added
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
karpent | 0:8acbce46eede | 1 | // |
karpent | 0:8acbce46eede | 2 | // Scale.cpp |
karpent | 0:8acbce46eede | 3 | // |
karpent | 0:8acbce46eede | 4 | |
karpent | 0:8acbce46eede | 5 | #include "Scale.h" |
karpent | 0:8acbce46eede | 6 | #include "mbed.h" // for AnalogIn |
karpent | 0:8acbce46eede | 7 | |
karpent | 2:ef3093a7a43e | 8 | #ifdef ARDUINO |
karpent | 0:8acbce46eede | 9 | int scalePin = 1; |
karpent | 0:8acbce46eede | 10 | #else |
karpent | 0:8acbce46eede | 11 | AnalogIn scaleRead(A1); |
karpent | 0:8acbce46eede | 12 | #endif |
karpent | 0:8acbce46eede | 13 | |
karpent | 0:8acbce46eede | 14 | Scale::Scale() |
karpent | 0:8acbce46eede | 15 | { |
karpent | 2:ef3093a7a43e | 16 | // Set ScaleFixed as default |
karpent | 2:ef3093a7a43e | 17 | SetScale(ScaleFixed, 1.f, 1.f, 8.f, 0.4f); |
karpent | 0:8acbce46eede | 18 | } |
karpent | 0:8acbce46eede | 19 | |
karpent | 2:ef3093a7a43e | 20 | void Scale::SetScale(ScaleType type, float initialValue, float minValue, float maxValue, float delta) |
karpent | 0:8acbce46eede | 21 | { |
karpent | 2:ef3093a7a43e | 22 | _type = type; |
karpent | 2:ef3093a7a43e | 23 | |
karpent | 2:ef3093a7a43e | 24 | _scale = initialValue; |
karpent | 2:ef3093a7a43e | 25 | _delta = delta; |
karpent | 2:ef3093a7a43e | 26 | _minScale = minValue; |
karpent | 2:ef3093a7a43e | 27 | _maxScale = maxValue; |
karpent | 0:8acbce46eede | 28 | } |
karpent | 0:8acbce46eede | 29 | |
karpent | 0:8acbce46eede | 30 | |
karpent | 0:8acbce46eede | 31 | float Scale::GetScale() |
karpent | 0:8acbce46eede | 32 | { |
karpent | 2:ef3093a7a43e | 33 | switch(_type) { |
karpent | 2:ef3093a7a43e | 34 | |
karpent | 2:ef3093a7a43e | 35 | case ScaleReal: |
karpent | 0:8acbce46eede | 36 | |
karpent | 2:ef3093a7a43e | 37 | // Get real value |
karpent | 2:ef3093a7a43e | 38 | _scale = ReadScale(); |
karpent | 2:ef3093a7a43e | 39 | break; |
karpent | 2:ef3093a7a43e | 40 | |
karpent | 2:ef3093a7a43e | 41 | case ScaleSham: |
karpent | 2:ef3093a7a43e | 42 | |
karpent | 2:ef3093a7a43e | 43 | // Simulate changes |
karpent | 2:ef3093a7a43e | 44 | _scale += _delta; |
karpent | 0:8acbce46eede | 45 | |
karpent | 2:ef3093a7a43e | 46 | if(_scale > _maxScale) |
karpent | 2:ef3093a7a43e | 47 | _delta *= -1.f; |
karpent | 2:ef3093a7a43e | 48 | |
karpent | 2:ef3093a7a43e | 49 | if(_scale < _minScale) |
karpent | 2:ef3093a7a43e | 50 | _delta *= -1.f; |
karpent | 0:8acbce46eede | 51 | |
karpent | 2:ef3093a7a43e | 52 | break; |
karpent | 2:ef3093a7a43e | 53 | |
karpent | 2:ef3093a7a43e | 54 | default: |
karpent | 2:ef3093a7a43e | 55 | break; |
karpent | 2:ef3093a7a43e | 56 | } |
karpent | 2:ef3093a7a43e | 57 | |
karpent | 2:ef3093a7a43e | 58 | return _scale; |
karpent | 0:8acbce46eede | 59 | } |
karpent | 0:8acbce46eede | 60 | |
karpent | 0:8acbce46eede | 61 | /// Read the scale from a potentiometer attached to analog pin |
karpent | 0:8acbce46eede | 62 | float Scale::ReadScale() |
karpent | 0:8acbce46eede | 63 | { |
karpent | 2:ef3093a7a43e | 64 | float scale = _scale; |
karpent | 2:ef3093a7a43e | 65 | |
karpent | 0:8acbce46eede | 66 | #ifdef ARDUINO |
karpent | 0:8acbce46eede | 67 | scale = analogRead(scalePin); |
karpent | 0:8acbce46eede | 68 | #else |
karpent | 0:8acbce46eede | 69 | scale = scaleRead; |
karpent | 0:8acbce46eede | 70 | #endif |
karpent | 0:8acbce46eede | 71 | |
karpent | 2:ef3093a7a43e | 72 | return _minScale + scale * (_maxScale - _minScale)/1024.f; |
karpent | 0:8acbce46eede | 73 | } |