Skip to content

Commit

Permalink
Merge pull request #3 from DanielOgorchock/experimental
Browse files Browse the repository at this point in the history
Memory Optimizations
  • Loading branch information
DanielOgorchock committed Apr 15, 2015
2 parents c62f9b9 + 4631c47 commit 64aff97
Show file tree
Hide file tree
Showing 42 changed files with 271 additions and 226 deletions.
54 changes: 28 additions & 26 deletions Arduino/Sketches/ST_Anything/ST_Anything.ino
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@
// ---- --- ----
// 2015-01-03 Dan & Daniel Original Creation
// 2015-03-28 Dan Ogorchock Removed RCSwitch #include now that the libraries are split up
//
// 2015-03-31 Daniel O. Memory optimizations utilizing progmem
//
//******************************************************************************************

//******************************************************************************************
// SmartThings Library for Arduino Shield
//******************************************************************************************
#include <SoftwareSerial.h> //Arduino UNO/Leonardo uses SoftwareSerial for the SmartThings Library
#include <SmartThings.h> //Library to provide API to the SmartThings Shield
#include <dht.h> //DHT Temperature and Humidity Library
#include <avr/pgmspace.h>

//******************************************************************************************
// ST_Anything Library
Expand Down Expand Up @@ -85,37 +85,39 @@
#define PIN_ALARM 9
#define PIN_CONTACT 11

//******************************************************************************************
//Declare each Device that is attached to the Arduino
// Notes: - For each device, there is typically a corresponding "tile" defined in your
// SmartThings DeviceType Groovy code
// - For details on each device's constructor arguments below, please refer to the
// corresponding header (.h) and program (.cpp) files.
// - The name assigned to each device (1st argument below) must match the Groovy
// DeviceType Tile name. (Note: "temphumid" below is the exception to this rule
// as the DHT sensors produce both "temperature" and "humidity". Data from that
// particular sensor is sent to the ST Shield in two separate updates, one for
// "temperature" and one for "humidity")
//******************************************************************************************
//Polling Sensors
st::PS_Illuminance sensor1("illuminance", 120, 0, PIN_ILLUMINANCE);
st::PS_TemperatureHumidity sensor2("temphumid", 120, 10, PIN_TEMPERATUREHUMIDITY, st::PS_TemperatureHumidity::DHT22);
st::PS_Water sensor3("water", 60, 20, PIN_WATER);

//Interrupt Sensors
st::IS_Motion sensor4("motion", PIN_MOTION, HIGH, false);
st::IS_Contact sensor5("contact", PIN_CONTACT, LOW, true);

//Executors
st::EX_Switch executor1("switch", PIN_SWITCH, LOW, true);
st::EX_Alarm executor2("alarm", PIN_ALARM, LOW, true);


//******************************************************************************************
//Arduino Setup() routine
//******************************************************************************************
void setup()
{
//******************************************************************************************
//Declare each Device that is attached to the Arduino
// Notes: - For each device, there is typically a corresponding "tile" defined in your
// SmartThings DeviceType Groovy code
// - For details on each device's constructor arguments below, please refer to the
// corresponding header (.h) and program (.cpp) files.
// - The name assigned to each device (1st argument below) must match the Groovy
// DeviceType Tile name. (Note: "temphumid" below is the exception to this rule
// as the DHT sensors produce both "temperature" and "humidity". Data from that
// particular sensor is sent to the ST Shield in two separate updates, one for
// "temperature" and one for "humidity")
//******************************************************************************************
//Polling Sensors
static st::PS_Illuminance sensor1(F("illuminance"), 120, 0, PIN_ILLUMINANCE);
static st::PS_TemperatureHumidity sensor2(F("temphumid"), 120, 10, PIN_TEMPERATUREHUMIDITY, st::PS_TemperatureHumidity::DHT22);
static st::PS_Water sensor3(F("water"), 60, 20, PIN_WATER);

//Interrupt Sensors
static st::IS_Motion sensor4(F("motion"), PIN_MOTION, HIGH, false);
static st::IS_Contact sensor5(F("contact"), PIN_CONTACT, LOW, true);

//Executors
static st::EX_Switch executor1(F("switch"), PIN_SWITCH, LOW, true);
static st::EX_Alarm executor2(F("alarm"), PIN_ALARM, LOW, true);

//*****************************************************************************
// Configure debug print output from each main class
// -Note: Set these to "false" if using Hardware Serial on pins 0 & 1
Expand Down Expand Up @@ -162,4 +164,4 @@ void loop()
//Execute the Everything run method which takes care of "Everything"
//*****************************************************************************
st::Everything::run();
}
}
59 changes: 31 additions & 28 deletions Arduino/Sketches/ST_Anything_Doors/ST_Anything_Doors.ino
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
// 2015-01-03 Dan & Daniel Original Creation
// 2015-01-07 Dan Ogorchock Modified for Door Monitoring and Garage Door Control
// 2015-03-28 Dan Ogorchock Removed RCSwitch #include now that the libraries are split up
//
// 2015-03-31 Daniel O. Memory optimizations utilizing progmem
//
//******************************************************************************************

Expand All @@ -49,6 +49,7 @@
#include <SoftwareSerial.h> //Arduino UNO/Leonardo uses SoftwareSerial for the SmartThings Library
#include <SmartThings.h> //Library to provide API to the SmartThings Shield
#include <dht.h> //DHT Temperature and Humidity Library
#include <avr/pgmspace.h>

//******************************************************************************************
// ST_Anything Library
Expand Down Expand Up @@ -96,39 +97,41 @@
#define PIN_CONTACT_KITCHEN_DOOR 12
#define PIN_CONTACT_SIDEGARAGE_DOOR 13

//******************************************************************************************
//Declare each Device that is attached to the Arduino
// Notes: - For each device, there is typically a corresponding "tile" defined in your
// SmartThings DeviceType Groovy code
// - For details on each device's constructor arguments below, please refer to the
// corresponding header (.h) and program (.cpp) files.
// - The name assigned to each device (1st argument below) must match the Groovy
// DeviceType Tile name. (Note: "temphumid" below is the exception to this rule
// as the DHT sensors produce both "temperature" and "humidity". Data from that
// particular sensor is sent to the ST Shield in two separate updates, one for
// "temperature" and one for "humidity")
//******************************************************************************************
//Polling Sensors
st::PS_TemperatureHumidity sensor1("temphumid", 120, 10, PIN_TEMPERATUREHUMIDITY, st::PS_TemperatureHumidity::DHT22);

//Interrupt Sensors
st::IS_Motion sensor2("motion", PIN_MOTION, HIGH, false);
st::IS_DoorControl sensor3("leftDoor", PIN_CONTACT_LEFTGARAGE_DOOR, LOW, true, PIN_RELAY_LEFTGARAGE_DOOR, LOW, true, 1000);
st::IS_DoorControl sensor4("rightDoor", PIN_CONTACT_RIGHTGARAGE_DOOR, LOW, true, PIN_RELAY_RIGHTGARAGE_DOOR, LOW, true, 1000);
st::IS_Contact sensor5("garagesideDoor", PIN_CONTACT_SIDEGARAGE_DOOR, LOW, true);
st::IS_Contact sensor6("frontDoor", PIN_CONTACT_FRONT_DOOR, LOW, true);
st::IS_Contact sensor7("backDoor", PIN_CONTACT_BACK_DOOR, LOW, true);
st::IS_Contact sensor8("kitchenDoor", PIN_CONTACT_KITCHEN_DOOR, LOW, true);

//Executors
//st::EX_Switch executor1("sampleEX", PIN_sampleEX, LOW, true);


//******************************************************************************************
//Arduino Setup() routine
//******************************************************************************************
void setup()
{
//******************************************************************************************
//Declare each Device that is attached to the Arduino
// Notes: - For each device, there is typically a corresponding "tile" defined in your
// SmartThings DeviceType Groovy code
// - For details on each device's constructor arguments below, please refer to the
// corresponding header (.h) and program (.cpp) files.
// - The name assigned to each device (1st argument below) must match the Groovy
// DeviceType Tile name. (Note: "temphumid" below is the exception to this rule
// as the DHT sensors produce both "temperature" and "humidity". Data from that
// particular sensor is sent to the ST Shield in two separate updates, one for
// "temperature" and one for "humidity")
//******************************************************************************************
//Polling Sensors
static st::PS_TemperatureHumidity sensor1(F("temphumid"), 120, 10, PIN_TEMPERATUREHUMIDITY, st::PS_TemperatureHumidity::DHT22);

//Interrupt Sensors
static st::IS_Motion sensor2(F("motion"), PIN_MOTION, HIGH, false);
static st::IS_DoorControl sensor3(F("leftDoor"), PIN_CONTACT_LEFTGARAGE_DOOR, LOW, true, PIN_RELAY_LEFTGARAGE_DOOR, LOW, true, 1000);
static st::IS_DoorControl sensor4(F("rightDoor"), PIN_CONTACT_RIGHTGARAGE_DOOR, LOW, true, PIN_RELAY_RIGHTGARAGE_DOOR, LOW, true, 1000);
static st::IS_Contact sensor5(F("garagesideDoor"), PIN_CONTACT_SIDEGARAGE_DOOR, LOW, true);
static st::IS_Contact sensor6(F("frontDoor"), PIN_CONTACT_FRONT_DOOR, LOW, true);
static st::IS_Contact sensor7(F("backDoor"), PIN_CONTACT_BACK_DOOR, LOW, true);
static st::IS_Contact sensor8(F("kitchenDoor"), PIN_CONTACT_KITCHEN_DOOR, LOW, true);

//Executors
//static st::EX_Switch executor1(F("sampleEX"), PIN_sampleEX, LOW, true);


//*****************************************************************************
// Configure debug print output from each main class
// -Note: Set these to "false" if using Hardware Serial on pins 0 & 1
Expand Down Expand Up @@ -177,4 +180,4 @@ void loop()
//Execute the Everything run method which takes care of "Everything"
//*****************************************************************************
st::Everything::run();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
// 2015-01-03 Dan & Daniel Original Creation
// 2015-03-10 Dan Modified to monitor furnace alarm
// 2015-03-14 Dan Added LED capability for visual status of the FurnaceAlarm
//
// 2015-03-31 Daniel O. Memory optimizations utilizing progmem
//
//******************************************************************************************

Expand All @@ -42,6 +42,7 @@
//******************************************************************************************
#include <SoftwareSerial.h> //Arduino UNO/Leonardo uses SoftwareSerial for the SmartThings Library
#include <SmartThings.h> //Library to provide API to the SmartThings Shield
#include <avr/pgmspace.h>

//******************************************************************************************
// ST_Anything Library
Expand Down Expand Up @@ -72,34 +73,37 @@

#define PIN_CONTACT 11

//******************************************************************************************
//Declare each Device that is attached to the Arduino
// Notes: - For each device, there is typically a corresponding "tile" defined in your
// SmartThings DeviceType Groovy code
// - For details on each device's constructor arguments below, please refer to the
// corresponding header (.h) and program (.cpp) files.
// - The name assigned to each device (1st argument below) must match the Groovy
// DeviceType Tile name. (Note: "temphumid" below is the exception to this rule
// as the DHT sensors produce both "temperature" and "humidity". Data from that
// particular sensor is sent to the ST Shield in two separate updates, one for
// "temperature" and one for "humidity")
//******************************************************************************************
//Polling Sensors

//Interrupt Sensors
st::IS_Contact sensor1("contact", PIN_CONTACT, LOW, true, 20000);

//Executors


//Global Variables
bool lastStatus; //Hold the last status of the Furnace Alarm to prevent updating the LED too frequently
st::IS_Contact *sensor1p; //pointer for use in main loop

//******************************************************************************************
//Arduino Setup() routine
//******************************************************************************************
void setup()
{
//******************************************************************************************
//Declare each Device that is attached to the Arduino
// Notes: - For each device, there is typically a corresponding "tile" defined in your
// SmartThings DeviceType Groovy code
// - For details on each device's constructor arguments below, please refer to the
// corresponding header (.h) and program (.cpp) files.
// - The name assigned to each device (1st argument below) must match the Groovy
// DeviceType Tile name. (Note: "temphumid" below is the exception to this rule
// as the DHT sensors produce both "temperature" and "humidity". Data from that
// particular sensor is sent to the ST Shield in two separate updates, one for
// "temperature" and one for "humidity")
//******************************************************************************************
//Polling Sensors

//Interrupt Sensors
static st::IS_Contact sensor1(F("contact"), PIN_CONTACT, LOW, true, 20000);
sensor1p=&sensor1;

//Executors


//*****************************************************************************
// Configure debug print output from each main class
// -Note: Set these to "false" if using Hardware Serial on pins 0 & 1
Expand Down Expand Up @@ -147,18 +151,19 @@ void loop()

//Check to see if the Furnace is in Alarm. If true, set the Smart Thing Shield
//LED to Red. If false, set the LED to Green.
if (sensor1.getStatus() && !lastStatus)
if (sensor1p->getStatus() && !lastStatus)
{
//ALARM!!! (Red)
st::Everything::setLED(2,0,0);
lastStatus = true;

}
else if (!sensor1.getStatus() && lastStatus)
else if (!sensor1p->getStatus() && lastStatus)
{
//NORMAL (Green)
st::Everything::setLED(0,2,0);
lastStatus = false;
}

}

43 changes: 22 additions & 21 deletions Arduino/Sketches/ST_Anything_Power/ST_Anything_Power.ino
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
// ---- --- ----
// 2015-01-03 Dan & Daniel Original Creation (ST_Anything demo)
// 2015-03-31 Dan Ogorchock Modified for a Pulse Counter / Energy Meter
//
// 2015-04-14 Daniel O. Support for memory optimizations
//
//******************************************************************************************

Expand All @@ -49,6 +49,7 @@
//******************************************************************************************
#include <SoftwareSerial.h> //Arduino UNO/Leonardo uses SoftwareSerial for the SmartThings Library
#include <SmartThings.h> //Library to provide API to the SmartThings Shield
#include <avr/pgmspace.h>

//******************************************************************************************
// ST_Anything Library
Expand Down Expand Up @@ -86,31 +87,31 @@
#define PULSE_SLOPE 1.0 //Linear conversion slope (eng units = PULSE_SLOPE * counts + PULSE_OFFSET)
#define PULSE_OFFSET 0.0 //Linear conversion offset (eng units = PULSE_SLOPE * counts + PULSE_OFFSET)

//******************************************************************************************
//Declare each Device that is attached to the Arduino
// Notes: - For each device, there is typically a corresponding "tile" defined in your
// SmartThings DeviceType Groovy code
// - For details on each device's constructor arguments below, please refer to the
// corresponding header (.h) and program (.cpp) files.
// - The name assigned to each device (1st argument below) must match the Groovy
// DeviceType Tile name. (Note: "temphumid" below is the exception to this rule
// as the DHT sensors produce both "temperature" and "humidity". Data from that
// particular sensor is sent to the ST Shield in two separate updates, one for
// "temperature" and one for "humidity")
//******************************************************************************************
//Polling Sensors
st::PS_PulseCounter sensor1("power", PULSE_POLL_INTRVL, PULSE_POLL_OFFSET, PULSE_PIN, PULSE_INTTYPE, PULE_INPUTMODE, PULSE_SLOPE, PULSE_OFFSET);

//Interrupt Sensors

//Executors


//******************************************************************************************
//Arduino Setup() routine
//******************************************************************************************
void setup()
{
//******************************************************************************************
//Declare each Device that is attached to the Arduino
// Notes: - For each device, there is typically a corresponding "tile" defined in your
// SmartThings DeviceType Groovy code
// - For details on each device's constructor arguments below, please refer to the
// corresponding header (.h) and program (.cpp) files.
// - The name assigned to each device (1st argument below) must match the Groovy
// DeviceType Tile name. (Note: "temphumid" below is the exception to this rule
// as the DHT sensors produce both "temperature" and "humidity". Data from that
// particular sensor is sent to the ST Shield in two separate updates, one for
// "temperature" and one for "humidity")
//******************************************************************************************
//Polling Sensors
static st::PS_PulseCounter sensor1(F("power"), PULSE_POLL_INTRVL, PULSE_POLL_OFFSET, PULSE_PIN, PULSE_INTTYPE, PULE_INPUTMODE, PULSE_SLOPE, PULSE_OFFSET);

//Interrupt Sensors

//Executors

//*****************************************************************************
// Configure debug print output from each main class
// -Note: Set these to "false" if using Hardware Serial on pins 0 & 1
Expand Down Expand Up @@ -152,4 +153,4 @@ void loop()
//Execute the Everything run method which takes care of "Everything"
//*****************************************************************************
st::Everything::run();
}
}
Loading

0 comments on commit 64aff97

Please sign in to comment.