Example of using "Canvas" form "Graphics" library to display 3D graphics.

Dependencies:   BSP_DISCO_F746NG Graphics mbed

HardwareAccess/Scale.cpp

Committer:
karpent
Date:
2016-11-06
Revision:
0:8acbce46eede
Child:
2:ef3093a7a43e

File content as of revision 0:8acbce46eede:

//
//  Scale.cpp
//

#include "Scale.h"
#include "mbed.h"   // for AnalogIn

#ifdef ARDUINO 
int scalePin = 1;
#else
AnalogIn scaleRead(A1);
#endif

Scale::Scale()
{
    Setup(1.f, 0.4f, 1.f, 8.f);
}

Scale::Scale(float min, float max)
{
    Setup(1.f, 0.4f, min, max);
}

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;

    if(scale > maxScale)
        delta *= -1.f;

    if(scale < minScale)
        delta *= -1.f;

    return scale;
}

/// Read the scale from a potentiometer attached to analog pin
float Scale::ReadScale()
{
#ifdef ARDUINO
    scale = analogRead(scalePin);
#else
    scale = scaleRead;
#endif

    return minScale + scale * (maxScale - minScale)/1024.f;
}