-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheWsh_balance.ino
87 lines (58 loc) · 1.66 KB
/
eWsh_balance.ino
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
Balance Emulator - (c) 2016 Online LIMS, Ricardo Timmermann
The 'Balance emulator' sent random weights around TARGEDREAD
with a tolerance of READERROR in %. Adjust this values to get
a desired weight.
Example: emulate a balance to read around 2 gr
#define TARGETREAD 200
#define READERROR 5
You must sent to the Arduino Balance "READ\n" to get data.
Similar on a read balance when you request a weight by pressing print.
Weight 1.9998 gr
Weight 2.0212 gr
Weight 1.8950 gr
Weight 2.1010 gr
Weight 2.0018 gr
...
*/
#define TARGETREAD 200
#define READERROR 5
// == initialize the device =====================
float fminRead;
float fmaxRead;
void setup()
{
Serial.begin(9600);
Serial.println("Device Started, (c) by Online LIMS");
fminRead = TARGETREAD - TARGETREAD*READERROR/100;
fmaxRead = TARGETREAD + TARGETREAD*READERROR/100;
Serial.print("read range ");
Serial.print(fminRead);
Serial.print(" - ");
Serial.println(fmaxRead);
randomSeed(42);
}
// == balance weihjt emulator =====================
float readData()
{
float fRead;
fRead = random(fminRead,fmaxRead);
fRead = fRead/100;
return fRead;
}
// == main loop ==================================
String sReadCmd;
void loop()
{
if( Serial.available() ) {
sReadCmd = Serial.readString();
//-- read only if READ string is requested (the read commando)
if( sReadCmd.equals("READ\n") ) {
float fRead = readData();
Serial.print( "Weigth ");
Serial.print(fRead);
Serial.println( " gr");
delay(500);
}
}
}