我正在开发一个程序,该程序将使用 16 个模拟传感器读取距离。我刚来这个问题,比较一下,看看哪个是最大的。也许有一种方法或东西可以帮助我?如果没有,我该如何比较它们?我需要找到传感器的最大值以便以后使用。
请帮帮我,我在过去的两个小时里一直坚持这个。
这是代码:
#define a A0
#define b A1
#define c A2
#define d A3
#define e A4
#define f A5
#define g A6
#define h A7
#define i A8
#define j A9
#define k A10
#define l A11
#define m A12
#define n A13
#define o A14
#define p A15
int aState = 0;
int bState = 0;
int cState = 0;
int dState = 0;
int eState = 0;
int fState = 0;
int gState = 0;
int hState = 0;
int iState = 0;
int jState = 0;
int kState = 0;
int lState = 0;
int mState = 0;
int nState = 0;
int oState = 0;
int pState = 0;
void setup()
{
pinMode(a, INPUT);
pinMode(b, INPUT);
pinMode(c, INPUT);
pinMode(d, INPUT);
pinMode(e, INPUT);
pinMode(f, INPUT);
pinMode(g, INPUT);
pinMode(h, INPUT);
pinMode(i, INPUT);
pinMode(j, INPUT);
pinMode(k, INPUT);
pinMode(l, INPUT);
pinMode(m, INPUT);
pinMode(n, INPUT);
pinMode(o, INPUT);
pinMode(p, INPUT);
}
void loop()
{
int x[15];
x[0] = analogRead(a)/4;
x[1] = analogRead(b)/4;
x[2] = analogRead(c)/4;
x[3] = analogRead(d)/4;
x[4] = analogRead(e)/4;
x[5] = analogRead(f)/4;
x[6] = analogRead(g)/4;
x[7] = analogRead(h)/4;
x[8] = analogRead(i)/4;
x[9] = analogRead(j)/4;
x[10] = analogRead(k)/4;
x[11] = analogRead(l)/4;
x[12] = analogRead(m)/4;
x[13] = analogRead(n)/4;
x[14] = analogRead(o)/4;
x[15] = analogRead(p)/4;
}