I don't want to have a library dynamically loaded, but I want to make it easy for the end user to have a choice on which library is loaded, depending on what he is going to use as an output screen.
Something like this:
// set output to 1 if you want to use LCD
// set output to 2 if you want to use LED
// set output to 3 if you want to use VGA
// set output to 4 if you want to use TV-OUT
byte select = 1;
switch (select) {
case 1:
#include <LiquidCrystal.h>
break;
case 2:
#include "font_7X5.h"
#include <HT1632.h>
break;
case 3:
#include <arduino_uvga.h>
#include <conio.h>
break;
case 4:
#include <TVout.h>
#include <font8x8ext.h>
break;
}
What you want is conditional compilation in the first place. Then you want a #define line that the user can change to affetct what gets compiled in.
Like this:
// select the screen to use
// set OUTPUT_TYPE to 1 if you want to use LCD
// set OUTPUT_TYPE to 2 if you want to use LED
// set OUTPUT_TYPE to 3 if you want to use VGA
// set OUTPUT_TYPE to 4 if you want to use TV-OUT
#define OUTPUT_TYPE 1 // use 1 2 3 or 4
// user shouldn't change anything below this line
#if OUTPUT_TYPE == 1
#include <LiquidCrystal.h>
#elif OUTPUT_TYPE == 2
#include "font_7X5.h"
#include <HT1632.h>
#elif OUTPUT_TYPE == 3
#include <arduino_uvga.h>
#include <conio.h>
#elif OUTPUT_TYPE == 4
#include <TVout.h>
#include <font8x8ext.h>
#endif
Absolutely not. You are trying to turn a run-time condition into a compile-time condition. This isn't Windows. You don't have run-time inclusion of DLLs.
#define VID // choose LED, LCD, VGA or VID
#ifdef LCD
#include <LiquidCrystal.h>
#elif defined LED
#include <HT1632.h>
#include "font_7X5.h"
#elif defined VGA
#include <arduino_uvga.h>
#include <conio.h>
#elif defined VID
#include <TVout.h>
#include <font8x8ext.h>
#else
#error "Please define LED, LCD, VGA or VID"
#endif
Oh and nice thing you suggest with the error check.
I decided to use your example, because people only need to fill out 1, 2, 3 or 4. But indeed also in your example you can use that error check, and I will use it