Permalink
Browse files

Added monitor target and AnalogInOutSerial example

  • Loading branch information...
1 parent 72c4fab commit 9c7f173c7b2b494b7ce38e313bfb2604e152f87a Martin Oldfield committed Apr 29, 2012
View
@@ -64,11 +64,15 @@
# provided patches in the same spirit.
#
# 0.9 26.iv.2012 M J Oldfield
-# - Allow the punter to specify boards.txt file
-# and parser independently (after Peplin on github)
+# - Allow the punter to specify boards.txt
+# file and parser independently (after
+# Peplin and Brotchie on github)
# - Support user libraries (Peplin's patch)
# - Remove main.cpp if NO_CORE_MAIN_CPP is
# defined (ex Peplin)
+# - Added a monitor target which talks to the
+# Arduino serial port (Peplin's suggestion)
+#
#
########################################################################
#
@@ -131,6 +135,25 @@
# make reset - reset the Arduino by tickling DTR on the serial port
# make raw_upload - upload without first resetting
# make show_boards - list all the boards defined in boards.txt
+# make monitor - connect to the Arduino's serial port
+#
+########################################################################
+#
+# SERIAL MONITOR
+#
+# The serial monitor just invokes the GNU screen program with suitable
+# options. For more information see screen (1) and search for
+# 'character special device'.
+#
+# The really useful thing to know is that ^A-k gets you out!
+#
+# The fairly useful thing to know is that you can bind another key to
+# escape too, by creating $HOME{.screenrc} containing e.g.
+#
+# bindkey ^C kill
+#
+# If you want to change the baudrate, just set MONITOR_BAUDRATE. If you
+# don't set it, it defaults to 9600 baud.
#
########################################################################
#
@@ -219,6 +242,21 @@ endif
endif
########################################################################
+# Serial monitor (just a screen wrapper)
+#
+# Quite how to construct the monitor command seems intimately tied
+# to the command we're using (here screen). So, read the screen docs
+# for more information (search for 'character special device').
+#
+ifndef MONITOR_BAUDRATE
+MONITOR_BAUDRATE = 9600
+endif
+
+ifndef MONITOR_CMD
+MONITOR_CMD = screen
+endif
+
+########################################################################
# boards.txt parsing
#
ifndef BOARD_TAG
@@ -550,6 +588,9 @@ size: $(OBJDIR) $(TARGET_HEX)
show_boards:
$(PARSE_BOARD_CMD) --boards
-.PHONY: all clean depends upload raw_upload reset size show_boards
+monitor:
+ $(MONITOR_CMD) $(ARD_PORT) $(MONITOR_BAUDRATE)
+
+.PHONY: all clean depends upload raw_upload reset size show_boards monitor
include $(DEP_FILE)
@@ -0,0 +1,53 @@
+/*
+ Analog input, analog output, serial output
+
+ Reads an analog input pin, maps the result to a range from 0 to 255
+ and uses the result to set the pulsewidth modulation (PWM) of an output pin.
+ Also prints the results to the serial monitor.
+
+ The circuit:
+ * potentiometer connected to analog pin 0.
+ Center pin of the potentiometer goes to the analog pin.
+ side pins of the potentiometer go to +5V and ground
+ * LED connected from digital pin 9 to ground
+
+ created 29 Dec. 2008
+ modified 30 Aug 2011
+ by Tom Igoe
+
+ This example code is in the public domain.
+
+ */
+
+// These constants won't change. They're used to give names
+// to the pins used:
+const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
+const int analogOutPin = 9; // Analog output pin that the LED is attached to
+
+int sensorValue = 0; // value read from the pot
+int outputValue = 0; // value output to the PWM (analog out)
+
+void setup() {
+ // initialize serial communications at 9600 bps:
+ Serial.begin(9600);
+}
+
+void loop() {
+ // read the analog in value:
+ sensorValue = analogRead(analogInPin);
+ // map it to the range of the analog out:
+ outputValue = map(sensorValue, 0, 1023, 0, 255);
+ // change the analog out value:
+ analogWrite(analogOutPin, outputValue);
+
+ // print the results to the serial monitor:
+ Serial.print("sensor = " );
+ Serial.print(sensorValue);
+ Serial.print("\t output = ");
+ Serial.println(outputValue);
+
+ // wait 10 milliseconds before the next loop
+ // for the analog-to-digital converter to settle
+ // after the last reading:
+ delay(10);
+}
@@ -0,0 +1,9 @@
+ARDUINO_DIR = /Applications/Arduino.app/Contents/Resources/Java
+PARSE_BOARD = ../../arduino-mk/ard-parse-boards
+
+BOARD_TAG = uno
+ARDUINO_PORT = /dev/cu.usb*
+
+ARDUINO_LIBS =
+
+include ../../arduino-mk/Arduino.mk
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 9c7f173

Please sign in to comment.