Browse Source

Upload files to ''

master
cs151003 5 years ago
parent
commit
ac20b32d78
  1. 168
      remotexy_relays4.ino

168
remotexy_relays4.ino

@ -0,0 +1,168 @@
/*
-- New project --
This source code of graphical user interface
has been generated automatically by RemoteXY editor.
To compile this code using RemoteXY library 2.4.3 or later version
download by link http://remotexy.com/en/library/
To connect using RemoteXY mobile app by link http://remotexy.com/en/download/
- for ANDROID 4.3.1 or later version;
- for iOS 1.3.5 or later version;
This source code is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
*/
//////////////////////////////////////////////
// RemoteXY include library //
//////////////////////////////////////////////
// RemoteXY select connection mode and include library
#define REMOTEXY_MODE__ESP8266_HARDSERIAL_POINT
#include <RemoteXY.h>
// RemoteXY connection settings
#define REMOTEXY_SERIAL Serial
#define REMOTEXY_SERIAL_SPEED 115200
#define REMOTEXY_WIFI_SSID "RemoteXY"
#define REMOTEXY_WIFI_PASSWORD "12345678"
#define REMOTEXY_SERVER_PORT 6377
// RemoteXY configurate
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =
{ 255,2,0,39,0,159,0,8,13,0,
65,4,12,20,9,9,2,1,61,18,
22,11,2,26,16,31,79,78,0,79,
70,70,0,129,0,29,20,22,7,17,
114,101,108,97,121,32,50,0,2,0,
62,35,22,11,2,26,31,31,79,78,
0,79,70,70,0,129,0,30,37,22,
7,17,114,101,108,97,121,32,51,0,
129,0,29,5,22,7,17,114,101,108,
97,121,32,49,0,129,0,30,52,22,
7,17,114,101,108,97,121,32,52,0,
67,5,5,5,20,5,177,26,16,67,
4,7,53,20,5,2,26,21,65,1,
12,35,9,9,129,0,62,6,33,5,
17,80,104,111,116,111,114,101,115,105,
115,116,111,114,0,129,0,63,52,18,
6,17,80,73,82,0 };
// this structure defines all the variables of your control interface
struct {
// input variable
uint8_t switch_1; // =1 if switch ON and =0 if OFF
uint8_t switch_2; // =1 if switch ON and =0 if OFF
// output variable
uint8_t led_1_r; // =0..255 LED Red brightness
char photoresistor[16]; // string UTF8 end zero
char pir[21]; // string UTF8 end zero
uint8_t led_2_b; // =0..255 LED Blue brightness
// other variable
uint8_t connect_flag; // =1 if wire connected, else =0
} RemoteXY;
#pragma pack(pop)
/////////////////////////////////////////////
// END RemoteXY include //
/////////////////////////////////////////////
#define PIN_SWITCH_1 6
#define PIN_SWITCH_2 5
//για φωτοαντίσταση
int anSensor = A0; // select the analog input pin for the photoresistor
int relayPin4=4;
//για σένσορα κίνησης
int pirSensor = 10;
int pirState = LOW; // we start, assuming no motion detected
int val = 0; // variable for reading the pin status
int relayPin1=7;
void setup()
{
RemoteXY_Init ();
pinMode (relayPin1, OUTPUT); //relay 1
pinMode (PIN_SWITCH_1, OUTPUT);//relay 2
pinMode (PIN_SWITCH_2, OUTPUT); //relay 3
pinMode (relayPin4, OUTPUT); //relay 4
// TODO you setup code
}
void loop()
{
//Για την φωτοαντίσταση
int timiFotos = analogRead(anSensor);
RemoteXY_Handler ();
//relay 1
//Για τον pir
val = digitalRead(pirSensor); // read input value
if (val == HIGH) { // check if the input is HIGH
if (pirState == LOW) {
// we have just turned on
strcpy (RemoteXY.pir, "Detected!");
digitalWrite(relayPin1, HIGH);//αναμένο ρελε συνεχεια
// We only want to print on the output change, not state
pirState = HIGH;
}
} else {
if (pirState == HIGH){
// we have just turned of
strcpy (RemoteXY.pir, "Ended!");
digitalWrite(relayPin1, LOW); //σβησμένο ρελε συνεχεια
// We only want to print on the output change, not state
pirState = LOW;
}
}
//relay 2
digitalWrite(PIN_SWITCH_1, (RemoteXY.switch_1==1)?LOW:HIGH);//λειτουργεί κανονικά αλλίως ανάποδα
if (digitalRead(PIN_SWITCH_1) == LOW) // if pin 10 enjoyed a high level voltage
RemoteXY.led_1_r = 255; // then turn on red light
else // else
RemoteXY.led_1_r = 0; // turn off red
//relay 3
digitalWrite(PIN_SWITCH_2, (RemoteXY.switch_2==1)?LOW:HIGH);
if (digitalRead(PIN_SWITCH_2) == LOW) // if pin 10 enjoyed a high level voltage
RemoteXY.led_2_b = 255; // then turn on red light
else // else
RemoteXY.led_2_b = 0; // turn off red
//relay 4
if (timiFotos<400)
{
digitalWrite(relayPin4, LOW);
strcpy (RemoteXY.photoresistor, "turn ON");
delay(1000);
}
if (timiFotos>=400)
{
digitalWrite(relayPin4,HIGH);
strcpy (RemoteXY.photoresistor, "turn OFF");
delay(1000);
}
// TODO you loop code
// use the RemoteXY structure for data transfer
}
Loading…
Cancel
Save