Beetle树莓派RP2350代码篇五稿
#include <Wire.h>#include <Adafruit_SSD1306.h>
#include <SoftwareSerial.h>
#define OLED_WIDTH 128
#define OLED_HEIGHT 64
#define OLED_ADDR 0x3C
SoftwareSerial hrSerial(18, 19); // RX=18, TX未用
Adafruit_SSD1306 oled(OLED_WIDTH, OLED_HEIGHT, &Wire, -1);
int bpm = 0;
void setup() {
Serial.begin(9600);
hrSerial.begin(9600); // 波特率需与传感器匹配
// 初始化OLED
if (!oled.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR)) {
Serial.println("OLED初始化失败");
while (1);
}
oled.clearDisplay();
oled.setTextSize(1);
oled.setTextColor(SSD1306_WHITE);
oled.display();
}
void loop() {
// 读取心率传感器数据
if (hrSerial.available()) {
String data = hrSerial.readStringUntil('\n');
parseBPM(data); // 解析BPM值
updateDisplay(); // 刷新OLED
}
}
void parseBPM(String data) {
// 假设数据格式为"BPM:72"
int startIdx = data.indexOf("BPM:");
if (startIdx != -1) {
String valStr = data.substring(startIdx + 4);
bpm = valStr.toInt();
}
}
void updateDisplay() {
oled.clearDisplay();
oled.setCursor(0, 0);
oled.print("心率监测");
oled.setCursor(0, 20);
oled.print("BPM: ");
oled.print(bpm);
oled.display();
}
期待完整版本
https://vk.com/topic-231146152_54152380
https://vk.com/topic-231170993_53695523
https://vk.com/topic-231110257_54422666
https://vk.com/topic-231194230_54453896
https://vk.com/topic-231194219_53950136
https://vk.com/topic-231194205_53347441
https://vk.com/topic-231193594_53423516
https://vk.com/topic-231193578_53878088
https://vk.com/topic-231193557_54422669
https://vk.com/topic-230867560_54440880
https://vk.com/topic-230748866_53694744
https://vk.com/topic-230908148_53864442
https://vk.com/topic-230893050_54439511
https://vk.com/topic-231010955_53333210
https://vk.com/topic-230756102_54135632
https://vk.com/topic-230775817_54403496
https://vk.com/topic-231084979_53930693
https://vk.com/topic-231084960_54434760
https://vk.com/topic-231084940_54434347
https://vk.com/topic-231193643_53696000
https://vk.com/topic-231193632_54152002
https://vk.com/topic-231193616_53708240
https://vk.com/topic-231010333_53682529
https://vk.com/topic-230893543_53682304
https://vk.com/topic-230908408_53864444
https://vk.com/topic-231009291_54792863
https://vk.com/topic-231010847_54406826
https://vk.com/topic-230755562_54136551
https://vk.com/topic-230775922_54134442
https://vk.com/topic-231085239_53930696
https://vk.com/topic-231085229_53930467
https://vk.com/topic-231085214_53405089
https://vk.com/topic-231193731_54807325
https://vk.com/topic-231193720_54453482
https://vk.com/topic-231193668_53877700
https://vk.com/topic-229745654_53411007
https://vk.com/topic-230869875_53334522
https://vk.com/topic-230755466_53694488
https://vk.com/topic-230894236_53693742
https://vk.com/topic-230908680_54439260
https://vk.com/topic-230759283_53679402
https://vk.com/topic-230776028_53859881
https://vk.com/topic-231085670_54435077
https://vk.com/topic-231085661_54788254
https://vk.com/topic-231085452_54133492
https://vk.com/topic-231193774_53423522
https://vk.com/topic-231193765_53347680
https://vk.com/topic-231193752_54151736
https://vk.com/topic-230894711_54794055
https://vk.com/topic-230908992_54139323
页:
[1]