Lua ESP8266脚本需要额外的=

问题描述 投票:-2回答:2

我正在尝试使用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 {;}
 }

我在做什么错?

lua syntax-error esp8266 esplorer
2个回答
0
投票

Lua解释器不了解C ++。

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

或者用Lua编写代码。

https://github.com/esp8266/Arduino

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


0
投票

我在做什么错?

使用错误的编程语言。

NodeMCU想要运行Lua代码,而您却给了它C代码,这是行不通的。

我该如何解决? (暗示)

您可以使用arduino IDE来为ESP8266编写C ++代码,但是由于您似乎已经设置好了一切来运行Lua代码,因此建议您改用它。

您提供的C代码可以使用Lua API重写为NodeMCU

local pin = 2 -- The number of the I/O Pin
local type = "down" -- Trigger on falling edge

-- https://nodemcu.readthedocs.io/en/master/modules/gpio/#gpiotrig
gpio.trig(pin, type, function()
   print("Movement detected, proceding to exterminate!")
end)
© www.soinside.com 2019 - 2024. All rights reserved.