老农新码 2023-06-10 10:11 采纳率: 0%
浏览 20

c语言遇问题,运行时遇到问题,求解

刚开始学习,遇问题,求解

img


#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEServer.h>
#include <BLE2902.h>

#define OLED_RESET -1
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"
BLECharacteristic *pCharacteristic;

#define TEMPERATURE_SENSOR_PIN 34
#define LED_PIN 2

void setup() {
  Serial.begin(9600);

  // 初始化 OLED 显示屏
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for (;;)
      ;
  }
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0, 0);

  // 初始化蓝牙
  BLEDevice::init("ESP32 BLE Server");
  BLEServer *pServer = BLEDevice::createServer();
  BLEService *pService = pServer->createService(SERVICE_UUID);
  pCharacteristic = pService->createCharacteristic(
    CHARACTERISTIC_UUID,
    BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_NOTIFY);
  pCharacteristic->addDescriptor(new BLE2902());
  pService->start();
  BLEAdvertising *pAdvertising = pServer->getAdvertising();
  pAdvertising->addServiceUUID(pService->getUUID());
  pAdvertising->setScanResponse(true);
  pAdvertising->setMinPreferred(0x0);
  pAdvertising->setMinPreferred(0x1);
  BLEDevice::startAdvertising();

  // 初始化温度传感器
  pinMode(LED_PIN, OUTPUT);
  pinMode(TEMPERATURE_SENSOR_PIN, INPUT);
}

void loop() {
  float temperature = readTemperature();
  display.clearDisplay();
  display.setCursor(0, 0);
  display.print("Temperature: ");
  display.print(temperature);
  display.print(" C");
  display.display();

  // 蓝牙传输数据
  String temperatureString = String(temperature);
  pCharacteristic->setValue(temperatureString.c_str());
  pCharacteristic->notify();

  delay(1000);
}

float readTemperature() {
  int sensorValue = analogRead(TEMPERATURE_SENSOR_PIN);
  float voltage
  • 写回答

3条回答 默认 最新

  • 创意程序员 2023-06-10 10:29
    关注

    Wire.h 这个文件没有,应该从哪来?

    评论

报告相同问题?

问题事件

  • 创建了问题 6月10日

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?