-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
69 lines (55 loc) · 1.18 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include "timing.h"
#include "uart.h"
#include "HX711_ADC.h"
void init(void)
{
uart::init();
timing::init();
sei(); // re-enable interrupts
}
int main(void)
{
float mass_measured = 0;
char outbuf[16];
char* inbuf;
uint32_t timestamp = 0;
init();
HX711_ADC hx;
hx.begin(128); // gain
hx.start(1000, true); // stabilizing time, tare
float calibrationValue = 2250.;
if (!hx.getTareTimeoutFlag()) hx.setCalFactor(calibrationValue);
while (true)
{
if (hx.update())
{
mass_measured = hx.getData();
// print CSV data: timestamp, mass measured, debug
sprintf(outbuf, "%lu, ", timestamp++);
uart::putstring(outbuf, false);
uart::putfloat(mass_measured);
uart::putch('\n');
_delay_ms(1000);
}
// handle incoming commands: t, m xxx.xxx
inbuf = uart::getstring();
if (inbuf[0] == 't')
{
hx.tareNoDelay();
}
else if (inbuf[0] == 'm')
{
hx.getNewCalibration(atof(&inbuf[2]));
}
//uart::putstring(inbuf, true);
//if (hx.getTareStatus())
// uart::putstring((char*) "Tare complete", true);
}
}