Skip to content

Commit be3ffaa

Browse files
committed
Fix SwitchMote PIR sketch
1 parent 2537b74 commit be3ffaa

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

Examples/SwitchMote/SwitchMote_withPIR.ino

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,15 @@
6565
#define PIR_LED_ON 3000
6666
#endif
6767
// **********************************************************************************
68-
#define LED_RM 15 //digital pin for MIDDLE RED LED
69-
#define LED_GM 18 //digital pin for MIDDLE GREEN LED
68+
#define BTNCOUNT 2 //1 or 3 (2 also possible)
69+
#define BTNT 6 //digital pin of top button
70+
#define BTNB 4 //digital pin of bottom button
71+
7072
#define LED_RT 16 //digital pin for TOP RED LED
7173
#define LED_GT 19 //digital pin for TOP GREEN LED
7274
#define LED_RM 15 //digital pin for MIDDLE RED LED
75+
//#define LED_GM 18 //digital pin for MIDDLE GREEN LED
76+
#define LED_RM 15 //digital pin for MIDDLE RED LED
7377
#define LED_RB 14 //digital pin for BOTTOM RED LED
7478
#define LED_GB 17 //digital pin for BOTTOM GREEN LE
7579

@@ -78,11 +82,6 @@
7882
#define RELAY1_INDEX 0 //index in btn[] array which is associated with the MAIN relay
7983
#define RELAY2_INDEX 1 //index in btn[] array which is associated with the secondary relay (SwitchMote 2x10A only)
8084

81-
#define BTNCOUNT 2 //1 or 3 (2 also possible)
82-
#define BTNM 5 //digital pin of middle button
83-
#define BTNT 6 //digital pin of top button
84-
#define BTNB 4 //digital pin of bottom button
85-
8685
#define BUTTON_BOUNCE_MS 200 //timespan before another button change can occur
8786
#define SYNC_ENTER 3000 //time required to hold a button before SwitchMote enters [SYNC mode]
8887
#define SYNC_TIME 20000 //max time spent in SYNC mode before returning to normal operation (you got this much time to SYNC 2 SMs, increase if need more time to walk)
@@ -154,11 +153,11 @@ unsigned long syncStart=0;
154153
unsigned long now=0;
155154
byte btnIndex=0; // as the sketch loops this index will loop through the available physical buttons
156155
byte mode[] = {ON,ON,ON}; //could use single bytes for efficiency but keeping it separate for clarity
157-
byte btn[] = {BTNT, BTNM, BTNB};
156+
byte btn[] = {BTNT, BTNB};
158157
byte btnLastState[]={RELEASED,RELEASED,RELEASED};
159158
unsigned long btnLastPress[]={0,0,0};
160-
byte btnLEDRED[] = {LED_RT, LED_RM, LED_RB};
161-
byte btnLEDGRN[] = {LED_GT, LED_GM, LED_GB};
159+
byte btnLEDRED[] = {LED_RT, LED_RB};
160+
byte btnLEDGRN[] = {LED_GT, LED_GB};
162161
uint32_t lastSYNC=0; //remember last status change - used to detect & stop loop conditions in circular SYNC scenarios
163162
char * buff="justAnEmptyString";
164163

@@ -193,16 +192,14 @@ void setup(void)
193192
radio.enableAutoPower(ATC_RSSI);
194193
DEBUGln(F("\r\nRFM69_ATC Enabled (Auto Transmission Control)"));
195194
#endif
196-
197-
198195

199-
pinMode(LED_RM, OUTPUT);pinMode(LED_GM, OUTPUT);
196+
pinMode(LED_RM, OUTPUT);//pinMode(LED_GM, OUTPUT);
200197
pinMode(LED_RT, OUTPUT);pinMode(LED_GT, OUTPUT);
201198
pinMode(LED_RB, OUTPUT);pinMode(LED_GB, OUTPUT);
202199
// by writing HIGH while in INPUT mode, the internal pullup is activated
203200
// the button will read 1 when RELEASED (because of the pullup)
204201
// the button will read 0 when PRESSED (because it's shorted to GND)
205-
pinMode(BTNM, INPUT);digitalWrite(BTNM, HIGH); //activate pullup
202+
//pinMode(BTNM, INPUT);digitalWrite(BTNM, HIGH); //activate pullup
206203
pinMode(BTNT, INPUT);digitalWrite(BTNT, HIGH); //activate pullup
207204
pinMode(BTNB, INPUT);digitalWrite(BTNB, HIGH); //activate pullup
208205
pinMode(RELAY1, OUTPUT);
@@ -441,7 +438,8 @@ void action(byte whichButtonIndex, byte whatMode, boolean notifyGateway)
441438
DEBUG(F("]:D"));
442439
DEBUG(btn[whichButtonIndex]);
443440
DEBUG(F(" - "));
444-
DEBUG(btn[whichButtonIndex]==BTNT?F("TOP: "):btn[whichButtonIndex]==BTNM?F("MAIN: "):btn[whichButtonIndex]==BTNB?F("BOTTOM: "):F("UNKNOWN"));
441+
//DEBUG(btn[whichButtonIndex]==BTNT?F("TOP: "):btn[whichButtonIndex]==BTNM?F("MAIN: "):btn[whichButtonIndex]==BTNB?F("BOTTOM: "):F("UNKNOWN"));
442+
DEBUG(btn[whichButtonIndex]==BTNT?F("TOP: "):btn[whichButtonIndex]==BTNB?F("BOTTOM: "):F("UNKNOWN"));
445443
DEBUG(whatMode==ON?F("ON "):F("OFF"));
446444

447445
mode[whichButtonIndex] = whatMode;

0 commit comments

Comments
 (0)