File tree 4 files changed +1267
-1193
lines changed
4 files changed +1267
-1193
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) {
34
34
return " JOYSTICK" ;
35
35
case 0x7C :
36
36
return " BUTTONS" ;
37
+ case 0x28 :
38
+ return " RELAY" ;
37
39
case 0x76 :
38
40
case 0x74 :
39
41
return " ENCODER" ;
Original file line number Diff line number Diff line change @@ -571,4 +571,51 @@ class ModulinoDistance : public Module {
571
571
// VL53L4ED_ResultsData_t results;
572
572
float internal = NAN;
573
573
_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
+ };
You can’t perform that action at this time.
0 commit comments