确认输出状态


示例

#include <Phpoc.h>
#include <PhpocExpansion.h>

byte spcId = 1;

ExpansionRelayOutput output0(spcId, 0);
ExpansionRelayOutput output1(spcId, 1);
ExpansionRelayOutput output2(spcId, 2);
ExpansionRelayOutput output3(spcId, 3);

void getOutputState() {
    if(output0.isOn())
        Serial.println("Port 0: 1");
    else
        Serial.println("Port 0: 0");

    if(output1.isOn())
        Serial.println("Port 1: 1");
    else
        Serial.println("Port 1: 0");

    if(output2.isOff())
        Serial.println("Port 2: 0");
    else
        Serial.println("Port 2: 1");

    if(output3.isOff())
        Serial.println("Port 3: 0");
    else
        Serial.println("Port 3: 1");
}

void setup() {
    Serial.begin(9600);
    while(!Serial)
        ;

    Phpoc.begin(PF_LOG_SPI | PF_LOG_NET);
    Expansion.begin();
}

void loop() {
    Serial.println("turn all output ports on");
    output0.on();
    output1.on();
    output2.on();
    output3.on();

    // get status of output ports
    getOutputState();

    delay(1000);

    Serial.println("turn all output ports off");
    output0.off();
    output1.off();
    output2.off();
    output3.off();

    // get status of output ports
    getOutputState();

    delay(1000);
}
turn all output ports on
Port 0: 1
Port 1: 1
Port 2: 1
Port 3: 1
turn all output ports off
Port 0: 0
Port 1: 0
Port 2: 0
Port 3: 0
...