Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed FXOS8700CQ MODSERIAL
Diff: main.cpp
- Revision:
- 85:0cf65ceb4492
- Parent:
- 84:fc8c9b39723a
--- a/main.cpp Wed Mar 06 21:11:49 2019 +0000
+++ b/main.cpp Mon Apr 29 04:24:38 2019 +0000
@@ -85,7 +85,7 @@
}
case TEMP_HUMIDITY_ACCELEROMETER:
{
- sprintf(modem_string, "GET %s%s?serial=%s&temp=%s&humidity=%s&accelX=%s&accelY=%s&accelZ=%s %s%s\r\n\r\n", FLOW_BASE_URL, FLOW_INPUT_NAME, FLOW_DEVICE_NAME, SENSOR_DATA.Temperature, SENSOR_DATA.Humidity, SENSOR_DATA.AccelX,SENSOR_DATA.AccelY,SENSOR_DATA.AccelZ, FLOW_URL_TYPE, MY_SERVER_URL);
+ sprintf(modem_string, "GET %s%s?serial=%s&temp=%s&humidity=%s&accelX=%s&accelY=%s&accelZ=%s&alarm=%s %s%s\r\n\r\n", FLOW_BASE_URL, FLOW_INPUT_NAME, FLOW_DEVICE_NAME, SENSOR_DATA.Temperature, SENSOR_DATA.Humidity, SENSOR_DATA.AccelX,SENSOR_DATA.AccelY,SENSOR_DATA.AccelZ,SENSOR_DATA.Proximity, FLOW_URL_TYPE, MY_SERVER_URL);
break;
}
case TEMP_HUMIDITY_ACCELEROMETER_GPS:
@@ -210,21 +210,25 @@
//DigitalIn btn_temp_up(D4);
//DigitalIn btn_temp_down(D8);
-DigitalIn btn_silence(D7);
+DigitalIn btn_silence(D4);
DigitalIn motion(D3);
DigitalOut buzzer(D5);
-AnalogIn pot_temp_set(A3);
-DHT sensor(D4, DHT11);
+AnalogIn pot_temp_set(A2);
+AnalogIn Alarm_Off(A3);
+//DHT sensor(D4, DHT11);
int main() {
static unsigned ledOnce = 0;
int error = 0;
float h = 0.0f, c = 0.0f, f = 0.0f, k = 0.0f, dp = 0.0f, dpf = 0.0f;
float value = 0.0f;
+ float alm_off;
float temp_setting = 0.0f, diff = 0.0f;
int mycolor = 0x0;
- bool alarm = false;
+ bool alarms = false;
+ int mycounter = 0;
+ int movement;
//delay so that the debug terminal can open after power-on reset:
wait (5.0);
@@ -280,9 +284,13 @@
//parse_JSON(&myJsonResponse[0]);
}
} //bTimerExpiredFlag
-
- //--------------------------------begin new code--------------------------------
- error = sensor.readData();
+ //------------------------------------------------------------------------------
+ //------------------------------------------------------------------------------
+ //------------------------------------------------------------------------------
+ //-------------------------------BEGIN NEW CODE---------------------------------
+ //------------------------------------------------------------------------------
+ //------------------------------------------------------------------------------
+ /* error = sensor.readData();
if (0 == error)
{
c = sensor.ReadTemperature(CELCIUS);
@@ -298,15 +306,15 @@
{
//printf("Error: %d\n", error);
}
-
+ */
value = pot_temp_set;
//printf("Slide location %3.6f\r\n", value);
temp_setting = value * 40.0f + 50.0f;
- printf(WHT "Thermostat is set to %3.2f degrees.\r\n", temp_setting);
+ // printf(WHT "Thermostat is set to %3.2f degrees.\r\n", temp_setting);
//current_temp and rel_humid are assigned in sensors.cpp
- printf(WHT "Current temperature is %3.2f degrees.\r\n", current_temp);
- printf(WHT "Relative humidity is %3.2f percent.\r\n", rel_humid);
+ // printf(WHT "Current temperature is %3.2f degrees.\r\n", current_temp);
+ // printf(WHT "Relative humidity is %3.2f percent.\r\n", rel_humid);
printf(WHT "\r\n");
@@ -333,27 +341,46 @@
}
//if motion sensor detects motion, sound an alarm
- if ((motion == 1) && !alarm)
+
+ if (motion && !alarms)
{
- alarm = true;
+ alarms = true;
+ strcpy(SENSOR_DATA.Proximity, "1");
printf(WHT "--------------------------------\r\n");
printf(WHT "Alert! Home intrusion detected!\r\n");
printf(WHT "--------------------------------\r\n");
printf(WHT "\r\n");
}
- if ((btn_silence == 1) && alarm)
+ alm_off = Alarm_Off;//Switching to integer because AnalogIn acts weird in If statement
+ if((alm_off > 0.5f) && alarms)
{
- alarm = false;
+ alarms = false;
+ strcpy(SENSOR_DATA.Proximity, "0");
buzzer = 0;
printf(WHT "Alarm disengaged. Resuming normal operation.\r\n");
printf(WHT "\r\n");
}
- if (alarm)
+ if (alarms)
{
buzzer = !buzzer;
}
- wait(1.0);
+
+ /*wait(1.0);
+
+ mycounter = mycounter + 1;
+ if (mycounter >= 20)
+ {
+ mycounter = 0;
+ }
+ if (mycounter >= 15)
+ {
+ strcpy(SENSOR_DATA.Proximity, "1");
+ }
+ else
+ {
+ strcpy(SENSOR_DATA.Proximity, "0");
+ } */
} //forever loop
}