On()


Description

This function turns the output ON.

Syntax

output.on()

Parameters

none

Returns

none

Example

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

byte spcId = 1;

ExpansionRelayOutput relay0(spcId, 0);
ExpansionRelayOutput relay1(spcId, 1);
ExpansionRelayOutput relay2(spcId, 2);
ExpansionRelayOutput relay3(spcId, 3);

void relayPrintState(void) {
    if(relay0.isOn())
        Serial.println("Relay 0 is ON");
    else
        Serial.println("Relay 0 is OFF");

    if(relay1.isOn())
        Serial.println("Relay 1 is ON");
    else
        Serial.println("Relay 1 is OFF");

    if(relay2.isOff())
        Serial.println("Relay 2 is OFF");
    else
        Serial.println("Relay 2 is ON");

    if(relay3.isOff())
        Serial.println("Relay 3 is OFF");
    else
        Serial.println("Relay 3 is ON");

    Serial.println();
}

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

    // begin PHPoC Shield or PHPoC WiFi Shield
    Phpoc.begin(PF_LOG_SPI | PF_LOG_NET);
    //Phpoc.begin();

    // begin expansion board
    Expansion.begin();

    // get name and print it to serial
    Serial.println(relay0.getName());
}

void loop() {
    // turn all relays on
    relay0.on();
    relay1.on();
    relay2.on();
    relay3.on();
    delay(1000);

    // get current state and pint to serial
    relayPrintState();

    // turn all relays off
    relay0.off();
    relay1.off();
    relay2.off();
    relay3.off();
    delay(1000);

    // get current state and pint to serial
    relayPrintState();
}