Skip to content

Commit 79e93cd

Browse files
Rocketctfacchinm
authored andcommitted
added support for opto relay
1 parent 7f6142b commit 79e93cd

File tree

4 files changed

+1267
-1193
lines changed

4 files changed

+1267
-1193
lines changed
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <Modulino.h>
2+
3+
ModulinoRelay relay;
4+
5+
void setup() {
6+
Serial.begin(115200);
7+
Modulino.begin();
8+
relay.begin();
9+
10+
}
11+
void loop() {
12+
relay.on();
13+
if(relay.getStatus())
14+
{
15+
Serial.println("Relay state ON!");
16+
}
17+
delay(1000);
18+
relay.off();
19+
if(!(relay.getStatus()))
20+
{
21+
Serial.println("Relay state OFF!");
22+
}
23+
Serial.println();
24+
delay(1000);
25+
}

examples/Utilities/AddressChanger/AddressChanger.ino

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ String pinstrapToName(uint8_t pinstrap) {
3434
return "JOYSTICK";
3535
case 0x7C:
3636
return "BUTTONS";
37+
case 0x28:
38+
return "RELAY";
3739
case 0x76:
3840
case 0x74:
3941
return "ENCODER";

src/Modulino.h

+48-1
Original file line numberDiff line numberDiff line change
@@ -571,4 +571,51 @@ class ModulinoDistance : public Module {
571571
//VL53L4ED_ResultsData_t results;
572572
float internal = NAN;
573573
_distance_api* api = nullptr;
574-
};
574+
};
575+
576+
class ModulinoRelay : public Module {
577+
public:
578+
ModulinoRelay(uint8_t address = 0xFF)
579+
: Module(address, "RELAY") {}
580+
bool update() {
581+
uint8_t buf[3];
582+
auto res = read((uint8_t*)buf, 3);
583+
auto ret = res && (buf[0] != last_status[0] || buf[1] != last_status[1] || buf[2] != last_status[2]);
584+
last_status[0] = buf[0];
585+
last_status[1] = buf[1];
586+
last_status[2] = buf[2];
587+
return ret;
588+
}
589+
void on() {
590+
uint8_t buf[3];
591+
buf[0] = 1;
592+
buf[1] = 0;
593+
buf[2] = 0;
594+
write((uint8_t*)buf, 3);
595+
return;
596+
}
597+
void off() {
598+
uint8_t buf[3];
599+
buf[0] = 0;
600+
buf[1] = 0;
601+
buf[2] = 0;
602+
write((uint8_t*)buf, 3);
603+
return;
604+
}
605+
bool getStatus() {
606+
update();
607+
return last_status[0];
608+
}
609+
virtual uint8_t discover() {
610+
for (unsigned int i = 0; i < sizeof(match)/sizeof(match[0]); i++) {
611+
if (scan(match[i])) {
612+
return match[i];
613+
}
614+
}
615+
return 0xFF;
616+
}
617+
private:
618+
bool last_status[3];
619+
protected:
620+
uint8_t match[1] = { 0x28 }; // same as fw main.c
621+
};

0 commit comments

Comments
 (0)