1

我想和我的 Arduino 交流。我安装了 Arduino IDE,如果我使用它,一切正常。这是我的草图:

const int ledPin = 11; // the pin that the LED is attached to

void setup() {
  // initialize the serial communication:
  Serial.begin(9600);
  // initialize the ledPin as an output:
  pinMode(ledPin, OUTPUT);
}

void loop() {
  byte brightness;
  // check if data has been sent from the computer:
  if (Serial.available()) {
    // read the most recent byte (which will be from 0 to 255):
    brightness = (Serial.read()-48)*28;
    // set the brightness of the LED:
    analogWrite(ledPin, brightness);
    Serial.println(brightness);
  }
}

如果我现在启动串行监视器并输入“9”,我会得到一个 252,并且 LED 会跳到全亮度。如果你输入“0”,LED 就会熄灭!

这就是我想在 Lua 中重新创建的内容。我下载了rs232,然后我写了这个脚本:

local rs232 = require "rs232"

local e, p = rs232.open('/dev/ttyACM0',{
  baud         = '_9600';
  data_bits    = '_8';
  parity       = 'NONE';
  stop_bits    = '_1';
  flow_control = 'OFF';
  rts          = 'ON';
})

input=io.read()
p:write(input)
print(p:read(1))
p:close()

但什么也没有发生。即使没有这个p.read()部分。

请帮忙。

PS:我的系统是Linux CentOS 7,板子是Uno

4

0 回答 0