【发布时间】:2020-05-18 15:29:36
【问题描述】:
我想从传感器获取数据(我使用了 velostat)。这是我的代码。
Arduino 代码
#define numRows 1
#define numCols 1
int rows_out = 13;
int cols_in = 12;
int Values = 0;
void setup() {
// set all rows and columns to INPUT (high impedance):
pinMode(rows_out, INPUT_PULLUP);
pinMode(cols_in, INPUT);
Serial.begin(9600);
}
void loop() {
pinMode(cols_in, OUTPUT); // set as OUTPUT
digitalWrite(cols_in, LOW); // set LOW
Values = analogRead(rows_out); // read INPUT
pinMode(cols_in, INPUT); // set back to INPUT!
// Print the incoming values of the grid:
Serial.println(Values);
delay(1000);
}
我用 velostat 制作了一个传感器。它有两条电缆。 我将其中一个与 arduino 板的模拟引脚连接起来。另一个带有 GND 和其他模拟引脚。像这样。
velostat 电缆 1 - 模拟针 12
velostat 电缆 2 - 模拟引脚 13 - GND
但是当我上传这个程序时,奇怪的数据出现在串行监视器上。
串行监视器上显示的数据
4095
4095
4075
3283
3082
3056
2973
2941
2865
2685
2308
1859
1365
如果有人知道原因,请帮助我。我猜是因为电缆连接有问题或者我连接了错误的引脚,但我不确定。
【问题讨论】:
-
Velostat 基本上是一个电阻器,它的电阻会随着施加的压力而变化。所以你需要通过在 Velostat 和 5v 之间连接一个电阻来形成一个分压器,Velostate 的另一端只需连接到 GND。如果您理解这一点,那么您的代码根本没有任何意义。