Kristof T'Jonck / Mbed 2 deprecated CYS_Receiver

Dependencies:   xtoff2 RF24Network mbed

Fork of xtoff3 by pieter Berteloot

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LoadCell.cpp Source File

LoadCell.cpp

00001 #include "LoadCell.h"
00002 
00003 LoadCell::LoadCell(PinName pin): ain(pin)
00004 {
00005     SAMPLE_AMOUNT = 2000;
00006     CALIBRATION_MASS = 843.56; // 274.19
00007     TARE_VALUE = 0.743027;
00008     CALIBRATION_VALUE = 0.725960;
00009     OFFSET = TARE_VALUE-CALIBRATION_VALUE;
00010     DOWN_OFFSET = 0.023591;
00011 };
00012 
00013 
00014 float LoadCell::analogRead()
00015 {
00016     float samples [SAMPLE_AMOUNT];
00017     for(int i = 0; i < SAMPLE_AMOUNT; i++) {
00018         float read =ain.read();
00019         samples [i] =read;
00020     }
00021     return Maths::mean(samples,0,SAMPLE_AMOUNT);
00022 }
00023 
00024 float LoadCell::simpleAnalogRead()
00025 {
00026     return ain.read();
00027 }
00028 
00029 float LoadCell::calculateMass(float value)
00030 {
00031     return ((TARE_VALUE - value)*(CALIBRATION_MASS))/(OFFSET);
00032 }
00033 
00034 
00035 float LoadCell::tare()
00036 {
00037     TARE_VALUE = 0;
00038     float values[20];
00039     for (int a = 0; a<20; a++) {
00040         values[a] = analogRead();
00041     }
00042 
00043     TARE_VALUE = Maths::mean(values,0,20);
00044     return TARE_VALUE;
00045 }
00046 
00047 float LoadCell::tareDown()
00048 {
00049     TARE_VALUE = 0;
00050     float values[20];
00051     for (int a = 0; a<20; a++) {
00052         values[a] = analogRead();
00053     }
00054 
00055     TARE_VALUE = Maths::mean(values,0,20)- DOWN_OFFSET;
00056     return TARE_VALUE;
00057 }
00058 
00059 float LoadCell::callibrate()
00060 {
00061     CALIBRATION_VALUE = analogRead();
00062     return CALIBRATION_VALUE;
00063 }
00064 
00065 
00066 float LoadCell::mass()
00067 {
00068     return calculateMass(analogRead());
00069 }
00070 
00071 float LoadCell::simpleMass()
00072 {
00073     return calculateMass(simpleAnalogRead());
00074 }
00075 
00076 
00077 void LoadCell::setCalibrationMass(int mass)
00078 {
00079     CALIBRATION_MASS = mass;
00080 }
00081 
00082 void LoadCell::setSampleAmount(int samples)
00083 {
00084     SAMPLE_AMOUNT = samples;
00085 }
00086 
00087