Skip to content

added support for opto relay #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions examples/Modulino_Relay/Basic/Basic.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <Modulino.h>

ModulinoRelay relay;

void setup() {
Serial.begin(115200);
Modulino.begin();
relay.begin();

}
void loop() {
relay.ON();
if(relay.getStatus())
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As new name this could be "isRelayOn()" instead of "getStatus()"?

{
Serial.println("Relay state ON!");
}
delay(1000);
relay.OFF();
if(!(relay.getStatus()))
{
Serial.println("Relay state OFF!");
}
Serial.println();
delay(1000);
}
2 changes: 2 additions & 0 deletions examples/Utilities/AddressChanger/AddressChanger.ino
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ String pinstrapToName(uint8_t pinstrap) {
return "JOYSTICK";
case 0x7C:
return "BUTTONS";
case 0x28:
return "RELAY";
case 0x76:
case 0x74:
return "ENCODER";
Expand Down
51 changes: 50 additions & 1 deletion src/Modulino.h
Original file line number Diff line number Diff line change
Expand Up @@ -571,4 +571,53 @@ class ModulinoDistance : public Module {
//VL53L4ED_ResultsData_t results;
float internal = NAN;
_distance_api* api = nullptr;
};
};

class ModulinoRelay : public Module {
public:
ModulinoRelay(uint8_t address = 0xFF)
: Module(address, "RELAY") {}
bool update() {
uint8_t buf[3];
auto res = read((uint8_t*)buf, 3);
auto ret = res && (buf[0] != last_status[0] || buf[1] != last_status[1] || buf[2] != last_status[2]);
last_status[0] = buf[0];
last_status[1] = buf[1];
last_status[2] = buf[2];


return ret;
}
void ON() {
uint8_t buf[3];
buf[0] = 1;
buf[1] = 0;
buf[2] = 0;
write((uint8_t*)buf, 3);
return;
}
void OFF() {
uint8_t buf[3];
buf[0] = 0;
buf[1] = 0;
buf[2] = 0;
write((uint8_t*)buf, 3);
return;
}
bool getStatus() {
update();
return last_status[0];
}
virtual uint8_t discover() {
for (unsigned int i = 0; i < sizeof(match)/sizeof(match[0]); i++) {
if (scan(match[i])) {
return match[i];
}
}
return 0xFF;
}
private:
bool last_status[3];
protected:
uint8_t match[1] = { 0x28 }; // same as fw main.c
};
Loading
Loading