File tree Expand file tree Collapse file tree 4 files changed +1243
-1167
lines changed Expand file tree Collapse file tree 4 files changed +1243
-1167
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff 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" ;
Original file line number Diff line number Diff line change @@ -571,4 +571,53 @@ 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+
588+
589+ return ret;
590+ }
591+ void ON () {
592+ uint8_t buf[3 ];
593+ buf[0 ] = 1 ;
594+ buf[1 ] = 0 ;
595+ buf[2 ] = 0 ;
596+ write ((uint8_t *)buf, 3 );
597+ return ;
598+ }
599+ void OFF () {
600+ uint8_t buf[3 ];
601+ buf[0 ] = 0 ;
602+ buf[1 ] = 0 ;
603+ buf[2 ] = 0 ;
604+ write ((uint8_t *)buf, 3 );
605+ return ;
606+ }
607+ bool getStatus () {
608+ update ();
609+ return last_status[0 ];
610+ }
611+ virtual uint8_t discover () {
612+ for (unsigned int i = 0 ; i < sizeof (match)/sizeof (match[0 ]); i++) {
613+ if (scan (match[i])) {
614+ return match[i];
615+ }
616+ }
617+ return 0xFF ;
618+ }
619+ private:
620+ bool last_status[3 ];
621+ protected:
622+ uint8_t match[1 ] = { 0x28 }; // same as fw main.c
623+ };
You can’t perform that action at this time.
0 commit comments