按钮增量而不是高/低的Arduino数据值

时间:2018-06-25 12:19:23

标签: arduino

我还发布了这个问题here

我正在连接MUX74HC4067并读取每个引脚的值。所有值一起增加,直到达到227,然后重新开始。我不确定是什么问题,我稍后再设置引脚,因为当它们全部正常工作时,我最终将从ini文件中检索这些引脚以配置电路板。

串行监视器输出以下内容作为简短示例:

Push button at channel 0 is 197
Push button at channel 1 is 197
Push button at channel 2 is 197
Push button at channel 3 is 197
Push button at channel 4 is 197
Push button at channel 5 is 197
Push button at channel 6 is 197
Push button at channel 7 is 197
Push button at channel 8 is 197
Push button at channel 9 is 197
Push button at channel 10 is 197
Push button at channel 11 is 197
Push button at channel 12 is 197
Push button at channel 13 is 197
Push button at channel 14 is 197
Push button at channel 15 is 197

Push button at channel 0 is 227
Push button at channel 1 is 227
Push button at channel 2 is 227
Push button at channel 3 is 227
Push button at channel 4 is 227
Push button at channel 5 is 227
Push button at channel 6 is 227
Push button at channel 7 is 227
Push button at channel 8 is 227
Push button at channel 9 is 227
Push button at channel 10 is 227
Push button at channel 11 is 227
Push button at channel 12 is 227
Push button at channel 13 is 227
Push button at channel 14 is 227
Push button at channel 15 is 227
#include "MUX74HC4067.h"

// Creates a MUX74HC4067 instance
// 1st argument is the Arduino PIN to which the EN pin connects
// 2nd-5th arguments are the Arduino PINs to which the S0-S3 pins connect

MUX74HC4067 *pmux1 = NULL;

void setup()
{
MUX74HC4067 pmux1(22,23,24,25,26);

Serial.begin(9600);  // Initializes serial port
 // Waits for serial port to connect. Needed for Leonardo only
while ( !Serial ) ;

// Configures how the SIG pin will be interfaced
// e.g. The SIG pin connects to PIN 3 on the Arduino,
//      and PIN 3 is a digital input
//  mux1.signalPin(27, INPUT, DIGITAL);
 pmux1.signalPin(27, INPUT, DIGITAL);
}

// Reads the 16 channels and reports on the serial monitor
// if the corresponding push button is pressed
void loop()
{
 byte data;

for (byte i = 0; i < 16; ++i)
{
    // Reads from channel i and returns HIGH or LOW
data = pmux1->read(i);


    Serial.print("Push button at channel ");
    Serial.print(i);
    Serial.print(" is ");
   Serial.println(data);
    if ( data == HIGH ) Serial.println("not pressed");
    else if ( data == LOW ) Serial.println("pressed");
}
Serial.println();

delay(1500);
}

这是指向library mux的链接。

这行代码检索值,并在本教程中:

 data = mux1.read(i);

工作正常。

我更改为以下内容,因为所有工作时都将从INI文件中设置引脚。

data = pmux1->read(i);

我也无所适从,因为它们也检索值,所以它们是HIGH或LOW。

0 个答案:

没有答案