summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2014-08-12 08:27:34 -0700
committerJesse Morgan <jesse@jesterpm.net>2014-08-12 08:27:34 -0700
commitb6b6bdcf8256c635caeaa53c227e2444ed36c5b4 (patch)
tree176169d5a891dd7ba354082e4269f0a1b65e2132
parent3439e192069f315e986f7b51b6e68c41983138bc (diff)
Getting the box ready for Daniel.
This is a first pass at cleaning up the code and getting the libraries to build with Arduino 1.0. I've started reworking the code for the new adventure. Dialog notes are in notes.txt. I've also added a Makefile to build from the command line.
-rw-r--r--Makefile4
-rw-r--r--Puzzle_Box/Puzzle_Box.h52
-rw-r--r--Puzzle_Box/Puzzle_Box.pde257
-rw-r--r--Puzzle_Box/notes.txt56
-rw-r--r--arduino.mk447
-rw-r--r--libraries/EEPROM/EEPROM.cpp2
-rw-r--r--libraries/LiquidCrystal/LiquidCrystal.cpp5
-rw-r--r--libraries/LiquidCrystal/LiquidCrystal.h2
-rw-r--r--libraries/NewSoftSerial/NewSoftSerial.cpp9
-rw-r--r--libraries/NewSoftSerial/NewSoftSerial.h2
-rw-r--r--libraries/PWMServo/PWMServo.cpp2
-rw-r--r--libraries/TinyGPS/TinyGPS.cpp2
-rw-r--r--libraries/TinyGPS/TinyGPS.h2
13 files changed, 701 insertions, 141 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..e1e15ef
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,4 @@
+#LIBRARIES := EEPROM
+BOARD := uno
+
+include arduino.mk
diff --git a/Puzzle_Box/Puzzle_Box.h b/Puzzle_Box/Puzzle_Box.h
index bd5b2fb..8a310fa 100644
--- a/Puzzle_Box/Puzzle_Box.h
+++ b/Puzzle_Box/Puzzle_Box.h
@@ -1,6 +1,3 @@
-
-
-
/* Pin assignments for the version 1.1 shield */
static const int GPSrx = 4, GPStx = 3; // GPS
static const int LCD_Enable = 6, LCD_RS = 5, LCD_RW = 7; // LCD
@@ -15,14 +12,21 @@ void Msg(LiquidCrystal &lcd, const char *top, const char *bottom, unsigned long
void drawEye(int location);
void stepEyeAnimation();
void toggleEye(bool on);
-void doMainStage();
-void doButtonStage();
+
+void doIdle();
+void displayMessage();
+void doLatLong();
+void doHeading();
+void doEastOf();
+
bool doUpdateDistance();
void doCheckOverrideSerial();
void doCheckAccess();
void PowerOff();
float toRandomUnit(int choice, float dist);
-void showQuote(int quote);
+
+float toRandomUnit(int choice, float dist);
+char* getUnitLabel(int choice);
/* Fixed values should not need changing */
static const int DEF_ATTEMPT_MAX = 50;
@@ -32,6 +36,37 @@ static const int EEPROM_OFFSET = 100;
static const int MAIN_STAGE = 1;
static const int BUTTON_STAGE = 2;
+static const char MESSAGE = 3;
+static const char LATLONG = 4;
+static const char HEADING = 5;
+static const char EASTOF = 6;
+static const char OPEN = 7;
+
+static const byte STATES[] = {
+ 0,
+ MESSAGE, // Daniel!? Is it you?
+ MESSAGE, // Finally, you found me; Adventure time
+ LATLONG,
+ MESSAGE, // What's that?
+ HEADING,
+ MESSAGE, // Well that was fun, lets go back to camp
+ EASTOF,
+ MESSAGE, // Oh, btw, got you a gift
+ OPEN
+ };
+
+// LATLONG
+static const float LATLONG_LATITUDE = 46.09681;
+static const float LATLONG_LONGITUDE = -121.65900;
+
+// HEADING
+// 46.092838, -121.649211
+static const float HEADING_LATITUDE = 46.092838;
+static const float HEADING_LONGITUDE = -121.649211;
+
+// EASTOF
+static const float EASTOF_LONGITUDE = -121.62730;
+
/* Random Units */
static const int NUMBER_OF_UNITS = 4;
@@ -45,9 +80,4 @@ static const int MAX_EYE_STEPS = 13;
/* These values should be adjusted according to your needs */
static const int CLOSED_ANGLE = 80; // degrees
static const int OPEN_ANGLE = 200; // degrees
-
-static const float DEST_LATITUDE = 47.272697;
-static const float DEST_LONGITUDE = -122.021201;
static const int RADIUS = 100; // meters
-
-
diff --git a/Puzzle_Box/Puzzle_Box.pde b/Puzzle_Box/Puzzle_Box.pde
index 61c8589..5ada15a 100644
--- a/Puzzle_Box/Puzzle_Box.pde
+++ b/Puzzle_Box/Puzzle_Box.pde
@@ -1,7 +1,7 @@
/*
puzzle_box_sample.pde - Sample Arduino Puzzle Box sketch for MAKE.
COPYRIGHT (c) 2008-2011 MIKAL HART. All Rights Reserved.
-
+
This software is licensed under the terms of the Creative
Commons "Attribution Non-Commercial Share Alike" license, version
3.0, which grants the limited right to use or modify it NON-
@@ -10,21 +10,21 @@ derivative works are licensed under the IDENTICAL TERMS. For
license details see
http://creativecommons.org/licenses/by-nc-sa/3.0/
-
+
This source code 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.
-
-This code is written to accompany the January, 2011 MAKE article
+
+This code is written to accompany the January, 2011 MAKE article
entitled "Reverse Geocache Puzzle Box".
-
-This sketch illustrates how one might implement a basic puzzle box
-that incorporates rudimentary aspects of the technology in Mikal
+
+This sketch illustrates how one might implement a basic puzzle box
+that incorporates rudimentary aspects of the technology in Mikal
Hart's Reverse Geocache(tm) puzzle.
-
+
"Reverse Geocache" is a trademark of Mikal Hart.
-For supporting libraries and more information see
+For supporting libraries and more information see
http://arduiniana.org.
*/
@@ -42,13 +42,14 @@ For supporting libraries and more information see
/* Hardware Objects */
NewSoftSerial nss(GPSrx, GPStx);
LiquidCrystal lcd(LCD_RS, LCD_RW, LCD_Enable, LCD_DB4, LCD_DB5, LCD_DB6, LCD_DB7);
-TinyGPS tinygps;
+TinyGPS tinygps;
PWMServo servo;
/* Running Information */
-int currentStage = MAIN_STAGE;
-int attempt_counter;
-int currentEyeAnimationStep = 0;
+byte currentStage = MAIN_STAGE;
+byte attempt_counter;
+byte currentMessageId;
+byte currentEyeAnimationStep = 0;
long lastLoopTime = 0;
long lastAniTime = 0;
@@ -58,73 +59,95 @@ int currentUnit = 0;
/* The Arduino setup() function */
-void setup()
-{
- /*Turn on switch LED*/
- pinMode(LED_pin, OUTPUT);
- digitalWrite(LED_pin,HIGH);
-
- /* attach servo motor */
- servo.attach(servo_control);
-
- /* establish a debug session with a host computer */
- Serial.begin(115200);
-
- /* establish communications with the GPS module */
- nss.begin(4800);
-
- /* establish communication with 8x2 LCD */
- lcd.createChar(0, eye1);
- lcd.createChar(1, eye2);
- lcd.createChar(2, eye3);
- lcd.createChar(3, eye4);
- lcd.createChar(4, eye5);
- lcd.createChar(5, eye6);
- lcd.createChar(6, eye7);
- lcd.createChar(7, eye8);
- lcd.begin(8, 2); // this for an 8x2 LCD -- adjust as needed
-
- /* Make sure Pololu switch pin is OUTPUT and LOW */
- pinMode(pololu_switch_off, OUTPUT);
- digitalWrite(pololu_switch_off, LOW);
-
- /* make sure motorized latch is closed */
- servo.write(CLOSED_ANGLE);
-
- /* read the attempt counter from the EEPROM */
- attempt_counter = EEPROM.read(EEPROM_OFFSET);
- if (attempt_counter == 0xFF) // brand new EEPROM?
- attempt_counter = 0;
-
-
- lastLoopTime = millis();
-
- pinMode(BUTTON_PIN, INPUT);
- digitalWrite(BUTTON_PIN, HIGH);
-
- randomSeed(analogRead(2));
+void setup() {
+ /*Turn on switch LED*/
+ pinMode(LED_pin, OUTPUT);
+ digitalWrite(LED_pin,HIGH);
+
+ /* attach servo motor */
+ servo.attach(servo_control);
+
+ /* establish a debug session with a host computer */
+ Serial.begin(115200);
+
+ /* establish communications with the GPS module */
+ nss.begin(4800);
+
+ /* establish communication with 8x2 LCD */
+ lcd.createChar(0, eye1);
+ lcd.createChar(1, eye2);
+ lcd.createChar(2, eye3);
+ lcd.createChar(3, eye4);
+ lcd.createChar(4, eye5);
+ lcd.createChar(5, eye6);
+ lcd.createChar(6, eye7);
+ lcd.createChar(7, eye8);
+ lcd.begin(8, 2); // this for an 8x2 LCD -- adjust as needed
+
+ /* Make sure Pololu switch pin is OUTPUT and LOW */
+ pinMode(pololu_switch_off, OUTPUT);
+ digitalWrite(pololu_switch_off, LOW);
+
+ /* make sure motorized latch is closed */
+ servo.write(CLOSED_ANGLE);
+
+ /* read the attempt counter from the EEPROM */
+ attempt_counter = EEPROM.read(EEPROM_OFFSET);
+ currentMessageId = EEPROM.read(EEPROM_OFFSET + 1);
+ currentStage = EEPROM.read(EEPROM_OFFSET + 2);
+
+ if (attempt_counter == 0xFF) {
+ // brand new EEPROM?
+ attempt_counter = 0;
+ currentMessageId = 0;
+ currentStage = 0;
+ }
+
+ lastLoopTime = millis();
+
+ pinMode(BUTTON_PIN, INPUT);
+ digitalWrite(BUTTON_PIN, HIGH);
+
+ randomSeed(analogRead(2));
}
/* The Arduino loop() function */
-void loop()
-{
+void loop() {
// Check for a stage transition
int buttonState = digitalRead(BUTTON_PIN);
if (buttonState == LOW ) {
- currentStage = BUTTON_STAGE;
- }
-
- // Find our stage
- switch (currentStage) {
- case MAIN_STAGE:
- doMainStage();
- break;
+ currentStage++;
+
+ // Find our stage
+ switch (currentStage) {
+ case MESSAGE:
+ displayMessage();
+ break;
+
+ case LATLONG:
+ doLatLong();
+ break;
- case BUTTON_STAGE:
- doButtonStage();
- break;
+ case HEADING:
+ doHeading();
+ break;
+ case EASTOF:
+ doEastOf();
+ break;
+
+ case OPEN:
+ servo.write(OPEN_ANGLE); // and open the box
+ break;
+
+ default:
+ // Dunno
+ break;
+ }
+
+ } else {
+ doIdle();
}
// Find the current distance just to be ready
@@ -132,19 +155,19 @@ void loop()
im_ready = true;
}
-
// Check for override login attempts
doCheckOverrideSerial();
/* Turn off after 5 minutes */
- if (millis() >= 300000)
+ if (millis() >= 300000) {
PowerOff();
+ }
}
/**
* This is what we do while idle...
*/
-void doMainStage() {
+void doIdle() {
/* Timeline
* 0 E On (500 ms)
* 500 E Off (200 ms)
@@ -188,7 +211,7 @@ void doMainStage() {
} else {
// On
toggleEye(true);
-
+
// Reset timer
lastLoopTime = millis();
}
@@ -197,18 +220,18 @@ void doMainStage() {
/**
* This is what we do when the button has been pressed.
*/
-void doButtonStage() {
+void doLatLong() {
// Plan to go back to the main stage
currentStage = MAIN_STAGE;
- // Screen on please.
+ // Screen on please.
toggleEye(true);
/* increment it with each run */
++attempt_counter;
// TODO: Witty Saying
- //showQuote(4);
+ //showQuote(4);
/* Greeting */
Msg(lcd, "Hello", "Craig!", 1500);
@@ -229,7 +252,7 @@ void doButtonStage() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(attempt_counter);
- lcd.print(" of ");
+ lcd.print(" of ");
lcd.print(DEF_ATTEMPT_MAX);
delay(2000);
@@ -247,10 +270,19 @@ void doButtonStage() {
/* Save the new attempt counter */
EEPROM.write(EEPROM_OFFSET, attempt_counter);
+ EEPROM.write(EEPROM_OFFSET + 1, currentMessageId);
+ EEPROM.write(EEPROM_OFFSET + 2, currentStage);
doCheckAccess();
}
+void doHeading() {
+
+}
+
+void doEastOf() {
+
+}
/**
* This function updates the distance, if possible.
@@ -269,7 +301,7 @@ bool doUpdateDistance() {
if (fix_age != TinyGPS::GPS_INVALID_AGE)
{
/* Calculate the distance to the destination */
- currentDistance = TinyGPS::distance_between(lat, lon, DEST_LATITUDE, DEST_LONGITUDE);
+ currentDistance = TinyGPS::distance_between(lat, lon, LATLONG_LATITUDE, LATLONG_LONGITUDE);
return true;
}
}
@@ -299,11 +331,11 @@ void doCheckAccess() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print((long)toRandomUnit(currentUnit, currentDistance));
- lcd.setCursor(0, 1);
+ lcd.setCursor(0, 1);
lcd.print(getUnitLabel(currentUnit));
- currentUnit = (currentUnit + 1) % NUMBER_OF_UNITS;
-
+ currentUnit = (currentUnit + 1) % NUMBER_OF_UNITS;
+
delay(4000);
Msg(lcd, "Access", "Denied!", 2000);
}
@@ -316,12 +348,12 @@ void doCheckAccess() {
void PowerOff()
{
Msg(lcd, "Powering", "Off!", 2000);
- lcd.clear();
-
+ lcd.clear();
+
/*Turn off switch LED*/
pinMode(LED_pin, OUTPUT);
digitalWrite(LED_pin,LOW);
-
+
/* Bring Pololu switch control pin HIGH to turn off */
digitalWrite(pololu_switch_off, HIGH);
@@ -329,20 +361,22 @@ void PowerOff()
/* is being bypassed by the USB port. We'll wait a couple of */
/* minutes and then grant access. */
delay(120000);
- servo.write(OPEN_ANGLE); // and open the box
+ servo.write(OPEN_ANGLE); // and open the box
/* Reset the attempt counter */
- EEPROM.write(EEPROM_OFFSET, 0);
-
+ EEPROM.write(EEPROM_OFFSET, 0);
+ EEPROM.write(EEPROM_OFFSET + 1, 0);
+ EEPROM.write(EEPROM_OFFSET + 2, 0);
+
/* Leave the latch open for 10 seconds */
- delay(10000);
+ delay(10000);
/* And then seal it back up */
- servo.write(CLOSED_ANGLE);
+ servo.write(CLOSED_ANGLE);
/* Exit the program for real */
exit(1);
-}
+}
/* A helper function to display messages of a specified duration */
void Msg(LiquidCrystal &lcd, const char *top, const char *bottom, unsigned long del)
@@ -363,12 +397,12 @@ void drawEye(int location)
lcd.clear();
location = location + 2;
-
+
for (int i = 0; i < 4; i++) {
lcd.setCursor(location + i, 0);
lcd.write(i);
}
-
+
for (int i = 0; i < 4; i++) {
lcd.setCursor(location + i, 1);
lcd.write(i + 4);
@@ -377,7 +411,7 @@ void drawEye(int location)
void stepEyeAnimation() {
long delta = millis() - lastAniTime;
-
+
if (delta >= 200) {
drawEye(eyeAnimationSteps[currentEyeAnimationStep]);
currentEyeAnimationStep++;
@@ -391,11 +425,11 @@ void toggleEye(bool on) {
if (on) {
lcd.display();
digitalWrite(LED_pin, HIGH);
-
+
} else {
lcd.noDisplay();
digitalWrite(LED_pin, LOW);
- }
+ }
}
/**
@@ -406,22 +440,22 @@ float toRandomUnit(int choice, float dist) {
switch (choice) {
// meters
case 0:
- return dist;
+ return dist;
// feet
case 1:
- return dist * 3.2808;
+ return dist * 3.2808;
// cubits
case 2:
- return dist * 2.18;
+ return dist * 2.18;
// hands
case 3:
- return dist * 9.84252;
+ return dist * 9.84252;
- default:
- return -1;
+ default:
+ return -1;
}
}
@@ -451,13 +485,14 @@ char* getUnitLabel(int choice) {
}
}
-void showQuote(int id) {
- int pairs = messages[id].pairs;
+void displayMessage() {
+ int id = currentMessageId++;
+ int pairs = messages[id].pairs;
- for (int i = 0; i < pairs; i++) {
- Msg(lcd,
- messages[id].lines[i].line1,
- messages[id].lines[i].line2,
- 1000);
- }
+ for (int i = 0; i < pairs; i++) {
+ Msg(lcd,
+ messages[id].lines[i].line1,
+ messages[id].lines[i].line2,
+ 1000);
+ }
}
diff --git a/Puzzle_Box/notes.txt b/Puzzle_Box/notes.txt
index f2bb8ef..ff0cb0e 100644
--- a/Puzzle_Box/notes.txt
+++ b/Puzzle_Box/notes.txt
@@ -1,11 +1,53 @@
-* Turns on
+########
+########
+Daniel!?
+Is it u?
-* Eyes shift
-* Blink
-* Rnd Blink/shift
+Finally!
-Once the button has been pressed:
- * Witty comment
- * Give distance in a random unit
+You
+Found me
+Let's go
+on an
+
+Adven-
+ture
+
+
+########
+########
+
+We're
+almost
+
+Hey!
+What's
+
+Over
+There
+
+########
+########
+
+That was
+fun!
+
+But now
+Im tired
+
+Back to
+Camp?
+
+########
+########
+
+Ah,
+Campfire
+
+Oh, hey,
+I got
+
+You a
+Gift
diff --git a/arduino.mk b/arduino.mk
new file mode 100644
index 0000000..c9ef964
--- /dev/null
+++ b/arduino.mk
@@ -0,0 +1,447 @@
+#_______________________________________________________________________________
+#
+# edam's Arduino makefile
+#_______________________________________________________________________________
+# version 0.5
+#
+# Copyright (C) 2011, 2012, 2013 Tim Marston <tim@ed.am>.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+#
+#_______________________________________________________________________________
+#
+#
+# This is a general purpose makefile for use with Arduino hardware and
+# software. It works with the arduino-1.0 and later software releases. It
+# should work GNU/Linux and OS X. To download the latest version of this
+# makefile visit the following website where you can also find documentation on
+# it's use. (The following text can only really be considered a reference.)
+#
+# http://ed.am/dev/make/arduino-mk
+#
+# This makefile can be used as a drop-in replacement for the Arduino IDE's
+# build system. To use it, just copy arduino.mk in to your project directory.
+# Or, you could save it somewhere (I keep mine at ~/src/arduino.mk) and create
+# a symlink to it in your project directory, named "Makefile". For example:
+#
+# $ ln -s ~/src/arduino.mk Makefile
+#
+# The Arduino software (version 1.0 or later) is required. On GNU/Linux you
+# can probably install the software from your package manager. If you are
+# using Debian (or a derivative), try `apt-get install arduino`. Otherwise,
+# you can download the Arduino software manually from http://arduino.cc/. It
+# is suggested that you install it at ~/opt/arduino (or /Applications on OS X)
+# if you are unsure.
+#
+# If you downloaded the Arduino software manually and unpacked it somewhere
+# other than ~/opt/arduino (or /Applications), you will need to set up the
+# ARDUINODIR environment variable to be the path where you unpacked it. (If
+# unset, ARDUINODIR defaults to some sensible places). You could set this in
+# your ~/.profile by adding something like this:
+#
+# export ARDUINODIR=~/somewhere/arduino-1.0
+#
+# For each project, you will also need to set BOARD to the type of Arduino
+# you're building for. Type `make boards` for a list of acceptable values.
+# For example:
+#
+# $ export BOARD=uno
+# $ make
+#
+# You may also need to set SERIALDEV if it is not detected correctly.
+#
+# The presence of a .ino (or .pde) file causes the arduino.mk to automatically
+# determine values for SOURCES, TARGET and LIBRARIES. Any .c, .cc and .cpp
+# files in the project directory (or any "util" or "utility" subdirectories)
+# are automatically included in the build and are scanned for Arduino libraries
+# that have been #included. Note, there can only be one .ino (or .pde) file in
+# a project directory and if you want to be compatible with the Arduino IDE, it
+# should be called the same as the directory name.
+#
+# Alternatively, if you want to manually specify build variables, create a
+# Makefile that defines SOURCES and LIBRARIES and then includes arduino.mk.
+# (There is no need to define TARGET). You can also specify the BOARD here, if
+# the project has a specific one. Here is an example Makefile:
+#
+# SOURCES := main.cc other.cc
+# LIBRARIES := EEPROM
+# BOARD := pro5v
+# include ~/src/arduino.mk
+#
+# Here is a complete list of configuration parameters:
+#
+# ARDUINODIR The path where the Arduino software is installed on your system.
+#
+# ARDUINOCONST The Arduino software version, as an integer, used to define the
+# ARDUINO version constant. This defaults to 100 if undefined.
+#
+# AVRDUDECONF The avrdude.conf to use. If undefined, this defaults to a guess
+# based on where avrdude is. If set empty, no avrdude.conf is
+# passed to avrdude (so the system default is used).
+#
+# AVRDUDEFLAGS Specify any additional flags for avrdude. The usual flags,
+# required to build the project, will be appended to this.
+#
+# AVRTOOLSPATH A space-separated list of directories that is searched in order
+# when looking for the avr build tools. This defaults to PATH,
+# followed by subdirectories in ARDUINODIR.
+#
+# BOARD Specify a target board type. Run `make boards` to see available
+# board types.
+#
+# CPPFLAGS Specify any additional flags for the compiler. The usual flags,
+# required to build the project, will be appended to this.
+#
+# LINKFLAGS Specify any additional flags for the linker. The usual flags,
+# required to build the project, will be appended to this.
+#
+# LIBRARIES A list of Arduino libraries to build and include. This is set
+# automatically if a .ino (or .pde) is found.
+#
+# LIBRARYPATH A space-separated list of directories that is searched in order
+# when looking for Arduino libraries. This defaults to "libs",
+# "libraries" (in the project directory), then your sketchbook
+# "libraries" directory, then the Arduino libraries directory.
+#
+# SERIALDEV The POSIX device name of the serial device that is the Arduino.
+# If unspecified, an attempt is made to guess the name of a
+# connected Arduino's serial device, which may work in some cases.
+#
+# SOURCES A list of all source files of whatever language. The language
+# type is determined by the file extension. This is set
+# automatically if a .ino (or .pde) is found.
+#
+# TARGET The name of the target file. This is set automatically if a
+# .ino (or .pde) is found, but it is not necessary to set it
+# otherwise.
+#
+# This makefile also defines the following goals for use on the command line
+# when you run make:
+#
+# all This is the default if no goal is specified. It builds the
+# target.
+#
+# target Builds the target.
+#
+# upload Uploads the target (building it, as necessary) to an attached
+# Arduino.
+#
+# clean Deletes files created during the build.
+#
+# boards Display a list of available board names, so that you can set the
+# BOARD environment variable appropriately.
+#
+# monitor Start `screen` on the serial device. This is meant to be an
+# equivalent to the Arduino serial monitor.
+#
+# size Displays size information about the built target.
+#
+# bootloader Burns the bootloader for your board to it.
+#
+# <file> Builds the specified file, either an object file or the target,
+# from those that that would be built for the project.
+#_______________________________________________________________________________
+#
+
+# default arduino software directory, check software exists
+ifndef ARDUINODIR
+ARDUINODIR := $(firstword $(wildcard ~/opt/arduino /usr/share/arduino \
+ /Applications/Arduino.app/Contents/Resources/Java \
+ $(HOME)/Applications/Arduino.app/Contents/Resources/Java))
+endif
+ifeq "$(wildcard $(ARDUINODIR)/hardware/arduino/boards.txt)" ""
+$(error ARDUINODIR is not set correctly; arduino software not found)
+endif
+
+# default arduino version
+ARDUINOCONST ?= 100
+
+# default path for avr tools
+AVRTOOLSPATH ?= $(subst :, , $(PATH)) $(ARDUINODIR)/hardware/tools \
+ $(ARDUINODIR)/hardware/tools/avr/bin
+
+# default path to find libraries
+LIBRARYPATH ?= libraries libs $(SKETCHBOOKDIR)/libraries $(ARDUINODIR)/libraries
+
+# default serial device to a poor guess (something that might be an arduino)
+SERIALDEVGUESS := 0
+ifndef SERIALDEV
+SERIALDEV := $(firstword $(wildcard \
+ /dev/ttyACM? /dev/ttyUSB? /dev/tty.usbserial* /dev/tty.usbmodem*))
+SERIALDEVGUESS := 1
+endif
+
+# no board?
+ifndef BOARD
+ifneq "$(MAKECMDGOALS)" "boards"
+ifneq "$(MAKECMDGOALS)" "clean"
+$(error BOARD is unset. Type 'make boards' to see possible values)
+endif
+endif
+endif
+
+# obtain board parameters from the arduino boards.txt file
+BOARDSFILE := $(ARDUINODIR)/hardware/arduino/boards.txt
+readboardsparam = $(shell sed -ne "s/$(BOARD).$(1)=\(.*\)/\1/p" $(BOARDSFILE))
+BOARD_BUILD_MCU := $(call readboardsparam,build.mcu)
+BOARD_BUILD_FCPU := $(call readboardsparam,build.f_cpu)
+BOARD_BUILD_VARIANT := $(call readboardsparam,build.variant)
+BOARD_UPLOAD_SPEED := $(call readboardsparam,upload.speed)
+BOARD_UPLOAD_PROTOCOL := $(call readboardsparam,upload.protocol)
+BOARD_USB_VID := $(call readboardsparam,build.vid)
+BOARD_USB_PID := $(call readboardsparam,build.pid)
+BOARD_BOOTLOADER_UNLOCK := $(call readboardsparam,bootloader.unlock_bits)
+BOARD_BOOTLOADER_LOCK := $(call readboardsparam,bootloader.lock_bits)
+BOARD_BOOTLOADER_LFUSES := $(call readboardsparam,bootloader.low_fuses)
+BOARD_BOOTLOADER_HFUSES := $(call readboardsparam,bootloader.high_fuses)
+BOARD_BOOTLOADER_EFUSES := $(call readboardsparam,bootloader.extended_fuses)
+BOARD_BOOTLOADER_PATH := $(call readboardsparam,bootloader.path)
+BOARD_BOOTLOADER_FILE := $(call readboardsparam,bootloader.file)
+
+# obtain preferences from the IDE's preferences.txt
+PREFERENCESFILE := $(firstword $(wildcard \
+ $(HOME)/.arduino/preferences.txt $(HOME)/Library/Arduino/preferences.txt))
+ifneq "$(PREFERENCESFILE)" ""
+readpreferencesparam = $(shell sed -ne "s/$(1)=\(.*\)/\1/p" $(PREFERENCESFILE))
+SKETCHBOOKDIR := $(call readpreferencesparam,sketchbook.path)
+endif
+
+# invalid board?
+ifeq "$(BOARD_BUILD_MCU)" ""
+ifneq "$(MAKECMDGOALS)" "boards"
+ifneq "$(MAKECMDGOALS)" "clean"
+$(error BOARD is invalid. Type 'make boards' to see possible values)
+endif
+endif
+endif
+
+# auto mode?
+INOFILE := $(wildcard */*.ino */*.pde *.ino *.pde)
+ifdef INOFILE
+ifneq "$(words $(INOFILE))" "1"
+$(error There is more than one .pde or .ino file in this directory!)
+endif
+
+# automatically determine sources and targeet
+TARGET := $(basename $(INOFILE))
+SOURCES := $(INOFILE) \
+ $(wildcard *.c *.cc *.cpp *.C) \
+ $(wildcard $(addprefix util/, *.c *.cc *.cpp *.C)) \
+ $(wildcard $(addprefix utility/, *.c *.cc *.cpp *.C))
+
+# automatically determine included libraries
+LIBRARIES := $(filter $(notdir $(wildcard $(addsuffix /*, $(LIBRARYPATH)))), \
+ $(shell sed -ne "s/^ *\# *include *[<\"]\(.*\)\.h[>\"]/\1/p" $(SOURCES)))
+
+endif
+
+# software
+findsoftware = $(firstword $(wildcard $(addsuffix /$(1), $(AVRTOOLSPATH))))
+CC := $(call findsoftware,avr-gcc)
+CXX := $(call findsoftware,avr-g++)
+LD := $(call findsoftware,avr-ld)
+AR := $(call findsoftware,avr-ar)
+OBJCOPY := $(call findsoftware,avr-objcopy)
+AVRDUDE := $(call findsoftware,avrdude)
+AVRSIZE := $(call findsoftware,avr-size)
+
+# directories
+ARDUINOCOREDIR := $(ARDUINODIR)/hardware/arduino/cores/arduino
+LIBRARYDIRS := $(foreach lib, $(LIBRARIES), \
+ $(firstword $(wildcard $(addsuffix /$(lib), $(LIBRARYPATH)))))
+LIBRARYDIRS += $(addsuffix /utility, $(LIBRARYDIRS))
+
+# files
+TARGET := $(if $(TARGET),$(TARGET),a.out)
+OBJECTS := $(addsuffix .o, $(basename $(SOURCES)))
+DEPFILES := $(patsubst %, .dep/%.dep, $(SOURCES))
+ARDUINOLIB := .lib/arduino.a
+ARDUINOLIBOBJS := $(foreach dir, $(ARDUINOCOREDIR) $(LIBRARYDIRS), \
+ $(patsubst %, .lib/%.o, $(wildcard $(addprefix $(dir)/, *.c *.cpp))))
+BOOTLOADERHEX := $(addprefix \
+ $(ARDUINODIR)/hardware/arduino/bootloaders/$(BOARD_BOOTLOADER_PATH)/, \
+ $(BOARD_BOOTLOADER_FILE))
+
+# avrdude confifuration
+ifeq "$(AVRDUDECONF)" ""
+ifeq "$(AVRDUDE)" "$(ARDUINODIR)/hardware/tools/avr/bin/avrdude"
+AVRDUDECONF := $(ARDUINODIR)/hardware/tools/avr/etc/avrdude.conf
+else
+AVRDUDECONF := $(wildcard $(AVRDUDE).conf)
+endif
+endif
+
+# flags
+CPPFLAGS += -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections
+CPPFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
+CPPFLAGS += -mmcu=$(BOARD_BUILD_MCU)
+CPPFLAGS += -DF_CPU=$(BOARD_BUILD_FCPU) -DARDUINO=$(ARDUINOCONST)
+CPPFLAGS += -DUSB_VID=$(BOARD_USB_VID) -DUSB_PID=$(BOARD_USB_PID)
+CPPFLAGS += -I. -Iutil -Iutility -I $(ARDUINOCOREDIR)
+CPPFLAGS += -I $(ARDUINODIR)/hardware/arduino/variants/$(BOARD_BUILD_VARIANT)/
+CPPFLAGS += $(addprefix -I , $(LIBRARYDIRS))
+CPPDEPFLAGS = -MMD -MP -MF .dep/$<.dep
+CPPINOFLAGS := -x c++ -include $(ARDUINOCOREDIR)/Arduino.h
+AVRDUDEFLAGS += $(addprefix -C , $(AVRDUDECONF)) -DV
+AVRDUDEFLAGS += -p $(BOARD_BUILD_MCU) -P $(SERIALDEV)
+AVRDUDEFLAGS += -c $(BOARD_UPLOAD_PROTOCOL) -b $(BOARD_UPLOAD_SPEED)
+LINKFLAGS += -Os -Wl,--gc-sections -mmcu=$(BOARD_BUILD_MCU)
+
+# figure out which arg to use with stty (for OS X, GNU and busybox stty)
+STTYFARG := $(shell stty --help 2>&1 | \
+ grep -q 'illegal option' && echo -f || echo -F)
+
+# include dependencies
+ifneq "$(MAKECMDGOALS)" "clean"
+-include $(DEPFILES)
+endif
+
+# default rule
+.DEFAULT_GOAL := all
+
+#_______________________________________________________________________________
+# RULES
+
+.PHONY: all target upload clean boards monitor size bootloader
+
+all: target
+
+target: $(TARGET).hex
+
+upload: target
+ @echo "\nUploading to board..."
+ @test -n "$(SERIALDEV)" || { \
+ echo "error: SERIALDEV could not be determined automatically." >&2; \
+ exit 1; }
+ @test 0 -eq $(SERIALDEVGUESS) || { \
+ echo "*GUESSING* at serial device:" $(SERIALDEV); \
+ echo; }
+ifeq "$(BOARD_BOOTLOADER_PATH)" "caterina"
+ stty $(STTYFARG) $(SERIALDEV) speed 1200
+ sleep 1
+else
+ stty $(STTYFARG) $(SERIALDEV) hupcl
+endif
+ $(AVRDUDE) $(AVRDUDEFLAGS) -U flash:w:$(TARGET).hex:i
+
+clean:
+ rm -f $(OBJECTS)
+ rm -f $(TARGET).elf $(TARGET).hex $(ARDUINOLIB) *~
+ rm -rf .lib .dep
+
+boards:
+ @echo "Available values for BOARD:"
+ @sed -nEe '/^#/d; /^[^.]+\.name=/p' $(BOARDSFILE) | \
+ sed -Ee 's/([^.]+)\.name=(.*)/\1 \2/' \
+ -e 's/(.{12}) *(.*)/\1 \2/'
+
+monitor:
+ @test -n "$(SERIALDEV)" || { \
+ echo "error: SERIALDEV could not be determined automatically." >&2; \
+ exit 1; }
+ @test -n `which screen` || { \
+ echo "error: can't find GNU screen, you might need to install it." >&2 \
+ exit 1; }
+ @test 0 -eq $(SERIALDEVGUESS) || { \
+ echo "*GUESSING* at serial device:" $(SERIALDEV); \
+ echo; }
+ screen $(SERIALDEV)
+
+size: $(TARGET).elf
+ echo && $(AVRSIZE) --format=avr --mcu=$(BOARD_BUILD_MCU) $(TARGET).elf
+
+bootloader:
+ @echo "Burning bootloader to board..."
+ @test -n "$(SERIALDEV)" || { \
+ echo "error: SERIALDEV could not be determined automatically." >&2; \
+ exit 1; }
+ @test 0 -eq $(SERIALDEVGUESS) || { \
+ echo "*GUESSING* at serial device:" $(SERIALDEV); \
+ echo; }
+ stty $(STTYFARG) $(SERIALDEV) hupcl
+ $(AVRDUDE) $(AVRDUDEFLAGS) -U lock:w:$(BOARD_BOOTLOADER_UNLOCK):m
+ $(AVRDUDE) $(AVRDUDEFLAGS) -eU lfuse:w:$(BOARD_BOOTLOADER_LFUSES):m
+ $(AVRDUDE) $(AVRDUDEFLAGS) -U hfuse:w:$(BOARD_BOOTLOADER_HFUSES):m
+ifneq "$(BOARD_BOOTLOADER_EFUSES)" ""
+ $(AVRDUDE) $(AVRDUDEFLAGS) -U efuse:w:$(BOARD_BOOTLOADER_EFUSES):m
+endif
+ifneq "$(BOOTLOADERHEX)" ""
+ $(AVRDUDE) $(AVRDUDEFLAGS) -U flash:w:$(BOOTLOADERHEX):i
+endif
+ $(AVRDUDE) $(AVRDUDEFLAGS) -U lock:w:$(BOARD_BOOTLOADER_LOCK):m
+
+# building the target
+
+$(TARGET).hex: $(TARGET).elf
+ $(OBJCOPY) -O ihex -R .eeprom $< $@
+
+.INTERMEDIATE: $(TARGET).elf
+
+$(TARGET).elf: $(ARDUINOLIB) $(OBJECTS)
+ $(CC) $(LINKFLAGS) $(OBJECTS) $(ARDUINOLIB) -lm -o $@
+
+%.o: %.c
+ mkdir -p .dep/$(dir $<)
+ $(COMPILE.c) $(CPPDEPFLAGS) -o $@ $<
+
+%.o: %.cpp
+ mkdir -p .dep/$(dir $<)
+ $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $<
+
+%.o: %.cc
+ mkdir -p .dep/$(dir $<)
+ $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $<
+
+%.o: %.C
+ mkdir -p .dep/$(dir $<)
+ $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $<
+
+%.o: %.ino
+ mkdir -p .dep/$(dir $<)
+ $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $(CPPINOFLAGS) $<
+
+%.o: %.pde
+ mkdir -p .dep/$(dir $<)
+ $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $(CPPINOFLAGS) $<
+
+# building the arduino library
+
+$(ARDUINOLIB): $(ARDUINOLIBOBJS)
+ $(AR) rcs $@ $?
+
+.lib/%.c.o: %.c
+ mkdir -p $(dir $@)
+ $(COMPILE.c) -o $@ $<
+
+.lib/%.cpp.o: %.cpp
+ mkdir -p $(dir $@)
+ $(COMPILE.cpp) -o $@ $<
+
+.lib/%.cc.o: %.cc
+ mkdir -p $(dir $@)
+ $(COMPILE.cpp) -o $@ $<
+
+.lib/%.C.o: %.C
+ mkdir -p $(dir $@)
+ $(COMPILE.cpp) -o $@ $<
+
+# Local Variables:
+# mode: makefile
+# tab-width: 4
+# End:
diff --git a/libraries/EEPROM/EEPROM.cpp b/libraries/EEPROM/EEPROM.cpp
index 06cec10..9c5e18a 100644
--- a/libraries/EEPROM/EEPROM.cpp
+++ b/libraries/EEPROM/EEPROM.cpp
@@ -22,7 +22,7 @@
******************************************************************************/
#include <avr/eeprom.h>
-#include "WConstants.h"
+#include "Arduino.h"
#include "EEPROM.h"
/******************************************************************************
diff --git a/libraries/LiquidCrystal/LiquidCrystal.cpp b/libraries/LiquidCrystal/LiquidCrystal.cpp
index 835d398..32765a8 100644
--- a/libraries/LiquidCrystal/LiquidCrystal.cpp
+++ b/libraries/LiquidCrystal/LiquidCrystal.cpp
@@ -3,7 +3,7 @@
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
-#include "WProgram.h"
+#include "Arduino.h"
// When the display powers up, it is configured as follows:
//
@@ -258,8 +258,9 @@ inline void LiquidCrystal::command(uint8_t value) {
send(value, LOW);
}
-inline void LiquidCrystal::write(uint8_t value) {
+inline size_t LiquidCrystal::write(uint8_t value) {
send(value, HIGH);
+ return 1;
}
/************ low level data pushing commands **********/
diff --git a/libraries/LiquidCrystal/LiquidCrystal.h b/libraries/LiquidCrystal/LiquidCrystal.h
index e6c6bb8..eccce54 100644
--- a/libraries/LiquidCrystal/LiquidCrystal.h
+++ b/libraries/LiquidCrystal/LiquidCrystal.h
@@ -79,7 +79,7 @@ public:
void createChar(uint8_t, uint8_t[]);
void setCursor(uint8_t, uint8_t);
- virtual void write(uint8_t);
+ virtual size_t write(uint8_t);
void command(uint8_t);
private:
void send(uint8_t, uint8_t);
diff --git a/libraries/NewSoftSerial/NewSoftSerial.cpp b/libraries/NewSoftSerial/NewSoftSerial.cpp
index 463ab01..54cb41e 100644
--- a/libraries/NewSoftSerial/NewSoftSerial.cpp
+++ b/libraries/NewSoftSerial/NewSoftSerial.cpp
@@ -36,8 +36,7 @@ http://arduiniana.org.
//
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
-#include "WConstants.h"
-#include "pins_arduino.h"
+#include "Arduino.h"
#include "NewSoftSerial.h"
// Abstractions for maximum portability between processors
@@ -458,10 +457,10 @@ uint8_t NewSoftSerial::available(void)
return (_receive_buffer_tail + _NewSS_MAX_RX_BUFF - _receive_buffer_head) % _NewSS_MAX_RX_BUFF;
}
-void NewSoftSerial::write(uint8_t b)
+size_t NewSoftSerial::write(uint8_t b)
{
if (_tx_delay == 0)
- return;
+ return 0;
activate();
@@ -504,6 +503,8 @@ void NewSoftSerial::write(uint8_t b)
SREG = oldSREG; // turn interrupts back on
tunedDelay(_tx_delay);
+
+ return 1;
}
#if !defined(cbi)
diff --git a/libraries/NewSoftSerial/NewSoftSerial.h b/libraries/NewSoftSerial/NewSoftSerial.h
index 1e39201..dd80c40 100644
--- a/libraries/NewSoftSerial/NewSoftSerial.h
+++ b/libraries/NewSoftSerial/NewSoftSerial.h
@@ -68,7 +68,7 @@ private:
// private methods
void recv();
bool activate();
- virtual void write(uint8_t byte);
+ virtual size_t write(uint8_t byte);
uint8_t rx_pin_read();
void tx_pin_write(uint8_t pin_state);
void setTX(uint8_t transmitPin);
diff --git a/libraries/PWMServo/PWMServo.cpp b/libraries/PWMServo/PWMServo.cpp
index f80b0c8..bc3dd7e 100644
--- a/libraries/PWMServo/PWMServo.cpp
+++ b/libraries/PWMServo/PWMServo.cpp
@@ -1,5 +1,5 @@
#include <avr/interrupt.h>
-#include <wiring.h>
+#include <Arduino.h>
#include <PWMServo.h>
/*
diff --git a/libraries/TinyGPS/TinyGPS.cpp b/libraries/TinyGPS/TinyGPS.cpp
index 15f1614..d4ee60f 100644
--- a/libraries/TinyGPS/TinyGPS.cpp
+++ b/libraries/TinyGPS/TinyGPS.cpp
@@ -19,7 +19,7 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include "WProgram.h"
+#include "Arduino.h"
#include "TinyGPS.h"
#define _GPRMC_TERM "GPRMC"
diff --git a/libraries/TinyGPS/TinyGPS.h b/libraries/TinyGPS/TinyGPS.h
index 7bcb0a7..9c75ad0 100644
--- a/libraries/TinyGPS/TinyGPS.h
+++ b/libraries/TinyGPS/TinyGPS.h
@@ -22,7 +22,7 @@
#ifndef TinyGPS_h
#define TinyGPS_h
-#include "WProgram.h"
+#include "Arduino.h"
#define _GPS_VERSION 10 // software version of this library
#define _GPS_MPH_PER_KNOT 1.15077945