Saturday, June 10, 2017

Using Compiler Directives with Arduino

In this video we look at what are compiler directives and how they can come in handy.

//***********************Arduino code from the video***********
 * This code was made for a video tutorial on ForceTronics YouTube Channel called "Using Compiler Directives with Arduino"
 * This code free to be used or modified by anybody at your own risk

//#define SERIAL_PRINT 1
#define ADC_PIN (uint8_t)A0

  #define _SERIAL_BEGIN(x) Serial.begin(x);
  #define _SERIAL_PRINT(x) Serial.print(x);
  #define _SERIAL_PRINTLN(x) Serial.println(x);
  #define _SERIAL_BEGIN(x)
  #define _SERIAL_PRINT(x)
  #define _SERIAL_PRINTLN(x)

void setup() {
  _SERIAL_BEGIN(57600); //start serial comm if enabled

  //This will only print if SERIAL_PRINT is 1
  _SERIAL_PRINTLN("We are going to take an ADC reading every 2 sec...");


void loop() {
  _SERIAL_PRINT("The latest ADC measurement is ");