/* AXA2902_CONTROL - An Arduino sketch to demonstrate all the different ways of controlling the Axa Remote Window Winder with the HOME-LINBUS Translator Shield. Created by Peter, 2015 V 1.00 This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include // constants won't change. Used here to // set pin numbers: const int ledPin = 13; // the number of the LED pin #define AXA2902_STATUS 2 #define AXA2902_STATUS_REQ 3 #define AXA2902_OPEN_CMD 4 #define AXA2902_STOP_CMD 5 #define AXA2902_CLOSE_CMD 6 #define WindowStatusOpen 0 #define WindowStatusClosed 1 boolean WindowStatus; unsigned char TimeOutCnt; void OpenWindowCmd() { digitalWrite(AXA2902_OPEN_CMD,LOW); delay(30); // waits 30mseconds digitalWrite(AXA2902_OPEN_CMD,HIGH); } void StopWindowCmd() { digitalWrite(AXA2902_STOP_CMD,LOW); delay(30); // waits 30mseconds digitalWrite(AXA2902_STOP_CMD,HIGH); } void CloseWindowCmd() { digitalWrite(AXA2902_CLOSE_CMD,LOW); delay(30); // waits 30mseconds digitalWrite(AXA2902_CLOSE_CMD,HIGH); } byte GetWindowStatusCmd() { digitalWrite(AXA2902_STATUS_REQ,LOW); delay(30); // waits 30mseconds digitalWrite(AXA2902_STATUS_REQ,HIGH); delay(80); // waits 80mseconds return digitalRead(AXA2902_STATUS); } void setup() { pinMode(ledPin, OUTPUT); pinMode(AXA2902_OPEN_CMD, OUTPUT); pinMode(AXA2902_STOP_CMD, OUTPUT); pinMode(AXA2902_CLOSE_CMD, OUTPUT); pinMode(AXA2902_STATUS_REQ, OUTPUT); pinMode(AXA2902_STATUS, INPUT); digitalWrite(AXA2902_OPEN_CMD, HIGH); digitalWrite(AXA2902_STOP_CMD, HIGH); digitalWrite(AXA2902_CLOSE_CMD, HIGH); digitalWrite(AXA2902_STATUS_REQ, HIGH); delay(300); // waits 300mseconds // Check current window status if(GetWindowStatusCmd() == WindowStatusClosed) { digitalWrite(ledPin, LOW); WindowStatus = WindowStatusClosed; } else { digitalWrite(ledPin, HIGH); WindowStatus = WindowStatusOpen; OpenWindowCmd(); delay(10000); // waits for 10 seconds } delay(500); // waits for 500mseconds } void loop() { // if closed we will open the window completely. if(WindowStatus==WindowStatusClosed) { OpenWindowCmd(); do { delay(500); // waits for half a second } while (GetWindowStatusCmd()!= WindowStatusOpen); digitalWrite(ledPin, HIGH); WindowStatus = WindowStatusOpen; delay(45000); // waits for 45 seconds to open completely !. // waiting XX seconds means you open the window partly, for example: 25 seconds is about 50% !. // exit if we completely opened the window. } // if opened we will close the window completely. if(WindowStatus==WindowStatusOpen) { CloseWindowCmd(); TimeOutCnt = 80; do { delay(500); // waits for half a second if(TimeOutCnt) TimeOutCnt--; else { OpenWindowCmd(); // Timeout happens only if the Window Winder is restarted and not closing. delay(45000); // waits for 45 seconds to open completely !. CloseWindowCmd(); TimeOutCnt = 80; } } while (GetWindowStatusCmd()!= WindowStatusClosed); digitalWrite(ledPin, LOW); WindowStatus = WindowStatusClosed; // exit if we completely closed the window. } delay(5000); // waits for 5 seconds }