-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSDS011_Mock.ino
54 lines (42 loc) · 1.01 KB
/
SDS011_Mock.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
void setup() {
Serial.begin(9600);
}
void mock_sds011() {
int value = 0;
while (1) {
int pm_25 = value * 10;
int pm_10 = (value + 10) * 10;
unsigned char buffer[10];
unsigned char *bp = buffer;
*bp++ = 0xAA;
*bp++ = 0xC0;
*bp++ = pm_25 % 256;
*bp++ = pm_25 / 256;
*bp++ = pm_10 % 256;
*bp++ = pm_10 / 256;
*bp++ = 0x12;
*bp++ = 0x34;
unsigned int sum = buffer[2] + buffer[3] + buffer[4] + buffer[5] + buffer[6] + buffer[7];
*bp++ = sum % 256;
*bp++ = 0xAB;
Serial.write(buffer, 10);
Serial.flush();
delay(1000);
value += 10;
if (value > 2500) value = 0;
}
}
void hello() {
int value = 0;
while (1) {
Serial.print("Hello ");
Serial.println(value);
Serial.flush();
delay(1000);
value ++;
if (value > 9999) value = 0;
}
}
void loop() {
mock_sds011();
}