Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

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); 

}

Wednesday, September 2, 2015

Contracting and Consulting Services for Open Source Hardware Design

This video provides an overview of ForceTronics LLC's contracting and consulting services. Whether you are a maker, entrepreneur, or a startup Forcetronics Contracting and Consulting Services can help turn your idea into reality leveraging the power of open source hardware.






If you are interested contact me on twitter or email:
  • Twitter: @ForceTronics
  • Email: forcetronics@gmail.com
Put “Contracting Services” or “Consulting Services” in the subject line



Wednesday, October 29, 2014

Building an Android App to Communicate with the RN-42 Bluetooth Module

In this video we will build an Android App to communicate with the RN-42 Bluetooth module. The RN-42 is connected to Arduino Uno and the Android App we build turns on and off an LED connected to the Arduino. Below the video you will find the Arduino code and a link to download the Android App code (MIT Inventor 2 was used to build the Android App). Enjoy!



Link to download App Inventor 2 code (.aia file):
https://dl.dropboxusercontent.com/u/26591541/AndroidBTExample.aia

Arduino Code:
/*
  This sketch is part of a tutorial for connecting to and communicating with an HC-06 or an RN-42 bluetooth module using a custom Android App. 
  The bluetooth modules are connected to an Arduino and the Arduino is connected to an LED. The Android app is used to wirelessly turn on and
  off the LED using  bluetooth. 

  This code is in the public domain.
 */

// Pin 7 has a LED connected to it
int led = 7;

// the setup routine runs once when you press reset:
void setup() {
  
  Serial.begin(9600);
  // initialize the digital pin as an output and set it low initially
  pinMode(led, OUTPUT);
  digitalWrite(led, LOW);
}

// the loop routine runs over and over again forever:
void loop() {
  delay(30);
  String t; //create an empty string to store messages from Android
  while(Serial.available()) { //keep reading bytes while they are still more in the buffer
    t += (char)Serial.read(); //read byte, convert to char, and append it to string
  }
  
  if(t.length()) { //if string is not empty do the following
    if(t == "on") { //if the string is equal to "on" then turn LED on
      digitalWrite(led, HIGH); //Set digital pin to high to turn LED on
      Serial.write("LED is on"); //Tell the Android app that the LED was turned on
    }
    else if (t == "off") { 
      digitalWrite(led, LOW);  
      Serial.write("LED is off");
    } // turn the LED off by making the voltage LOW
  }
}