我的 ESP8266 Lolin32 有一个奇怪的问题。我尝试制作一个从光传感器获得价值并建立 WiFi 连接的项目。我可以正确显示值,但是当我添加 Wifi 连接时,光传感器总是显示 4095,即使光传感器被隐藏也永远不会改变。这是一些代码
#include <WiFiUdp.h>
#include <ETH.h>
#include <WiFiSTA.h>
#include <WiFiMulti.h>
#include <WiFiType.h>
#include <WiFiServer.h>
#include <WiFiClient.h>
#include <WiFiScan.h>
#include <WiFiAP.h>
#include <WiFiGeneric.h>
#include <WiFi.h>
int photocellPin = 14;
int photocellReading;
const char* ssid = "ssid";
const char* password = "pass";
void setup() {
Serial.begin(9600);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.print("Connecting\n");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print("Waiting for connection...\n");
}
Serial.println();
//configTime(3 * 3600, 0, "pool.ntp.org", "time.nist.gov");
Serial.print("Connected, IP address: \n");
Serial.println(WiFi.localIP());
}
void loop() {
photocellReading = analogRead(photocellPin);
Serial.print("Analog reading = ");
Serial.print(photocellReading); // the raw analog reading
// We'll have a few threshholds, qualitatively determined
if (photocellReading < 10) {
Serial.println(" - Black");
} else if (photocellReading < 200) {
Serial.println(" - Dark");
} else if (photocellReading < 500) {
Serial.println(" - Light");
} else if (photocellReading < 800) {
Serial.println(" - Light +");
} else {
Serial.println(" - Light ++");
}
delay(50);
}
总是显示 4095 - Light ++