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

 #ifdef SERIAL_PRINT
  #define _SERIAL_BEGIN(x) Serial.begin(x);
  #define _SERIAL_PRINT(x) Serial.print(x);
  #define _SERIAL_PRINTLN(x) Serial.println(x);
 #else
  #define _SERIAL_BEGIN(x)
  #define _SERIAL_PRINT(x)
  #define _SERIAL_PRINTLN(x)
 #endif


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 ");
  _SERIAL_PRINTLN(analogRead(ADC_PIN));
  delay(2000); 

}

No comments:

Post a Comment