首页 > 解决方案 > Lua ESP8266 脚本期待额外 =

问题描述

我正在尝试用我的 ESP8266 测试接近传感器,但是我使用的测试代码一直失败。每当我运行代码时,都会出现错误:motion sensor.lua:1: '=' expected near 'int'

我还应该提到我正在使用 ESPlorer v0.2.0

const int PIRSensorOutPin = 2;    //PIR Sensor OUT Pin
void setup() {
   Serial.begin(9600);
  pinMode(PIRSensorOutPin, INPUT);
}
void loop()
{
    if (digitalRead(PIRSensorOutPin) == LOW)
    {
       Serial.println("Person detected!");    //Print to serial monitor
    }
    else {;}
 }

我究竟做错了什么?

标签: luasyntax-erroresp8266esplorer

解决方案


Lua 解释器不理解 C++。

您正在运行运行 Lua 文件的 NodeMCU 固件。但是您正在尝试运行 Arduino C++ 代码。那是行不通的。要运行此代码,您必须将 ESP8266 支持添加到您的 Arduino IDE,编译您的代码并将其闪存到 ESP。

或者在 Lua 中编写代码。

https://github.com/esp8266/Arduino

https://www.nodemcu.com/index_en.html


推荐阅读