Example of using "Canvas" form "Graphics" library to display 3D graphics.
Dependencies: BSP_DISCO_F746NG Graphics mbed
HardwareAccess/Scale.cpp@0:8acbce46eede, 2016-11-06 (annotated)
- Committer:
- karpent
- Date:
- Sun Nov 06 02:14:34 2016 +0000
- Revision:
- 0:8acbce46eede
- Child:
- 2:ef3093a7a43e
Initial revision with square 3D model.
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 | 0:8acbce46eede | 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 | 0:8acbce46eede | 16 | Setup(1.f, 0.4f, 1.f, 8.f); |
karpent | 0:8acbce46eede | 17 | } |
karpent | 0:8acbce46eede | 18 | |
karpent | 0:8acbce46eede | 19 | Scale::Scale(float min, float max) |
karpent | 0:8acbce46eede | 20 | { |
karpent | 0:8acbce46eede | 21 | Setup(1.f, 0.4f, min, max); |
karpent | 0:8acbce46eede | 22 | } |
karpent | 0:8acbce46eede | 23 | |
karpent | 0:8acbce46eede | 24 | void Scale::Setup(float scale, float delts, float min, float max) |
karpent | 0:8acbce46eede | 25 | { |
karpent | 0:8acbce46eede | 26 | scale = scale; |
karpent | 0:8acbce46eede | 27 | delta = delta; |
karpent | 0:8acbce46eede | 28 | minScale = min; |
karpent | 0:8acbce46eede | 29 | maxScale = max; |
karpent | 0:8acbce46eede | 30 | } |
karpent | 0:8acbce46eede | 31 | |
karpent | 0:8acbce46eede | 32 | // Simulate scale changing |
karpent | 0:8acbce46eede | 33 | float Scale::GetScale() |
karpent | 0:8acbce46eede | 34 | { |
karpent | 0:8acbce46eede | 35 | scale += delta; |
karpent | 0:8acbce46eede | 36 | |
karpent | 0:8acbce46eede | 37 | if(scale > maxScale) |
karpent | 0:8acbce46eede | 38 | delta *= -1.f; |
karpent | 0:8acbce46eede | 39 | |
karpent | 0:8acbce46eede | 40 | if(scale < minScale) |
karpent | 0:8acbce46eede | 41 | delta *= -1.f; |
karpent | 0:8acbce46eede | 42 | |
karpent | 0:8acbce46eede | 43 | return scale; |
karpent | 0:8acbce46eede | 44 | } |
karpent | 0:8acbce46eede | 45 | |
karpent | 0:8acbce46eede | 46 | /// Read the scale from a potentiometer attached to analog pin |
karpent | 0:8acbce46eede | 47 | float Scale::ReadScale() |
karpent | 0:8acbce46eede | 48 | { |
karpent | 0:8acbce46eede | 49 | #ifdef ARDUINO |
karpent | 0:8acbce46eede | 50 | scale = analogRead(scalePin); |
karpent | 0:8acbce46eede | 51 | #else |
karpent | 0:8acbce46eede | 52 | scale = scaleRead; |
karpent | 0:8acbce46eede | 53 | #endif |
karpent | 0:8acbce46eede | 54 | |
karpent | 0:8acbce46eede | 55 | return minScale + scale * (maxScale - minScale)/1024.f; |
karpent | 0:8acbce46eede | 56 | } |