Click here to Skip to main content
15,897,891 members
Articles / Internet of Things / Arduino

Arduino Unleashed

Rate me:
Please Sign up or sign in to vote.
4.90/5 (19 votes)
18 Sep 2010CPOL8 min read 172.3K   679   40  
This article is all about empowering you with more powerful tools that let you unleash your creativity without being limited by the default IDE.
  • arduino.zip
    • Arduino
      • .metadata
        • .lock
        • .log
        • .mylyn
          • contexts
          • repositories.xml.zip
        • .plugins
          • de.innot.avreclipse.core
          • org.eclipse.cdt.core
          • org.eclipse.cdt.make.core
          • org.eclipse.cdt.managedbuilder.core
          • org.eclipse.cdt.ui
          • org.eclipse.core.resources
            • .history
              • 0
                • 90178f64a8c1001f13c7f5de4bcffe65
              • 11
                • 90c8cb7aaec1001f1a968c8925716fac
              • 15
                • e003e79caec1001f1a968c8925716fac
              • 16
                • 309eaa2aaac1001f1a968c8925716fac
                • b00fc1e8a7c1001f13c7f5de4bcffe65
              • 17
                • 303f0b1aaac1001f1a968c8925716fac
              • 19
                • 50db879ba9c1001f13c7f5de4bcffe65
                • b0822d6baac1001f1a968c8925716fac
              • 1a
                • a0d01b72aec1001f1a968c8925716fac
              • 1d
                • 9006869ba9c1001f13c7f5de4bcffe65
              • 2
                • 40805c37b3c1001f1a968c8925716fac
              • 24
                • 908eddbfafc1001f1a968c8925716fac
              • 25
                • 60a2bb77aec1001f1a968c8925716fac
              • 26
                • 709c0a3eadc1001f1a968c8925716fac
              • 29
                • b0563bbbafc1001f1a968c8925716fac
              • 2a
                • 50b68fbfa7c1001f13c7f5de4bcffe65
              • 2f
                • 609fb36eaec1001f1a968c8925716fac
              • 3
                • 00b2433ea6c1001f13c7f5de4bcffe65
              • 30
                • e0862b6baac1001f1a968c8925716fac
              • 31
                • e0f5edd5a9c1001f13c7f5de4bcffe65
              • 32
                • 40a6c07eaac1001f1a968c8925716fac
              • 33
                • 7066e74ab3c1001f1a968c8925716fac
                • 80265848a7c1001f13c7f5de4bcffe65
              • 34
                • 00eb51d6adc1001f1a968c8925716fac
              • 35
                • d05a5b48a7c1001f13c7f5de4bcffe65
                • e046fe19aac1001f1a968c8925716fac
              • 36
                • 20ed7c6ba8c1001f13c7f5de4bcffe65
              • 37
                • f03b866ba8c1001f13c7f5de4bcffe65
              • 39
                • 507dde20a9c1001f13c7f5de4bcffe65
              • 3b
                • a0b1ce97aec1001f1a968c8925716fac
              • 3d
                • 0063ef74aec1001f1a968c8925716fac
              • 3e
                • e0191572aec1001f1a968c8925716fac
              • 42
                • 80903869aac1001f1a968c8925716fac
              • 45
                • 10c140a1aec1001f1a968c8925716fac
              • 47
                • 3073473caec1001f1a968c8925716fac
              • 48
                • c0b85d37b3c1001f1a968c8925716fac
              • 4f
                • 70572f6baac1001f1a968c8925716fac
              • 50
                • 30083988b3c1001f1a968c8925716fac
              • 51
                • d0723269a6c1001f13c7f5de4bcffe65
              • 52
                • 902b1441b0c1001f1a968c8925716fac
              • 54
                • d06a4b3caec1001f1a968c8925716fac
              • 56
                • 002c6d00aac1001f13c7f5de4bcffe65
                • b00a8fbdafc1001f1a968c8925716fac
                • b09bbdc9a7c1001f13c7f5de4bcffe65
              • 57
                • b0f54422aac1001f1a968c8925716fac
              • 58
                • d077b7b2afc1001f1a968c8925716fac
              • 5a
                • d05d819faec1001f1a968c8925716fac
              • 5b
                • b0f4b977aec1001f1a968c8925716fac
              • 5c
                • 007bc27eaac1001f1a968c8925716fac
              • 5d
                • 40e5c897aec1001f1a968c8925716fac
                • 608adfbfafc1001f1a968c8925716fac
                • d013899ba9c1001f13c7f5de4bcffe65
              • 5e
                • c0b1af2db3c1001f1a968c8925716fac
              • 5f
                • 3048ecd5a9c1001f13c7f5de4bcffe65
              • 61
                • 404b5cd6adc1001f1a968c8925716fac
              • 67
                • 20740441b0c1001f1a968c8925716fac
              • 68
                • 20aee081aec1001f1a968c8925716fac
              • 6a
                • f0ee1a37a9c1001f13c7f5de4bcffe65
              • 6b
                • d06be49caec1001f1a968c8925716fac
              • 6c
                • 10595034b0c1001f1a968c8925716fac
              • 7
                • d076c47eaac1001f1a968c8925716fac
              • 70
                • 10503ea1aec1001f1a968c8925716fac
                • 30b3ee79a7c1001f13c7f5de4bcffe65
                • e06d6369a6c1001f13c7f5de4bcffe65
              • 71
                • f06556d4a9c1001f13c7f5de4bcffe65
              • 72
                • 40a2011aaac1001f1a968c8925716fac
              • 74
                • 00145534b0c1001f1a968c8925716fac
                • 70add097aec1001f1a968c8925716fac
              • 77
                • 50a0ae2db3c1001f1a968c8925716fac
                • 70271c37a9c1001f13c7f5de4bcffe65
              • 79
                • 20b07f9faec1001f1a968c8925716fac
              • 7a
                • 400092bfa7c1001f13c7f5de4bcffe65
                • 8051a52db3c1001f1a968c8925716fac
              • 7b
                • 703298bdafc1001f1a968c8925716fac
              • 7d
                • 006f493caec1001f1a968c8925716fac
                • 0087c57aaec1001f1a968c8925716fac
                • f063093eadc1001f1a968c8925716fac
              • 7f
                • d033043eadc1001f1a968c8925716fac
              • 80
                • a038c7c9a7c1001f13c7f5de4bcffe65
                • f03e3e22aac1001f1a968c8925716fac
              • 81
                • 402ade9caec1001f1a968c8925716fac
                • 809b876ba8c1001f13c7f5de4bcffe65
              • 84
                • 30698b4ea8c1001f13c7f5de4bcffe65
              • 85
                • 90b7c839aec1001f1a968c8925716fac
              • 87
                • 2040ed74aec1001f1a968c8925716fac
              • 8a
                • 004b6169a6c1001f13c7f5de4bcffe65
                • 60a34622aac1001f1a968c8925716fac
              • 8c
                • 70f2e59caec1001f1a968c8925716fac
              • 8d
                • c02f1241b0c1001f1a968c8925716fac
              • 8f
                • a05b95bfa7c1001f13c7f5de4bcffe65
                • e082e281aec1001f1a968c8925716fac
              • 93
                • 602ce681aec1001f1a968c8925716fac
              • 98
                • 5096829faec1001f1a968c8925716fac
              • 99
                • 309f4822aac1001f1a968c8925716fac
                • b0b13c88b3c1001f1a968c8925716fac
              • a
                • 50b47d9faec1001f1a968c8925716fac
              • a4
                • f04b5937b3c1001f1a968c8925716fac
              • a7
                • b077a4e3a7c1001f13c7f5de4bcffe65
                • c015c5c9a7c1001f13c7f5de4bcffe65
              • aa
                • 70c9a82aaac1001f1a968c8925716fac
              • ab
                • 40411937a9c1001f13c7f5de4bcffe65
                • 60a56b00aac1001f13c7f5de4bcffe65
              • ad
                • 30ea3d88b3c1001f1a968c8925716fac
                • c0125bd6adc1001f1a968c8925716fac
              • ae
                • 9088be77aec1001f1a968c8925716fac
                • b0205b37b3c1001f1a968c8925716fac
              • af
                • d02d5234b0c1001f1a968c8925716fac
              • b
                • 007b4155aac1001f1a968c8925716fac
              • b0
                • 10ec9ae1a7c1001f13c7f5de4bcffe65
              • b2
                • 00a8ed4ab3c1001f1a968c8925716fac
              • b4
                • 6066b6b2afc1001f1a968c8925716fac
              • b5
                • 00caa2e3a7c1001f13c7f5de4bcffe65
              • b9
                • 70880d57aac1001f1a968c8925716fac
              • bb
                • 00e5fa3dadc1001f1a968c8925716fac
                • 10ec7f9ba9c1001f13c7f5de4bcffe65
              • bc
                • 0062bfe8a7c1001f13c7f5de4bcffe65
                • 2077bd77aec1001f1a968c8925716fac
              • c1
                • b04742a1aec1001f1a968c8925716fac
                • e0480641b0c1001f1a968c8925716fac
              • c2
                • 1052e020a9c1001f13c7f5de4bcffe65
                • d008d497aec1001f1a968c8925716fac
              • c5
                • 10fc93bfa7c1001f13c7f5de4bcffe65
              • c6
                • 207294e3a7c1001f13c7f5de4bcffe65
              • c7
                • 40840f57aac1001f1a968c8925716fac
              • c8
                • 900a53d4a9c1001f13c7f5de4bcffe65
                • c0bc1057aac1001f1a968c8925716fac
              • c9
                • 40a743a1aec1001f1a968c8925716fac
                • d0cce481aec1001f1a968c8925716fac
              • ca
                • 3066bde8a7c1001f13c7f5de4bcffe65
              • cb
                • 908ae120a9c1001f13c7f5de4bcffe65
              • cc
                • c02d0a1aaac1001f1a968c8925716fac
                • f08df0d5a9c1001f13c7f5de4bcffe65
              • d0
                • 2085eb4ab3c1001f1a968c8925716fac
              • d3
                • 000c5248a7c1001f13c7f5de4bcffe65
              • d5
                • a08c0b57aac1001f1a968c8925716fac
              • d6
                • 80e0ee4ab3c1001f1a968c8925716fac
              • d8
                • 20d0e3bfafc1001f1a968c8925716fac
              • d9
                • b0f4a62aaac1001f1a968c8925716fac
                • f06d2b69a6c1001f13c7f5de4bcffe65
              • dc
                • c0aece7aaec1001f1a968c8925716fac
              • e0
                • 80db5334b0c1001f1a968c8925716fac
              • e1
                • 00c31337a9c1001f13c7f5de4bcffe65
              • e3
                • 8081dc20a9c1001f13c7f5de4bcffe65
              • e5
                • 507e1d72aec1001f1a968c8925716fac
              • e6
                • 704b50d4a9c1001f13c7f5de4bcffe65
              • e7
                • 106559d6adc1001f1a968c8925716fac
              • e8
                • c0006f00aac1001f13c7f5de4bcffe65
                • c037f174aec1001f1a968c8925716fac
              • e9
                • a091b4b2afc1001f1a968c8925716fac
              • ea
                • 408e846ba8c1001f13c7f5de4bcffe65
              • eb
                • c08496bdafc1001f1a968c8925716fac
              • ec
                • 702d55d4a9c1001f13c7f5de4bcffe65
              • f1
                • b019ad2db3c1001f1a968c8925716fac
                • f0dc3a88b3c1001f1a968c8925716fac
              • f4
                • 50225a48a7c1001f13c7f5de4bcffe65
              • f7
                • 4076cd7aaec1001f1a968c8925716fac
              • f8
                • b0d6ab2aaac1001f1a968c8925716fac
              • fb
                • 10fda6b2afc1001f1a968c8925716fac
            • .projects
              • Arduino
                • .indexes
                  • 19
                    • history.index
                  • 33
                    • history.index
                  • af
                    • history.index
                  • history.index
                  • properties.index
                • .markers
              • BlinkenLights
                • .indexes
                  • 19
                    • history.index
                  • 33
                    • history.index
                  • af
                    • history.index
                  • history.index
                  • properties.index
            • .root
              • .indexes
                • history.version
                • properties.index
                • properties.version
              • 3.tree
            • .safetable
              • org.eclipse.core.resources
          • org.eclipse.core.runtime
          • org.eclipse.debug.core
          • org.eclipse.debug.ui
          • org.eclipse.epp.usagedata.recording
          • org.eclipse.equinox.p2.ui
          • org.eclipse.ltk.core.refactoring
          • org.eclipse.mylyn.bugzilla.core
          • org.eclipse.mylyn.tasks.ui
          • org.eclipse.team.cvs.core
          • org.eclipse.ui.intro
          • org.eclipse.ui.workbench
        • version.ini
      • Arduino
      • BlinkenLights
/*
 Print.cpp - Base class that provides print() and println()
 Copyright (c) 2008 David A. Mellis.  All right reserved.
 
 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version 2.1 of the License, or (at your option) any later version.
 
 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 Lesser General Public License for more details.
 
 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 Modified 23 November 2006 by David A. Mellis
 */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "wiring.h"

#include "Print.h"

// Public Methods //////////////////////////////////////////////////////////////

/* default implementation: may be overridden */
void Print::write(const char *str)
{
  while (*str)
    write(*str++);
}

/* default implementation: may be overridden */
void Print::write(const uint8_t *buffer, size_t size)
{
  while (size--)
    write(*buffer++);
}

void Print::print(const String &s)
{
  for (int i = 0; i < s.length(); i++) {
    write(s[i]);
  }
}

void Print::print(const char str[])
{
  write(str);
}

void Print::print(char c, int base)
{
  print((long) c, base);
}

void Print::print(unsigned char b, int base)
{
  print((unsigned long) b, base);
}

void Print::print(int n, int base)
{
  print((long) n, base);
}

void Print::print(unsigned int n, int base)
{
  print((unsigned long) n, base);
}

void Print::print(long n, int base)
{
  if (base == 0) {
    write(n);
  } else if (base == 10) {
    if (n < 0) {
      print('-');
      n = -n;
    }
    printNumber(n, 10);
  } else {
    printNumber(n, base);
  }
}

void Print::print(unsigned long n, int base)
{
  if (base == 0) write(n);
  else printNumber(n, base);
}

void Print::print(double n, int digits)
{
  printFloat(n, digits);
}

void Print::println(void)
{
  print('\r');
  print('\n');  
}

void Print::println(const String &s)
{
  print(s);
  println();
}

void Print::println(const char c[])
{
  print(c);
  println();
}

void Print::println(char c, int base)
{
  print(c, base);
  println();
}

void Print::println(unsigned char b, int base)
{
  print(b, base);
  println();
}

void Print::println(int n, int base)
{
  print(n, base);
  println();
}

void Print::println(unsigned int n, int base)
{
  print(n, base);
  println();
}

void Print::println(long n, int base)
{
  print(n, base);
  println();
}

void Print::println(unsigned long n, int base)
{
  print(n, base);
  println();
}

void Print::println(double n, int digits)
{
  print(n, digits);
  println();
}

// Private Methods /////////////////////////////////////////////////////////////

void Print::printNumber(unsigned long n, uint8_t base)
{
  unsigned char buf[8 * sizeof(long)]; // Assumes 8-bit chars. 
  unsigned long i = 0;

  if (n == 0) {
    print('0');
    return;
  } 

  while (n > 0) {
    buf[i++] = n % base;
    n /= base;
  }

  for (; i > 0; i--)
    print((char) (buf[i - 1] < 10 ?
      '0' + buf[i - 1] :
      'A' + buf[i - 1] - 10));
}

void Print::printFloat(double number, uint8_t digits) 
{ 
  // Handle negative numbers
  if (number < 0.0)
  {
     print('-');
     number = -number;
  }

  // Round correctly so that print(1.999, 2) prints as "2.00"
  double rounding = 0.5;
  for (uint8_t i=0; i<digits; ++i)
    rounding /= 10.0;
  
  number += rounding;

  // Extract the integer part of the number and print it
  unsigned long int_part = (unsigned long)number;
  double remainder = number - (double)int_part;
  print(int_part);

  // Print the decimal point, but only if there are digits beyond
  if (digits > 0)
    print("."); 

  // Extract digits from the remainder one at a time
  while (digits-- > 0)
  {
    remainder *= 10.0;
    int toPrint = int(remainder);
    print(toPrint);
    remainder -= toPrint; 
  } 
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) NVIDIA India
India India
I am a software engineer by profession and an electronics engineer by education. Used to be (and still am) a hobby programmer, an electronics enthusiast/DIYer etc.

Some areas which interest me are...compiler construction, operating systems, robotics, science in general etc

Comments and Discussions