15,899,937 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by Doctor Wizard (Top 1 by date)
Doctor Wizard
11-May-16 9:18am
View
<pre lang="C#">Problem is NOT with HTUD21D.h, as my HTUD21D_testbed and DS18B20_testbed projects both compile and run just fine. Further testing seems to confirm it is a problem with the conditional compile. Note the following:
1) I finished the DS18B20 section. The following will not compile:
<pre lang="c++">#define SENSOR_NONE 0
#define SENSOR_BMP180 1 // Set to 1 BMP180 Barometric Pressure sensor is installed -- OR
#define SENSOR_HTU21D 2 // set to 2 if HTU21D Temp & Humidity sensor is installed -- OR
#define SENSOR_DS18B20 3 // Set to 3 if DS18B20 Temp sensor is installed on the TinyRTC
#define SENSOR_TYPE SENSOR_DS18B20
#if SENSOR_TYPE == SENSOR_BMP180
#include <BMP180.h>
BMP180 weather;
#endif
#if SENSOR_TYPE == SENSOR_HTU21D
#include <HTU21D.h>
HTU21D weather;
#endif
#if SENSOR_TYPE == SENSOR_DS18B20
#define ONE_WIRE_BUS 15 // Data Pin that DS18B20 is connected to
#include <OneWire.h>
#include <DallasTemperature.h>
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature weather(&oneWire);
#endif
</pre>
But this will:
<pre lang="c++">#define SENSOR_NONE 0
#define SENSOR_BMP180 1 // Set to 1 BMP180 Barometric Pressure sensor is installed -- OR
#define SENSOR_HTU21D 2 // set to 2 if HTU21D Temp & Humidity sensor is installed -- OR
#define SENSOR_DS18B20 3 // Set to 3 if DS18B20 Temp sensor is installed on the TinyRTC
#define SENSOR_TYPE SENSOR_DS18B20
/*
#if SENSOR_TYPE == SENSOR_BMP180
#include <BMP180.h>
BMP180 weather;
#endif
#if SENSOR_TYPE == SENSOR_HTU21D
#include <HTU21D.h>
HTU21D weather;
#endif
#if SENSOR_TYPE == SENSOR_DS18B20
*/
#define ONE_WIRE_BUS 15 // Data Pin that DS18B20 is connected to
#include <OneWire.h>
#include <DallasTemperature.h>
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature weather(&oneWire);
//#endif</pre>
Likewise, if I move the DS18B20 block to the top, it will compile
<pre lang="c++">#define SENSOR_NONE 0
#define SENSOR_BMP180 1 // Set to 1 BMP180 Barometric Pressure sensor is installed -- OR
#define SENSOR_HTU21D 2 // set to 2 if HTU21D Temp & Humidity sensor is installed -- OR
#define SENSOR_DS18B20 3 // Set to 3 if DS18B20 Temp sensor is installed on the TinyRTC
#define SENSOR_TYPE SENSOR_DS18B20
#if SENSOR_TYPE == SENSOR_DS18B20
#define ONE_WIRE_BUS 15 // Data Pin that DS18B20 is connected to
#include <OneWire.h>
#include <DallasTemperature.h>
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature weather(&oneWire);
#endif
#if SENSOR_TYPE == SENSOR_BMP180
#include <BMP180.h>
BMP180 weather;
#endif
#if SENSOR_TYPE == SENSOR_HTU21D
#include <HTU21D.h>
HTU21D weather;
#endif</pre>
Same tricks apply to the HTU21D block. Commenting out the BMP180 block above it and the DS18B20 block below it gets it to compile. Moving the DS18B20 block to the top gets it to compile. But with it in the middle (or at the bottom) it will not compile.
Won't Compile:
<pre lang="c++">#define SENSOR_NONE 0
#define SENSOR_BMP180 1 // Set to 1 BMP180 Barometric Pressure sensor is installed -- OR
#define SENSOR_HTU21D 2 // set to 2 if HTU21D Temp & Humidity sensor is installed -- OR
#define SENSOR_DS18B20 3 // Set to 3 if DS18B20 Temp sensor is installed on the TinyRTC
#define SENSOR_TYPE SENSOR_HTU21D
#if SENSOR_TYPE == SENSOR_BMP180
#include <BMP180.h>
BMP180 weather;
#endif
#if SENSOR_TYPE == SENSOR_HTU21D
#include <HTU21D.h>
HTU21D weather;
#endif
#if SENSOR_TYPE == SENSOR_DS18B20
#define ONE_WIRE_BUS 15 // Data Pin that DS18B20 is connected to
#include <OneWire.h>
#include <DallasTemperature.h>
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature weather(&oneWire);
#endif</pre>
Will Compile:
<pre lang="c++">#define SENSOR_NONE 0
#define SENSOR_BMP180 1 // Set to 1 BMP180 Barometric Pr