Управление портами вывода
Пример: On/Off
- исходный код для Arduino:
#include <PhpocExpansion.h>
#include <Phpoc.h>
byte spcId = 1;
ExpansionRelayOutput output0(spcId, 0);
ExpansionRelayOutput output1(spcId, 1);
ExpansionRelayOutput output2(spcId, 2);
ExpansionRelayOutput output3(spcId, 3);
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();
delay(1000);
Serial.println("turn all output ports off");
output0.off();
output1.off();
output2.off();
output3.off();
delay(1000);
}
turn all output ports on
turn all output ports off
...
Пример : Задержка On/Off
- исходный код для скетча Arduino
#include <PhpocExpansion.h>
#include <Phpoc.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.print("Port 0: 1, ");
else
Serial.print("Port 0: 0, ");
if(output1.isOn())
Serial.print("Port 1: 1, ");
else
Serial.print("Port 1: 0, ");
if(output2.isOff())
Serial.print("Port 2: 0, ");
else
Serial.print("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();
output0.setDelay(100);
output1.setDelay(100);
output2.setDelay(100);
output3.setDelay(100);
}
void loop() {
Serial.println("turn all output ports on");
output0.on();
output1.on();
output2.on();
output3.on();
// get status of output ports
getOutputState();
delay(110);
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(110);
getOutputState();
delay(1000);
}
- результат вывода:
turn all output ports on
Port 0: 0, Port 1: 0, Port 2: 0, Port 3: 0
Port 0: 1, Port 1: 1, Port 2: 1, Port 3: 1
turn all output ports off
Port 0: 1, Port 1: 1, Port 2: 1, Port 3: 1
Port 0: 0, Port 1: 0, Port 2: 0, Port 3: 0
...