mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-20 14:54:31 +01:00
Removing old examples so I can copy over Tom's new ones.
This commit is contained in:
parent
e9e928e03e
commit
8d73929f5d
@ -1,27 +0,0 @@
|
||||
/*
|
||||
* AnalogInput
|
||||
* by DojoDave <http://www.0j0.org>
|
||||
*
|
||||
* Turns on and off a light emitting diode(LED) connected to digital
|
||||
* pin 13. The amount of time the LED will be on and off depends on
|
||||
* the value obtained by analogRead(). In the easiest case we connect
|
||||
* a potentiometer to analog pin 2.
|
||||
*
|
||||
* http://www.arduino.cc/en/Tutorial/AnalogInput
|
||||
*/
|
||||
|
||||
int potPin = 2; // select the input pin for the potentiometer
|
||||
int ledPin = 13; // select the pin for the LED
|
||||
int val = 0; // variable to store the value coming from the sensor
|
||||
|
||||
void setup() {
|
||||
pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT
|
||||
}
|
||||
|
||||
void loop() {
|
||||
val = analogRead(potPin); // read the value from the sensor
|
||||
digitalWrite(ledPin, HIGH); // turn the ledPin on
|
||||
delay(val); // stop the program for some time
|
||||
digitalWrite(ledPin, LOW); // turn the ledPin off
|
||||
delay(val); // stop the program for some time
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Calibration
|
||||
*
|
||||
* Demonstrates one techinque for calibrating sensor input. The
|
||||
* sensor readings during the first five seconds of the sketch
|
||||
* execution define the minimum and maximum of expected values.
|
||||
*/
|
||||
|
||||
int sensorPin = 2;
|
||||
int ledPin = 9;
|
||||
|
||||
int val = 0;
|
||||
int sensorMin = 1023, sensorMax = 0;
|
||||
|
||||
void setup() {
|
||||
// signal the start of the calibration period
|
||||
pinMode(13, OUTPUT);
|
||||
digitalWrite(13, HIGH);
|
||||
|
||||
// calibrate during the first five seconds
|
||||
while (millis() < 5000) {
|
||||
val = analogRead(sensorPin);
|
||||
|
||||
// record the maximum sensor value
|
||||
if (val > sensorMax) {
|
||||
sensorMax = val;
|
||||
}
|
||||
|
||||
// record the minimum sensor value
|
||||
if (val < sensorMin) {
|
||||
sensorMin = val;
|
||||
}
|
||||
}
|
||||
|
||||
// signal the end of the calibration period
|
||||
digitalWrite(13, LOW);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
val = analogRead(sensorPin);
|
||||
|
||||
// apply the calibration to the sensor reading
|
||||
val = map(val, sensorMin, sensorMax, 0, 255);
|
||||
|
||||
// in case the sensor value is outside the range seen during calibration
|
||||
val = constrain(val, 0, 255);
|
||||
|
||||
analogWrite(ledPin, val);
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
// Fading LED
|
||||
// by BARRAGAN <http://people.interaction-ivrea.it/h.barragan>
|
||||
|
||||
int value = 0; // variable to keep the actual value
|
||||
int ledpin = 9; // light connected to digital pin 9
|
||||
|
||||
void setup()
|
||||
{
|
||||
// nothing for setup
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
for(value = 0 ; value <= 255; value+=5) // fade in (from min to max)
|
||||
{
|
||||
analogWrite(ledpin, value); // sets the value (range from 0 to 255)
|
||||
delay(30); // waits for 30 milli seconds to see the dimming effect
|
||||
}
|
||||
for(value = 255; value >=0; value-=5) // fade out (from max to min)
|
||||
{
|
||||
analogWrite(ledpin, value);
|
||||
delay(30);
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Smoothing
|
||||
* David A. Mellis <dam@mellis.org>
|
||||
*
|
||||
* Reads repeatedly from an analog input, calculating a running average
|
||||
* and printing it to the computer.
|
||||
*
|
||||
* http://www.arduino.cc/en/Tutorial/Smoothing
|
||||
*/
|
||||
|
||||
// Define the number of samples to keep track of. The higher the number,
|
||||
// the more the readings will be smoothed, but the slower the output will
|
||||
// respond to the input. Using a #define rather than a normal variable lets
|
||||
// use this value to determine the size of the readings array.
|
||||
#define NUMREADINGS 10
|
||||
|
||||
int readings[NUMREADINGS]; // the readings from the analog input
|
||||
int index = 0; // the index of the current reading
|
||||
int total = 0; // the running total
|
||||
int average = 0; // the average
|
||||
|
||||
int inputPin = 0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600); // initialize serial communication with computer
|
||||
for (int i = 0; i < NUMREADINGS; i++)
|
||||
readings[i] = 0; // initialize all the readings to 0
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
total -= readings[index]; // subtract the last reading
|
||||
readings[index] = analogRead(inputPin); // read from the sensor
|
||||
total += readings[index]; // add the reading to the total
|
||||
index = (index + 1); // advance to the next index
|
||||
|
||||
if (index >= NUMREADINGS) // if we're at the end of the array...
|
||||
index = 0; // ...wrap around to the beginning
|
||||
|
||||
average = total / NUMREADINGS; // calculate the average
|
||||
Serial.println(average); // send it to the computer (as ASCII digits)
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
/*
|
||||
ASCII table
|
||||
|
||||
Prints out byte values in all possible formats:
|
||||
* as raw binary values
|
||||
* as ASCII-encoded decimal, hex, octal, and binary values
|
||||
|
||||
For more on ASCII, see http://www.asciitable.com and http://en.wikipedia.org/wiki/ASCII
|
||||
|
||||
The circuit: No external hardware needed.
|
||||
|
||||
created 2006
|
||||
by Nicholas Zambetti
|
||||
modified 18 Jan 2009
|
||||
by Tom Igoe
|
||||
|
||||
<http://www.zambetti.com>
|
||||
*/
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
|
||||
// prints title with ending line break
|
||||
Serial.println("ASCII Table ~ Character Map");
|
||||
}
|
||||
|
||||
// first visible ASCIIcharacter '!' is number 33:
|
||||
int thisByte = 33;
|
||||
// you can also write ASCII characters in single quotes.
|
||||
// for example. '!' is the same as 33, so you could also use this:
|
||||
//int thisByte = '!';
|
||||
|
||||
void loop()
|
||||
{
|
||||
// prints value unaltered, i.e. the raw binary version of the
|
||||
// byte. The serial monitor interprets all bytes as
|
||||
// ASCII, so 33, the first number, will show up as '!'
|
||||
Serial.print(thisByte, BYTE);
|
||||
|
||||
Serial.print(", dec: ");
|
||||
// prints value as string as an ASCII-encoded decimal (base 10).
|
||||
// Decimal is the default format for Serial.print() and Serial.println(),
|
||||
// so no modifier is needed:
|
||||
Serial.print(thisByte);
|
||||
// But you can declare the modifier for decimal if you want to.
|
||||
//this also works if you uncomment it:
|
||||
|
||||
// Serial.print(thisByte, DEC);
|
||||
|
||||
|
||||
Serial.print(", hex: ");
|
||||
// prints value as string in hexadecimal (base 16):
|
||||
Serial.print(thisByte, HEX);
|
||||
|
||||
Serial.print(", oct: ");
|
||||
// prints value as string in octal (base 8);
|
||||
Serial.print(thisByte, OCT);
|
||||
|
||||
Serial.print(", bin: ");
|
||||
// prints value as string in binary (base 2)
|
||||
// also prints ending line break:
|
||||
Serial.println(thisByte, BIN);
|
||||
|
||||
// if printed last visible character '~' or 126, stop:
|
||||
if(thisByte == 126) { // you could also use if (thisByte == '~') {
|
||||
// This loop loops forever and does nothing
|
||||
while(true) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// go on to the next character
|
||||
thisByte++;
|
||||
}
|
@ -1,360 +0,0 @@
|
||||
/*
|
||||
Dimmer
|
||||
|
||||
Demonstrates the sending data from the computer to the Arduino board,
|
||||
in this case to control the brightness of an LED. The data is sent
|
||||
in individual bytes, each of which ranges from 0 to 255. Arduino
|
||||
reads these bytes and uses them to set the brightness of the LED.
|
||||
|
||||
The circuit:
|
||||
LED attached from digital pin 9 to ground.
|
||||
Serial connection to Processing, Max/MSP, or another serial application
|
||||
|
||||
created 2006
|
||||
by David A. Mellis
|
||||
modified 14 Apr 2009
|
||||
by Tom Igoe and Scott Fitzgerald
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/Dimmer
|
||||
*/
|
||||
|
||||
const int ledPin = 9; // the pin that the LED is attached to
|
||||
|
||||
void setup()
|
||||
{
|
||||
// initialize the serial communication:
|
||||
Serial.begin(9600);
|
||||
// initialize the ledPin as an output:
|
||||
pinMode(ledPin, OUTPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
byte brightness;
|
||||
|
||||
// check if data has been sent from the computer:
|
||||
if (Serial.available()) {
|
||||
// read the most recent byte (which will be from 0 to 255):
|
||||
brightness = Serial.read();
|
||||
// set the brightness of the LED:
|
||||
analogWrite(ledPin, brightness);
|
||||
}
|
||||
}
|
||||
|
||||
/* Processing code for this example
|
||||
// Dimmer - sends bytes over a serial port
|
||||
// by David A. Mellis
|
||||
|
||||
import processing.serial.*;
|
||||
Serial port;
|
||||
|
||||
void setup() {
|
||||
size(256, 150);
|
||||
|
||||
println("Available serial ports:");
|
||||
println(Serial.list());
|
||||
|
||||
// Uses the first port in this list (number 0). Change this to
|
||||
// select the port corresponding to your Arduino board. The last
|
||||
// parameter (e.g. 9600) is the speed of the communication. It
|
||||
// has to correspond to the value passed to Serial.begin() in your
|
||||
// Arduino sketch.
|
||||
port = new Serial(this, Serial.list()[0], 9600);
|
||||
|
||||
// If you know the name of the port used by the Arduino board, you
|
||||
// can specify it directly like this.
|
||||
//port = new Serial(this, "COM1", 9600);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
// draw a gradient from black to white
|
||||
for (int i = 0; i < 256; i++) {
|
||||
stroke(i);
|
||||
line(i, 0, i, 150);
|
||||
}
|
||||
|
||||
// write the current X-position of the mouse to the serial port as
|
||||
// a single byte
|
||||
port.write(mouseX);
|
||||
}
|
||||
*/
|
||||
|
||||
/* Max/MSP v5 patch for this example
|
||||
|
||||
{
|
||||
"boxes" : [ {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "Dimmer\n\nThis patch sends a binary number from 0 to 255 out the serial port to an Arduino connected to the port. It dims an LED attached to the Arduino.\n\ncreated 2006\nby David A. Mellis\nmodified 14 Apr 2009\nby Scott Fitzgerald and Tom Igoe",
|
||||
"linecount" : 10,
|
||||
"patching_rect" : [ 209.0, 55.0, 344.0, 144.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-32",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "change the slider to alter the brightness of the LED",
|
||||
"linecount" : 3,
|
||||
"patching_rect" : [ 90.0, 235.0, 117.0, 48.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-7",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "number",
|
||||
"patching_rect" : [ 215.0, 385.0, 50.0, 19.0 ],
|
||||
"numoutlets" : 2,
|
||||
"fontsize" : 10.0,
|
||||
"outlettype" : [ "int", "bang" ],
|
||||
"id" : "obj-6",
|
||||
"fontname" : "Verdana",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "slider",
|
||||
"patching_rect" : [ 215.0, 235.0, 20.0, 140.0 ],
|
||||
"numoutlets" : 1,
|
||||
"outlettype" : [ "" ],
|
||||
"bgcolor" : [ 0.94902, 0.94902, 0.94902, 0.0 ],
|
||||
"id" : "obj-1",
|
||||
"size" : 256.0,
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "select 0 1",
|
||||
"patching_rect" : [ 342.0, 305.0, 62.0, 20.0 ],
|
||||
"numoutlets" : 3,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "bang", "bang", "" ],
|
||||
"id" : "obj-30",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "click here to close the serial port",
|
||||
"patching_rect" : [ 390.0, 396.0, 206.0, 20.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-26",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "click here to open the serial port",
|
||||
"patching_rect" : [ 415.0, 370.0, 206.0, 20.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-27",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "message",
|
||||
"text" : "close",
|
||||
"patching_rect" : [ 342.0, 396.0, 39.0, 18.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "" ],
|
||||
"id" : "obj-21",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "message",
|
||||
"text" : "port a",
|
||||
"patching_rect" : [ 364.0, 370.0, 41.0, 18.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "" ],
|
||||
"id" : "obj-19",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "Click here to get a list of serial ports",
|
||||
"patching_rect" : [ 435.0, 344.0, 207.0, 20.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-2",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "toggle",
|
||||
"patching_rect" : [ 342.0, 268.0, 15.0, 15.0 ],
|
||||
"numoutlets" : 1,
|
||||
"outlettype" : [ "int" ],
|
||||
"id" : "obj-11",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "message",
|
||||
"text" : "print",
|
||||
"patching_rect" : [ 384.0, 344.0, 36.0, 18.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "" ],
|
||||
"id" : "obj-13",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "serial a 9600",
|
||||
"patching_rect" : [ 259.0, 420.0, 84.0, 20.0 ],
|
||||
"numoutlets" : 2,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "int", "" ],
|
||||
"id" : "obj-14",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "Click to start",
|
||||
"patching_rect" : [ 369.0, 268.0, 117.0, 20.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-17",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "panel",
|
||||
"patching_rect" : [ 215.0, 235.0, 21.0, 139.0 ],
|
||||
"numoutlets" : 0,
|
||||
"mode" : 1,
|
||||
"grad1" : [ 1.0, 1.0, 1.0, 1.0 ],
|
||||
"id" : "obj-8",
|
||||
"grad2" : [ 0.509804, 0.509804, 0.509804, 1.0 ],
|
||||
"numinlets" : 1,
|
||||
"angle" : 270.0
|
||||
}
|
||||
|
||||
}
|
||||
],
|
||||
"lines" : [ {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-11", 0 ],
|
||||
"destination" : [ "obj-30", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 351.0, 296.0, 351.5, 296.0 ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-30", 1 ],
|
||||
"destination" : [ "obj-19", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-30", 0 ],
|
||||
"destination" : [ "obj-21", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-21", 0 ],
|
||||
"destination" : [ "obj-14", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 351.5, 416.5, 268.5, 416.5 ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-19", 0 ],
|
||||
"destination" : [ "obj-14", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 373.5, 393.5, 268.5, 393.5 ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-13", 0 ],
|
||||
"destination" : [ "obj-14", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 393.5, 365.5, 268.5, 365.5 ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-1", 0 ],
|
||||
"destination" : [ "obj-6", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-6", 0 ],
|
||||
"destination" : [ "obj-14", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 224.5, 411.5, 268.5, 411.5 ]
|
||||
}
|
||||
|
||||
}
|
||||
]
|
||||
}
|
||||
*/
|
@ -1,578 +0,0 @@
|
||||
/*
|
||||
Graph
|
||||
|
||||
A simple example of communication from the Arduino board to the computer:
|
||||
the value of analog input 0 is sent out the serial port. We call this "serial"
|
||||
communication because the connection appears to both the Arduino and the
|
||||
computer as a serial port, even though it may actually use
|
||||
a USB cable. Bytes are sent one after another (serially) from the Arduino
|
||||
to the computer.
|
||||
|
||||
You can use the Arduino serial monitor to view the sent data, or it can
|
||||
be read by Processing, PD, Max/MSP, or any other program capable of reading
|
||||
data from a serial port. The Processing code below graphs the data received
|
||||
so you can see the value of the analog input changing over time.
|
||||
|
||||
The circuit:
|
||||
Any analog input sensor is attached to analog in pin 0.
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/Graph
|
||||
|
||||
created 2006
|
||||
by David A. Mellis
|
||||
modified 14 Apr 2009
|
||||
by Tom Igoe and Scott Fitzgerald
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/Graph
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
// initialize the serial communication:
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// send the value of analog input 0:
|
||||
Serial.println(analogRead(0));
|
||||
// wait a bit for the analog-to-digital converter
|
||||
// to stabilize after the last reading:
|
||||
delay(10);
|
||||
}
|
||||
|
||||
/* Processing code for this example
|
||||
|
||||
// Graphing sketch
|
||||
|
||||
|
||||
// This program takes ASCII-encoded strings
|
||||
// from the serial port at 9600 baud and graphs them. It expects values in the
|
||||
// range 0 to 1023, followed by a newline, or newline and carriage return
|
||||
|
||||
// Created 20 Apr 2005
|
||||
// Updated 18 Jan 2008
|
||||
// by Tom Igoe
|
||||
|
||||
import processing.serial.*;
|
||||
|
||||
Serial myPort; // The serial port
|
||||
int xPos = 1; // horizontal position of the graph
|
||||
|
||||
void setup () {
|
||||
// set the window size:
|
||||
size(400, 300);
|
||||
|
||||
// List all the available serial ports
|
||||
println(Serial.list());
|
||||
// I know that the first port in the serial list on my mac
|
||||
// is always my Arduino, so I open Serial.list()[0].
|
||||
// Open whatever port is the one you're using.
|
||||
myPort = new Serial(this, Serial.list()[0], 9600);
|
||||
// don't generate a serialEvent() unless you get a newline character:
|
||||
myPort.bufferUntil('\n');
|
||||
// set inital background:
|
||||
background(0);
|
||||
}
|
||||
void draw () {
|
||||
// everything happens in the serialEvent()
|
||||
}
|
||||
|
||||
void serialEvent (Serial myPort) {
|
||||
// get the ASCII string:
|
||||
String inString = myPort.readStringUntil('\n');
|
||||
|
||||
if (inString != null) {
|
||||
// trim off any whitespace:
|
||||
inString = trim(inString);
|
||||
// convert to an int and map to the screen height:
|
||||
float inByte = float(inString);
|
||||
inByte = map(inByte, 0, 1023, 0, height);
|
||||
|
||||
// draw the line:
|
||||
stroke(127,34,255);
|
||||
line(xPos, height, xPos, height - inByte);
|
||||
|
||||
// at the edge of the screen, go back to the beginning:
|
||||
if (xPos >= width) {
|
||||
xPos = 0;
|
||||
background(0);
|
||||
}
|
||||
else {
|
||||
// increment the horizontal position:
|
||||
xPos++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
/* Max/MSP v5 patch for this example
|
||||
{
|
||||
"boxes" : [ {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "Graph\n\nThis patch takes a string, containing ASCII formatted number from 0 to 1023, with a carriage return and linefeed at the end. It converts the string to an integer and graphs it.\n\ncreated 2006\nby David A. Mellis\nmodified 14 Apr 2009\nby Scott Fitzgerald and Tom Igoe",
|
||||
"linecount" : 10,
|
||||
"patching_rect" : [ 479.0, 6.0, 344.0, 144.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-32",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "select 0 1",
|
||||
"patching_rect" : [ 327.0, 80.0, 62.0, 20.0 ],
|
||||
"numoutlets" : 3,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "bang", "bang", "" ],
|
||||
"id" : "obj-30",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "click here to close the serial port",
|
||||
"patching_rect" : [ 412.0, 231.0, 206.0, 20.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-26",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "click here to open the serial port",
|
||||
"patching_rect" : [ 412.0, 205.0, 206.0, 20.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-27",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "message",
|
||||
"text" : "close",
|
||||
"patching_rect" : [ 327.0, 231.0, 39.0, 18.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "" ],
|
||||
"id" : "obj-21",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "message",
|
||||
"text" : "port a",
|
||||
"patching_rect" : [ 349.0, 205.0, 41.0, 18.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "" ],
|
||||
"id" : "obj-19",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "multislider",
|
||||
"candicane7" : [ 0.878431, 0.243137, 0.145098, 1.0 ],
|
||||
"patching_rect" : [ 302.0, 450.0, 246.0, 167.0 ],
|
||||
"contdata" : 1,
|
||||
"numoutlets" : 2,
|
||||
"peakcolor" : [ 0.498039, 0.498039, 0.498039, 1.0 ],
|
||||
"slidercolor" : [ 0.066667, 0.058824, 0.776471, 1.0 ],
|
||||
"candicane8" : [ 0.027451, 0.447059, 0.501961, 1.0 ],
|
||||
"outlettype" : [ "", "" ],
|
||||
"setminmax" : [ 0.0, 1023.0 ],
|
||||
"settype" : 0,
|
||||
"candicane6" : [ 0.733333, 0.035294, 0.788235, 1.0 ],
|
||||
"setstyle" : 3,
|
||||
"bgcolor" : [ 0.231373, 0.713726, 1.0, 1.0 ],
|
||||
"id" : "obj-1",
|
||||
"candicane4" : [ 0.439216, 0.619608, 0.070588, 1.0 ],
|
||||
"candicane5" : [ 0.584314, 0.827451, 0.431373, 1.0 ],
|
||||
"candicane2" : [ 0.145098, 0.203922, 0.356863, 1.0 ],
|
||||
"candicane3" : [ 0.290196, 0.411765, 0.713726, 1.0 ],
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "Click here to get a list of serial ports",
|
||||
"patching_rect" : [ 412.0, 179.0, 207.0, 20.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-2",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "Here's the number from Arduino's analog input",
|
||||
"linecount" : 2,
|
||||
"patching_rect" : [ 153.0, 409.0, 138.0, 34.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-3",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "Convert ASCII to symbol",
|
||||
"patching_rect" : [ 379.0, 378.0, 147.0, 20.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-4",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "Convert integer to ASCII",
|
||||
"patching_rect" : [ 379.0, 355.0, 147.0, 20.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-5",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "number",
|
||||
"patching_rect" : [ 302.0, 414.0, 37.0, 20.0 ],
|
||||
"numoutlets" : 2,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "int", "bang" ],
|
||||
"bgcolor" : [ 0.866667, 0.866667, 0.866667, 1.0 ],
|
||||
"id" : "obj-6",
|
||||
"triscale" : 0.9,
|
||||
"fontname" : "Arial",
|
||||
"htextcolor" : [ 0.870588, 0.870588, 0.870588, 1.0 ],
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "fromsymbol",
|
||||
"patching_rect" : [ 302.0, 378.0, 74.0, 20.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "" ],
|
||||
"id" : "obj-7",
|
||||
"fontname" : "Arial",
|
||||
"color" : [ 1.0, 0.890196, 0.090196, 1.0 ],
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "itoa",
|
||||
"patching_rect" : [ 302.0, 355.0, 46.0, 20.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "int" ],
|
||||
"id" : "obj-8",
|
||||
"fontname" : "Arial",
|
||||
"color" : [ 1.0, 0.890196, 0.090196, 1.0 ],
|
||||
"numinlets" : 3
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "zl group 4",
|
||||
"patching_rect" : [ 302.0, 332.0, 64.0, 20.0 ],
|
||||
"numoutlets" : 2,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "", "" ],
|
||||
"id" : "obj-9",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "select 10 13",
|
||||
"patching_rect" : [ 244.0, 281.0, 77.0, 20.0 ],
|
||||
"numoutlets" : 3,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "bang", "bang", "" ],
|
||||
"id" : "obj-10",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "toggle",
|
||||
"patching_rect" : [ 244.0, 43.0, 15.0, 15.0 ],
|
||||
"numoutlets" : 1,
|
||||
"outlettype" : [ "int" ],
|
||||
"id" : "obj-11",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "qmetro 10",
|
||||
"patching_rect" : [ 244.0, 80.0, 65.0, 20.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "bang" ],
|
||||
"id" : "obj-12",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "message",
|
||||
"text" : "print",
|
||||
"patching_rect" : [ 369.0, 179.0, 36.0, 18.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "" ],
|
||||
"id" : "obj-13",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "serial a 9600",
|
||||
"patching_rect" : [ 244.0, 255.0, 84.0, 20.0 ],
|
||||
"numoutlets" : 2,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "int", "" ],
|
||||
"id" : "obj-14",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "Read serial input buffer every 10 milliseconds",
|
||||
"linecount" : 2,
|
||||
"patching_rect" : [ 53.0, 72.0, 185.0, 34.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-15",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "If you get newline (ASCII 10), send the list. If you get return (ASCII 13) do nothing. Any other value, add to the list",
|
||||
"linecount" : 3,
|
||||
"patching_rect" : [ 332.0, 269.0, 320.0, 48.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-16",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "Click to open/close serial port and start/stop patch",
|
||||
"linecount" : 2,
|
||||
"patching_rect" : [ 271.0, 32.0, 199.0, 34.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-17",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
],
|
||||
"lines" : [ {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-6", 0 ],
|
||||
"destination" : [ "obj-1", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-7", 0 ],
|
||||
"destination" : [ "obj-6", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-8", 0 ],
|
||||
"destination" : [ "obj-7", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-9", 0 ],
|
||||
"destination" : [ "obj-8", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-10", 0 ],
|
||||
"destination" : [ "obj-9", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 253.5, 308.0, 311.5, 308.0 ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-10", 2 ],
|
||||
"destination" : [ "obj-9", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 311.5, 320.0, 311.5, 320.0 ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-14", 0 ],
|
||||
"destination" : [ "obj-10", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-12", 0 ],
|
||||
"destination" : [ "obj-14", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-11", 0 ],
|
||||
"destination" : [ "obj-12", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-13", 0 ],
|
||||
"destination" : [ "obj-14", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 378.5, 200.5, 253.5, 200.5 ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-19", 0 ],
|
||||
"destination" : [ "obj-14", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 358.5, 228.5, 253.5, 228.5 ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-21", 0 ],
|
||||
"destination" : [ "obj-14", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 336.5, 251.5, 253.5, 251.5 ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-30", 0 ],
|
||||
"destination" : [ "obj-21", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-30", 1 ],
|
||||
"destination" : [ "obj-19", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-11", 0 ],
|
||||
"destination" : [ "obj-30", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 253.0, 71.0, 336.5, 71.0 ]
|
||||
}
|
||||
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
*/
|
@ -1,707 +0,0 @@
|
||||
/*
|
||||
Physical Pixel
|
||||
|
||||
An example of using the Arduino board to receive data from the
|
||||
computer. In this case, the Arduino boards turns on an LED when
|
||||
it receives the character 'H', and turns off the LED when it
|
||||
receives the character 'L'.
|
||||
|
||||
The data can be sent from the Arduino serial monitor, or another
|
||||
program like Processing (see code below), Flash (via a serial-net
|
||||
proxy), PD, or Max/MSP.
|
||||
|
||||
The circuit:
|
||||
* LED connected from digital pin 13 to ground
|
||||
|
||||
created 2006
|
||||
by David A. Mellis
|
||||
modified 14 Apr 2009
|
||||
by Tom Igoe and Scott Fitzgerald
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/PhysicalPixel
|
||||
*/
|
||||
|
||||
const int ledPin = 13; // the pin that the LED is attached to
|
||||
int incomingByte; // a variable to read incoming serial data into
|
||||
|
||||
void setup() {
|
||||
// initialize serial communication:
|
||||
Serial.begin(9600);
|
||||
// initialize the LED pin as an output:
|
||||
pinMode(ledPin, OUTPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// see if there's incoming serial data:
|
||||
if (Serial.available() > 0) {
|
||||
// read the oldest byte in the serial buffer:
|
||||
incomingByte = Serial.read();
|
||||
// if it's a capital H (ASCII 72), turn on the LED:
|
||||
if (incomingByte == 'H') {
|
||||
digitalWrite(ledPin, HIGH);
|
||||
}
|
||||
// if it's an L (ASCII 76) turn off the LED:
|
||||
if (incomingByte == 'L') {
|
||||
digitalWrite(ledPin, LOW);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Processing code for this example
|
||||
|
||||
// mouseover serial
|
||||
|
||||
// Demonstrates how to send data to the Arduino I/O board, in order to
|
||||
// turn ON a light if the mouse is over a square and turn it off
|
||||
// if the mouse is not.
|
||||
|
||||
// created 2003-4
|
||||
// based on examples by Casey Reas and Hernando Barragan
|
||||
// modified 18 Jan 2009
|
||||
// by Tom Igoe
|
||||
|
||||
|
||||
import processing.serial.*;
|
||||
|
||||
float boxX;
|
||||
float boxY;
|
||||
int boxSize = 20;
|
||||
boolean mouseOverBox = false;
|
||||
|
||||
Serial port;
|
||||
|
||||
void setup() {
|
||||
size(200, 200);
|
||||
boxX = width/2.0;
|
||||
boxY = height/2.0;
|
||||
rectMode(RADIUS);
|
||||
|
||||
// List all the available serial ports in the output pane.
|
||||
// You will need to choose the port that the Arduino board is
|
||||
// connected to from this list. The first port in the list is
|
||||
// port #0 and the third port in the list is port #2.
|
||||
println(Serial.list());
|
||||
|
||||
// Open the port that the Arduino board is connected to (in this case #0)
|
||||
// Make sure to open the port at the same speed Arduino is using (9600bps)
|
||||
port = new Serial(this, Serial.list()[0], 9600);
|
||||
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(0);
|
||||
|
||||
// Test if the cursor is over the box
|
||||
if (mouseX > boxX-boxSize && mouseX < boxX+boxSize &&
|
||||
mouseY > boxY-boxSize && mouseY < boxY+boxSize) {
|
||||
mouseOverBox = true;
|
||||
// draw a line around the box and change its color:
|
||||
stroke(255);
|
||||
fill(153);
|
||||
// send an 'H' to indicate mouse is over square:
|
||||
port.write('H');
|
||||
}
|
||||
else {
|
||||
// return the box to it's inactive state:
|
||||
stroke(153);
|
||||
fill(153);
|
||||
// send an 'L' to turn the LED off:
|
||||
port.write('L');
|
||||
mouseOverBox = false;
|
||||
}
|
||||
|
||||
// Draw the box
|
||||
rect(boxX, boxY, boxSize, boxSize);
|
||||
}
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
{
|
||||
"boxes" : [ {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "Physical Pixel\n\nThis patch sends an ASCII H or an ASCII L out the serial port to turn on an LED attached to an Arduino board. It can also send alternating H and L characters once every second to make the LED blink.\n\ncreated 2006\nby David A. Mellis\nmodified 14 Apr 2009\nby Scott Fitzgerald and Tom Igoe",
|
||||
"linecount" : 11,
|
||||
"patching_rect" : [ 14.0, 35.0, 354.0, 158.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-1",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "Click to blink every second",
|
||||
"patching_rect" : [ 99.0, 251.0, 161.0, 20.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-38",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "toggle",
|
||||
"patching_rect" : [ 74.0, 251.0, 21.0, 21.0 ],
|
||||
"numoutlets" : 1,
|
||||
"outlettype" : [ "int" ],
|
||||
"id" : "obj-39",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "p blink",
|
||||
"patching_rect" : [ 74.0, 286.0, 45.0, 20.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "int" ],
|
||||
"id" : "obj-37",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2,
|
||||
"patcher" : {
|
||||
"fileversion" : 1,
|
||||
"rect" : [ 54.0, 94.0, 640.0, 480.0 ],
|
||||
"bglocked" : 0,
|
||||
"defrect" : [ 54.0, 94.0, 640.0, 480.0 ],
|
||||
"openrect" : [ 0.0, 0.0, 0.0, 0.0 ],
|
||||
"openinpresentation" : 0,
|
||||
"default_fontsize" : 10.0,
|
||||
"default_fontface" : 0,
|
||||
"default_fontname" : "Verdana",
|
||||
"gridonopen" : 0,
|
||||
"gridsize" : [ 25.0, 25.0 ],
|
||||
"gridsnaponopen" : 0,
|
||||
"toolbarvisible" : 1,
|
||||
"boxanimatetime" : 200,
|
||||
"imprint" : 0,
|
||||
"boxes" : [ {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "* 1000",
|
||||
"patching_rect" : [ 200.0, 150.0, 46.0, 19.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 10.0,
|
||||
"outlettype" : [ "int" ],
|
||||
"id" : "obj-12",
|
||||
"fontname" : "Verdana",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "inlet",
|
||||
"patching_rect" : [ 200.0, 75.0, 25.0, 25.0 ],
|
||||
"numoutlets" : 1,
|
||||
"outlettype" : [ "" ],
|
||||
"id" : "obj-11",
|
||||
"numinlets" : 0,
|
||||
"comment" : ""
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "toggle",
|
||||
"patching_rect" : [ 125.0, 250.0, 20.0, 20.0 ],
|
||||
"numoutlets" : 1,
|
||||
"outlettype" : [ "int" ],
|
||||
"id" : "obj-10",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "metro 1000",
|
||||
"patching_rect" : [ 115.0, 190.0, 69.0, 19.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 10.0,
|
||||
"outlettype" : [ "bang" ],
|
||||
"id" : "obj-3",
|
||||
"fontname" : "Verdana",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "outlet",
|
||||
"patching_rect" : [ 125.0, 400.0, 25.0, 25.0 ],
|
||||
"numoutlets" : 0,
|
||||
"id" : "obj-2",
|
||||
"numinlets" : 1,
|
||||
"comment" : ""
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "inlet",
|
||||
"patching_rect" : [ 100.0, 25.0, 25.0, 25.0 ],
|
||||
"numoutlets" : 1,
|
||||
"outlettype" : [ "int" ],
|
||||
"id" : "obj-1",
|
||||
"numinlets" : 0,
|
||||
"comment" : ""
|
||||
}
|
||||
|
||||
}
|
||||
],
|
||||
"lines" : [ {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-12", 0 ],
|
||||
"destination" : [ "obj-3", 1 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-11", 0 ],
|
||||
"destination" : [ "obj-12", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-1", 0 ],
|
||||
"destination" : [ "obj-3", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-10", 0 ],
|
||||
"destination" : [ "obj-2", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-3", 0 ],
|
||||
"destination" : [ "obj-10", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
]
|
||||
}
|
||||
,
|
||||
"saved_object_attributes" : {
|
||||
"fontface" : 0,
|
||||
"fontsize" : 10.0,
|
||||
"default_fontface" : 0,
|
||||
"default_fontname" : "Verdana",
|
||||
"default_fontsize" : 10.0,
|
||||
"fontname" : "Verdana",
|
||||
"globalpatchername" : ""
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "convert to int",
|
||||
"patching_rect" : [ 154.0, 386.0, 104.0, 20.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-36",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "send L if 0, H if 1",
|
||||
"patching_rect" : [ 154.0, 361.0, 104.0, 20.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-35",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "is it on or off?",
|
||||
"patching_rect" : [ 179.0, 336.0, 95.0, 20.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-34",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "atoi",
|
||||
"patching_rect" : [ 279.0, 386.0, 46.0, 20.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "list" ],
|
||||
"id" : "obj-33",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 3
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "message",
|
||||
"text" : "H",
|
||||
"patching_rect" : [ 329.0, 361.0, 32.5, 17.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 10.0,
|
||||
"outlettype" : [ "" ],
|
||||
"id" : "obj-32",
|
||||
"fontname" : "Verdana",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "message",
|
||||
"text" : "L",
|
||||
"patching_rect" : [ 279.0, 361.0, 32.5, 17.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 10.0,
|
||||
"outlettype" : [ "" ],
|
||||
"id" : "obj-31",
|
||||
"fontname" : "Verdana",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "select 0 1",
|
||||
"patching_rect" : [ 279.0, 336.0, 62.0, 20.0 ],
|
||||
"numoutlets" : 3,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "bang", "bang", "" ],
|
||||
"id" : "obj-25",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "Click to turn the LED on and off",
|
||||
"linecount" : 2,
|
||||
"patching_rect" : [ 130.0, 205.0, 143.0, 34.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-24",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "toggle",
|
||||
"patching_rect" : [ 279.0, 211.0, 24.0, 24.0 ],
|
||||
"numoutlets" : 1,
|
||||
"outlettype" : [ "int" ],
|
||||
"id" : "obj-23",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "select 0 1",
|
||||
"patching_rect" : [ 381.0, 331.0, 62.0, 20.0 ],
|
||||
"numoutlets" : 3,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "bang", "bang", "" ],
|
||||
"id" : "obj-30",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "click here to close the serial port",
|
||||
"patching_rect" : [ 429.0, 422.0, 206.0, 20.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-26",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "click here to open the serial port",
|
||||
"patching_rect" : [ 454.0, 396.0, 206.0, 20.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-27",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "message",
|
||||
"text" : "close",
|
||||
"patching_rect" : [ 381.0, 422.0, 39.0, 18.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "" ],
|
||||
"id" : "obj-21",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "message",
|
||||
"text" : "port a",
|
||||
"patching_rect" : [ 403.0, 396.0, 41.0, 18.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "" ],
|
||||
"id" : "obj-19",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "Click here to get a list of serial ports",
|
||||
"patching_rect" : [ 474.0, 370.0, 207.0, 20.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-2",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "toggle",
|
||||
"patching_rect" : [ 381.0, 181.0, 21.0, 21.0 ],
|
||||
"numoutlets" : 1,
|
||||
"outlettype" : [ "int" ],
|
||||
"id" : "obj-11",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "message",
|
||||
"text" : "print",
|
||||
"patching_rect" : [ 423.0, 370.0, 36.0, 18.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "" ],
|
||||
"id" : "obj-13",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "serial a 9600",
|
||||
"patching_rect" : [ 279.0, 461.0, 84.0, 20.0 ],
|
||||
"numoutlets" : 2,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "int", "" ],
|
||||
"id" : "obj-14",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "Click to start",
|
||||
"patching_rect" : [ 408.0, 181.0, 117.0, 20.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-17",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
],
|
||||
"lines" : [ {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-39", 0 ],
|
||||
"destination" : [ "obj-37", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-37", 0 ],
|
||||
"destination" : [ "obj-25", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 83.5, 320.5, 288.5, 320.5 ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-33", 0 ],
|
||||
"destination" : [ "obj-14", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-32", 0 ],
|
||||
"destination" : [ "obj-33", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 338.5, 381.5, 288.5, 381.5 ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-31", 0 ],
|
||||
"destination" : [ "obj-33", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-25", 0 ],
|
||||
"destination" : [ "obj-31", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-25", 1 ],
|
||||
"destination" : [ "obj-32", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 310.0, 358.0, 338.5, 358.0 ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-23", 0 ],
|
||||
"destination" : [ "obj-25", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-13", 0 ],
|
||||
"destination" : [ "obj-14", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 432.5, 389.0, 367.0, 389.0, 367.0, 411.0, 288.5, 411.0 ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-19", 0 ],
|
||||
"destination" : [ "obj-14", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 412.5, 417.0, 288.5, 417.0 ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-21", 0 ],
|
||||
"destination" : [ "obj-14", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 390.5, 450.0, 288.5, 450.0 ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-30", 0 ],
|
||||
"destination" : [ "obj-21", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-30", 1 ],
|
||||
"destination" : [ "obj-19", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-11", 0 ],
|
||||
"destination" : [ "obj-30", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 390.5, 322.0, 390.5, 322.0 ]
|
||||
}
|
||||
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
*/
|
@ -1,1193 +0,0 @@
|
||||
/*
|
||||
Serial Call and Response
|
||||
Language: Wiring/Arduino
|
||||
|
||||
This program sends an ASCII A (byte of value 65) on startup
|
||||
and repeats that until it gets some data in.
|
||||
Then it waits for a byte in the serial port, and
|
||||
sends three sensor values whenever it gets a byte in.
|
||||
|
||||
Thanks to Greg Shakar and Scott Fitzgerald for the improvements
|
||||
|
||||
The circuit:
|
||||
* potentiometers attached to analog inputs 0 and 1
|
||||
* pushbutton attached to digital I/O 2
|
||||
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/SerialCallResponse
|
||||
|
||||
Created 26 Sept. 2005
|
||||
by Tom Igoe
|
||||
Modified 14 April 2009
|
||||
by Tom Igoe and Scott Fitzgerald
|
||||
*/
|
||||
|
||||
int firstSensor = 0; // first analog sensor
|
||||
int secondSensor = 0; // second analog sensor
|
||||
int thirdSensor = 0; // digital sensor
|
||||
int inByte = 0; // incoming serial byte
|
||||
|
||||
void setup()
|
||||
{
|
||||
// start serial port at 9600 bps:
|
||||
Serial.begin(9600);
|
||||
pinMode(2, INPUT); // digital sensor is on digital pin 2
|
||||
establishContact(); // send a byte to establish contact until receiver responds
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// if we get a valid byte, read analog ins:
|
||||
if (Serial.available() > 0) {
|
||||
// get incoming byte:
|
||||
inByte = Serial.read();
|
||||
// read first analog input, divide by 4 to make the range 0-255:
|
||||
firstSensor = analogRead(0)/4;
|
||||
// delay 10ms to let the ADC recover:
|
||||
delay(10);
|
||||
// read second analog input, divide by 4 to make the range 0-255:
|
||||
secondSensor = analogRead(1)/4;
|
||||
// read switch, map it to 0 or 255L
|
||||
thirdSensor = map(digitalRead(2), 0, 1, 0, 255);
|
||||
// send sensor values:
|
||||
Serial.print(firstSensor, BYTE);
|
||||
Serial.print(secondSensor, BYTE);
|
||||
Serial.print(thirdSensor, BYTE);
|
||||
}
|
||||
}
|
||||
|
||||
void establishContact() {
|
||||
while (Serial.available() <= 0) {
|
||||
Serial.print('A', BYTE); // send a capital A
|
||||
delay(300);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Processing sketch to run with this example:
|
||||
|
||||
import processing.serial.*;
|
||||
|
||||
int bgcolor; // Background color
|
||||
int fgcolor; // Fill color
|
||||
Serial myPort; // The serial port
|
||||
int[] serialInArray = new int[3]; // Where we'll put what we receive
|
||||
int serialCount = 0; // A count of how many bytes we receive
|
||||
int xpos, ypos; // Starting position of the ball
|
||||
boolean firstContact = false; // Whether we've heard from the microcontroller
|
||||
|
||||
void setup() {
|
||||
size(256, 256); // Stage size
|
||||
noStroke(); // No border on the next thing drawn
|
||||
|
||||
// Set the starting position of the ball (middle of the stage)
|
||||
xpos = width/2;
|
||||
ypos = height/2;
|
||||
|
||||
// Print a list of the serial ports, for debugging purposes:
|
||||
println(Serial.list());
|
||||
|
||||
// I know that the first port in the serial list on my mac
|
||||
// is always my FTDI adaptor, so I open Serial.list()[0].
|
||||
// On Windows machines, this generally opens COM1.
|
||||
// Open whatever port is the one you're using.
|
||||
String portName = Serial.list()[0];
|
||||
myPort = new Serial(this, portName, 9600);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(bgcolor);
|
||||
fill(fgcolor);
|
||||
// Draw the shape
|
||||
ellipse(xpos, ypos, 20, 20);
|
||||
}
|
||||
|
||||
void serialEvent(Serial myPort) {
|
||||
// read a byte from the serial port:
|
||||
int inByte = myPort.read();
|
||||
// if this is the first byte received, and it's an A,
|
||||
// clear the serial buffer and note that you've
|
||||
// had first contact from the microcontroller.
|
||||
// Otherwise, add the incoming byte to the array:
|
||||
if (firstContact == false) {
|
||||
if (inByte == 'A') {
|
||||
myPort.clear(); // clear the serial port buffer
|
||||
firstContact = true; // you've had first contact from the microcontroller
|
||||
myPort.write('A'); // ask for more
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Add the latest byte from the serial port to array:
|
||||
serialInArray[serialCount] = inByte;
|
||||
serialCount++;
|
||||
|
||||
// If we have 3 bytes:
|
||||
if (serialCount > 2 ) {
|
||||
xpos = serialInArray[0];
|
||||
ypos = serialInArray[1];
|
||||
fgcolor = serialInArray[2];
|
||||
|
||||
// print the values (for debugging purposes only):
|
||||
println(xpos + "\t" + ypos + "\t" + fgcolor);
|
||||
|
||||
// Send a capital A to request new sensor readings:
|
||||
myPort.write('A');
|
||||
// Reset serialCount:
|
||||
serialCount = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
Max/MSP version 5 patch to run with this example:
|
||||
|
||||
{
|
||||
"boxes" : [ {
|
||||
"box" : {
|
||||
"maxclass" : "message",
|
||||
"text" : "65",
|
||||
"patching_rect" : [ 339.0, 466.0, 32.5, 18.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "" ],
|
||||
"id" : "obj-9",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "sel 1",
|
||||
"patching_rect" : [ 339.0, 437.0, 36.0, 20.0 ],
|
||||
"numoutlets" : 2,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "bang", "" ],
|
||||
"id" : "obj-6",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "Serial Call-Response \n\nSends a byte out the serial port, and reads 3 bytes in. Sets foregound color, xpos, and ypos of a circle using the values returned from the serial port. \n\nNote: This patch assumes that the device on the other end of the serial port is going to send a single byte of value 65 (ASCII A) on startup. The sketch waits for that byte, then sends an ASCII A whenever it wants more data. \n\ncreated 14 Apr 2009\nby Scott Fitzgerald and Tom Igoe",
|
||||
"linecount" : 11,
|
||||
"patching_rect" : [ 404.0, 52.0, 464.0, 158.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-5",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "trigger (or [t]) forces right-left conventions. All the drawing and processing will happen before Max requests new values. When this trigger fires, it sends an ASCII A to ask Arduino for new values.",
|
||||
"linecount" : 3,
|
||||
"patching_rect" : [ 239.0, 505.0, 425.0, 48.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-65",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "reinitializes the gates when turned on and off",
|
||||
"linecount" : 2,
|
||||
"patching_rect" : [ 170.0, 370.0, 135.0, 34.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-64",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "checks for the ascii value of \"A\" to begin cominucation. After initial communication is made, this block shuts down.",
|
||||
"linecount" : 3,
|
||||
"patching_rect" : [ 460.0, 355.0, 233.0, 48.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-63",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "p \"draw the circle\"",
|
||||
"patching_rect" : [ 217.0, 645.0, 269.0, 19.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 10.0,
|
||||
"outlettype" : [ "" ],
|
||||
"id" : "obj-62",
|
||||
"fontname" : "Verdana",
|
||||
"numinlets" : 3,
|
||||
"patcher" : {
|
||||
"fileversion" : 1,
|
||||
"rect" : [ 54.0, 94.0, 640.0, 480.0 ],
|
||||
"bglocked" : 0,
|
||||
"defrect" : [ 54.0, 94.0, 640.0, 480.0 ],
|
||||
"openrect" : [ 0.0, 0.0, 0.0, 0.0 ],
|
||||
"openinpresentation" : 0,
|
||||
"default_fontsize" : 10.0,
|
||||
"default_fontface" : 0,
|
||||
"default_fontname" : "Verdana",
|
||||
"gridonopen" : 0,
|
||||
"gridsize" : [ 25.0, 25.0 ],
|
||||
"gridsnaponopen" : 0,
|
||||
"toolbarvisible" : 1,
|
||||
"boxanimatetime" : 200,
|
||||
"imprint" : 0,
|
||||
"boxes" : [ {
|
||||
"box" : {
|
||||
"maxclass" : "message",
|
||||
"text" : "frgb 255 255 255",
|
||||
"patching_rect" : [ 375.0, 150.0, 98.0, 18.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 11.595187,
|
||||
"outlettype" : [ "" ],
|
||||
"id" : "obj-47",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "message",
|
||||
"text" : "frgb 0 0 0",
|
||||
"patching_rect" : [ 275.0, 125.0, 59.0, 18.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 11.595187,
|
||||
"outlettype" : [ "" ],
|
||||
"id" : "obj-46",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "sel 255 0",
|
||||
"patching_rect" : [ 300.0, 100.0, 66.0, 21.0 ],
|
||||
"numoutlets" : 3,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "bang", "bang", "" ],
|
||||
"id" : "obj-45",
|
||||
"fontname" : "Verdana",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "pack 0 0 0 0",
|
||||
"patching_rect" : [ 50.0, 125.0, 180.0, 21.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "" ],
|
||||
"id" : "obj-43",
|
||||
"fontname" : "Verdana",
|
||||
"numinlets" : 4
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "+ 10",
|
||||
"patching_rect" : [ 200.0, 100.0, 40.0, 21.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "int" ],
|
||||
"id" : "obj-42",
|
||||
"fontname" : "Verdana",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "+ 10",
|
||||
"patching_rect" : [ 75.0, 100.0, 40.0, 21.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "int" ],
|
||||
"id" : "obj-41",
|
||||
"fontname" : "Verdana",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "message",
|
||||
"text" : "clear, paintoval $1 $2 $3 $4",
|
||||
"patching_rect" : [ 50.0, 150.0, 152.0, 18.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 11.595187,
|
||||
"outlettype" : [ "" ],
|
||||
"id" : "obj-40",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "inlet",
|
||||
"patching_rect" : [ 57.5, 40.0, 25.0, 25.0 ],
|
||||
"numoutlets" : 1,
|
||||
"outlettype" : [ "int" ],
|
||||
"id" : "obj-58",
|
||||
"numinlets" : 0,
|
||||
"comment" : ""
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "inlet",
|
||||
"patching_rect" : [ 120.0, 40.0, 25.0, 25.0 ],
|
||||
"numoutlets" : 1,
|
||||
"outlettype" : [ "int" ],
|
||||
"id" : "obj-59",
|
||||
"numinlets" : 0,
|
||||
"comment" : ""
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "inlet",
|
||||
"patching_rect" : [ 300.0, 40.0, 25.0, 25.0 ],
|
||||
"numoutlets" : 1,
|
||||
"outlettype" : [ "int" ],
|
||||
"id" : "obj-60",
|
||||
"numinlets" : 0,
|
||||
"comment" : ""
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "outlet",
|
||||
"patching_rect" : [ 228.333344, 228.0, 25.0, 25.0 ],
|
||||
"numoutlets" : 0,
|
||||
"id" : "obj-61",
|
||||
"numinlets" : 1,
|
||||
"comment" : ""
|
||||
}
|
||||
|
||||
}
|
||||
],
|
||||
"lines" : [ {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-47", 0 ],
|
||||
"destination" : [ "obj-61", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-46", 0 ],
|
||||
"destination" : [ "obj-61", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-40", 0 ],
|
||||
"destination" : [ "obj-61", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-60", 0 ],
|
||||
"destination" : [ "obj-45", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-59", 0 ],
|
||||
"destination" : [ "obj-42", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-59", 0 ],
|
||||
"destination" : [ "obj-43", 1 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-58", 0 ],
|
||||
"destination" : [ "obj-41", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-58", 0 ],
|
||||
"destination" : [ "obj-43", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-42", 0 ],
|
||||
"destination" : [ "obj-43", 3 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-41", 0 ],
|
||||
"destination" : [ "obj-43", 2 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-45", 1 ],
|
||||
"destination" : [ "obj-47", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-45", 0 ],
|
||||
"destination" : [ "obj-46", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-43", 0 ],
|
||||
"destination" : [ "obj-40", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
]
|
||||
}
|
||||
,
|
||||
"saved_object_attributes" : {
|
||||
"fontface" : 0,
|
||||
"fontsize" : 10.0,
|
||||
"default_fontface" : 0,
|
||||
"default_fontname" : "Verdana",
|
||||
"default_fontsize" : 10.0,
|
||||
"fontname" : "Verdana",
|
||||
"globalpatchername" : ""
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "0",
|
||||
"patching_rect" : [ 310.0, 378.0, 32.5, 20.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "int" ],
|
||||
"id" : "obj-57",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "!- 1",
|
||||
"patching_rect" : [ 385.0, 436.0, 32.5, 20.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "int" ],
|
||||
"id" : "obj-55",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "gate 1 1",
|
||||
"patching_rect" : [ 385.0, 355.0, 54.0, 20.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "" ],
|
||||
"id" : "obj-54",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "toggle",
|
||||
"patching_rect" : [ 385.0, 405.0, 20.0, 20.0 ],
|
||||
"numoutlets" : 1,
|
||||
"outlettype" : [ "int" ],
|
||||
"id" : "obj-53",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "gate 1 0",
|
||||
"patching_rect" : [ 194.0, 455.0, 54.0, 20.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "" ],
|
||||
"id" : "obj-50",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "sel 65",
|
||||
"patching_rect" : [ 385.0, 380.0, 43.0, 20.0 ],
|
||||
"numoutlets" : 2,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "bang", "" ],
|
||||
"id" : "obj-48",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "lcd",
|
||||
"patching_rect" : [ 217.0, 695.0, 256.0, 256.0 ],
|
||||
"numoutlets" : 4,
|
||||
"outlettype" : [ "list", "list", "int", "" ],
|
||||
"id" : "obj-39",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "t 65 l",
|
||||
"patching_rect" : [ 194.0, 504.0, 42.0, 21.0 ],
|
||||
"numoutlets" : 2,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "int", "" ],
|
||||
"id" : "obj-35",
|
||||
"fontname" : "Verdana",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "val3",
|
||||
"patching_rect" : [ 535.0, 604.0, 37.0, 21.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-1",
|
||||
"fontname" : "Verdana",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "number",
|
||||
"patching_rect" : [ 467.0, 604.0, 56.0, 21.0 ],
|
||||
"numoutlets" : 2,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "int", "bang" ],
|
||||
"id" : "obj-3",
|
||||
"fontname" : "Verdana",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "val2",
|
||||
"patching_rect" : [ 410.0, 605.0, 37.0, 21.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-18",
|
||||
"fontname" : "Verdana",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "val1",
|
||||
"patching_rect" : [ 282.0, 605.0, 37.0, 21.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-20",
|
||||
"fontname" : "Verdana",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "number",
|
||||
"patching_rect" : [ 342.0, 605.0, 56.0, 21.0 ],
|
||||
"numoutlets" : 2,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "int", "bang" ],
|
||||
"id" : "obj-22",
|
||||
"fontname" : "Verdana",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "number",
|
||||
"patching_rect" : [ 217.0, 605.0, 55.0, 21.0 ],
|
||||
"numoutlets" : 2,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "int", "bang" ],
|
||||
"id" : "obj-23",
|
||||
"fontname" : "Verdana",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "unpack 0 0 0",
|
||||
"patching_rect" : [ 217.0, 570.0, 269.0, 21.0 ],
|
||||
"numoutlets" : 3,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "int", "int", "int" ],
|
||||
"id" : "obj-29",
|
||||
"fontname" : "Verdana",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "zl group 3",
|
||||
"patching_rect" : [ 194.0, 480.0, 71.0, 21.0 ],
|
||||
"numoutlets" : 2,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "", "" ],
|
||||
"id" : "obj-31",
|
||||
"fontname" : "Verdana",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "select 0 1",
|
||||
"patching_rect" : [ 312.0, 200.0, 62.0, 20.0 ],
|
||||
"numoutlets" : 3,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "bang", "bang", "" ],
|
||||
"id" : "obj-30",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "click here to close the serial port",
|
||||
"patching_rect" : [ 360.0, 291.0, 206.0, 20.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-26",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "click here to open the serial port",
|
||||
"patching_rect" : [ 385.0, 265.0, 206.0, 20.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-27",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "message",
|
||||
"text" : "close",
|
||||
"patching_rect" : [ 312.0, 291.0, 39.0, 18.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "" ],
|
||||
"id" : "obj-21",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "message",
|
||||
"text" : "port a",
|
||||
"patching_rect" : [ 334.0, 265.0, 41.0, 18.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "" ],
|
||||
"id" : "obj-19",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "Click here to get a list of serial ports",
|
||||
"patching_rect" : [ 405.0, 239.0, 207.0, 20.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-2",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "toggle",
|
||||
"patching_rect" : [ 229.0, 155.0, 22.0, 22.0 ],
|
||||
"numoutlets" : 1,
|
||||
"outlettype" : [ "int" ],
|
||||
"id" : "obj-11",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "qmetro 10",
|
||||
"patching_rect" : [ 229.0, 200.0, 65.0, 20.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "bang" ],
|
||||
"id" : "obj-12",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "message",
|
||||
"text" : "print",
|
||||
"patching_rect" : [ 354.0, 239.0, 36.0, 18.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "" ],
|
||||
"id" : "obj-13",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "serial a 9600",
|
||||
"patching_rect" : [ 229.0, 315.0, 84.0, 20.0 ],
|
||||
"numoutlets" : 2,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "int", "" ],
|
||||
"id" : "obj-14",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "Read serial input buffer every 10 milliseconds",
|
||||
"linecount" : 2,
|
||||
"patching_rect" : [ 13.0, 192.0, 210.0, 34.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-15",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "Click to start",
|
||||
"patching_rect" : [ 256.0, 163.0, 117.0, 20.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-17",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
],
|
||||
"lines" : [ {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-12", 0 ],
|
||||
"destination" : [ "obj-14", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-11", 0 ],
|
||||
"destination" : [ "obj-12", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-13", 0 ],
|
||||
"destination" : [ "obj-14", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 363.5, 260.5, 238.5, 260.5 ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-19", 0 ],
|
||||
"destination" : [ "obj-14", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 343.5, 288.5, 238.5, 288.5 ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-21", 0 ],
|
||||
"destination" : [ "obj-14", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 321.5, 311.5, 238.5, 311.5 ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-30", 0 ],
|
||||
"destination" : [ "obj-21", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-30", 1 ],
|
||||
"destination" : [ "obj-19", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-11", 0 ],
|
||||
"destination" : [ "obj-30", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 238.5, 191.0, 321.5, 191.0 ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-29", 2 ],
|
||||
"destination" : [ "obj-3", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-29", 0 ],
|
||||
"destination" : [ "obj-23", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-29", 1 ],
|
||||
"destination" : [ "obj-22", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-14", 0 ],
|
||||
"destination" : [ "obj-50", 1 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-50", 0 ],
|
||||
"destination" : [ "obj-31", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-48", 0 ],
|
||||
"destination" : [ "obj-53", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-53", 0 ],
|
||||
"destination" : [ "obj-50", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 394.5, 426.0, 203.5, 426.0 ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-14", 0 ],
|
||||
"destination" : [ "obj-54", 1 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 238.5, 342.0, 429.5, 342.0 ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-54", 0 ],
|
||||
"destination" : [ "obj-48", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-62", 0 ],
|
||||
"destination" : [ "obj-39", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-3", 0 ],
|
||||
"destination" : [ "obj-62", 2 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-22", 0 ],
|
||||
"destination" : [ "obj-62", 1 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-23", 0 ],
|
||||
"destination" : [ "obj-62", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-53", 0 ],
|
||||
"destination" : [ "obj-55", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-55", 0 ],
|
||||
"destination" : [ "obj-54", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 394.5, 459.0, 453.0, 459.0, 453.0, 351.0, 394.5, 351.0 ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-30", 0 ],
|
||||
"destination" : [ "obj-57", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-57", 0 ],
|
||||
"destination" : [ "obj-53", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 319.5, 401.0, 394.5, 401.0 ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-35", 0 ],
|
||||
"destination" : [ "obj-14", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 203.5, 542.0, 167.0, 542.0, 167.0, 300.0, 238.5, 300.0 ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-35", 1 ],
|
||||
"destination" : [ "obj-29", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-31", 0 ],
|
||||
"destination" : [ "obj-35", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-6", 0 ],
|
||||
"destination" : [ "obj-9", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-53", 0 ],
|
||||
"destination" : [ "obj-6", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 394.5, 431.5, 348.5, 431.5 ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-9", 0 ],
|
||||
"destination" : [ "obj-14", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
*/
|
@ -1,1267 +0,0 @@
|
||||
/*
|
||||
Serial Call and Response in ASCII
|
||||
Language: Wiring/Arduino
|
||||
|
||||
This program sends an ASCII A (byte of value 65) on startup
|
||||
and repeats that until it gets some data in.
|
||||
Then it waits for a byte in the serial port, and
|
||||
sends three ASCII-encoded, comma-separated sensor values,
|
||||
truncated by a linefeed and carriage return,
|
||||
whenever it gets a byte in.
|
||||
|
||||
Thanks to Greg Shakar and Scott Fitzgerald for the improvements
|
||||
|
||||
The circuit:
|
||||
* potentiometers attached to analog inputs 0 and 1
|
||||
* pushbutton attached to digital I/O 2
|
||||
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/SerialCallResponseASCII
|
||||
|
||||
Created 26 Sept. 2005
|
||||
by Tom Igoe
|
||||
Modified 14 April 2009
|
||||
by Tom Igoe and Scott Fitzgerald
|
||||
*/
|
||||
|
||||
int firstSensor = 0; // first analog sensor
|
||||
int secondSensor = 0; // second analog sensor
|
||||
int thirdSensor = 0; // digital sensor
|
||||
int inByte = 0; // incoming serial byte
|
||||
|
||||
void setup()
|
||||
{
|
||||
// start serial port at 9600 bps:
|
||||
Serial.begin(9600);
|
||||
pinMode(2, INPUT); // digital sensor is on digital pin 2
|
||||
establishContact(); // send a byte to establish contact until receiver responds
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// if we get a valid byte, read analog ins:
|
||||
if (Serial.available() > 0) {
|
||||
// get incoming byte:
|
||||
inByte = Serial.read();
|
||||
// read first analog input, divide by 4 to make the range 0-255:
|
||||
firstSensor = analogRead(0)/4;
|
||||
// delay 10ms to let the ADC recover:
|
||||
delay(10);
|
||||
// read second analog input, divide by 4 to make the range 0-255:
|
||||
secondSensor = analogRead(1)/4;
|
||||
// read switch, map it to 0 or 255L
|
||||
thirdSensor = map(digitalRead(2), 0, 1, 0, 255);
|
||||
// send sensor values:
|
||||
Serial.print(firstSensor, DEC);
|
||||
Serial.print(",");
|
||||
Serial.print(secondSensor, DEC);
|
||||
Serial.print(",");
|
||||
Serial.println(thirdSensor, DEC);
|
||||
}
|
||||
}
|
||||
|
||||
void establishContact() {
|
||||
while (Serial.available() <= 0) {
|
||||
Serial.println("0,0,0"); // send an initial string
|
||||
delay(300);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Processing code to run with this example:
|
||||
|
||||
|
||||
import processing.serial.*; // import the Processing serial library
|
||||
Serial myPort; // The serial port
|
||||
|
||||
float bgcolor; // Background color
|
||||
float fgcolor; // Fill color
|
||||
float xpos, ypos; // Starting position of the ball
|
||||
|
||||
void setup() {
|
||||
size(640,480);
|
||||
|
||||
// List all the available serial ports
|
||||
println(Serial.list());
|
||||
|
||||
// I know that the first port in the serial list on my mac
|
||||
// is always my Arduino module, so I open Serial.list()[0].
|
||||
// Change the 0 to the appropriate number of the serial port
|
||||
// that your microcontroller is attached to.
|
||||
myPort = new Serial(this, Serial.list()[0], 9600);
|
||||
|
||||
// read bytes into a buffer until you get a linefeed (ASCII 10):
|
||||
myPort.bufferUntil('\n');
|
||||
|
||||
// draw with smooth edges:
|
||||
smooth();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(bgcolor);
|
||||
fill(fgcolor);
|
||||
// Draw the shape
|
||||
ellipse(xpos, ypos, 20, 20);
|
||||
}
|
||||
|
||||
// serialEvent method is run automatically by the Processing applet
|
||||
// whenever the buffer reaches the byte value set in the bufferUntil()
|
||||
// method in the setup():
|
||||
|
||||
void serialEvent(Serial myPort) {
|
||||
// read the serial buffer:
|
||||
String myString = myPort.readStringUntil('\n');
|
||||
// if you got any bytes other than the linefeed:
|
||||
myString = trim(myString);
|
||||
|
||||
// split the string at the commas
|
||||
// and convert the sections into integers:
|
||||
int sensors[] = int(split(myString, ','));
|
||||
|
||||
// print out the values you got:
|
||||
for (int sensorNum = 0; sensorNum < sensors.length; sensorNum++) {
|
||||
print("Sensor " + sensorNum + ": " + sensors[sensorNum] + "\t");
|
||||
}
|
||||
// add a linefeed after all the sensor values are printed:
|
||||
println();
|
||||
if (sensors.length > 1) {
|
||||
xpos = map(sensors[0], 0,1023,0,width);
|
||||
ypos = map(sensors[1], 0,1023,0,height);
|
||||
fgcolor = sensors[2];
|
||||
}
|
||||
// send a byte to ask for more data:
|
||||
myPort.write("A");
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
{
|
||||
"boxes" : [ {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "fromsymbol",
|
||||
"patching_rect" : [ 265.0, 585.0, 74.0, 20.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "" ],
|
||||
"id" : "obj-7",
|
||||
"fontname" : "Arial",
|
||||
"color" : [ 1.0, 0.890196, 0.090196, 1.0 ],
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "itoa",
|
||||
"patching_rect" : [ 265.0, 562.0, 46.0, 20.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "int" ],
|
||||
"id" : "obj-8",
|
||||
"fontname" : "Arial",
|
||||
"color" : [ 1.0, 0.890196, 0.090196, 1.0 ],
|
||||
"numinlets" : 3
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "zl group",
|
||||
"patching_rect" : [ 265.0, 539.0, 53.0, 20.0 ],
|
||||
"numoutlets" : 2,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "", "" ],
|
||||
"id" : "obj-4",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "select 10 13",
|
||||
"patching_rect" : [ 209.0, 501.0, 75.0, 20.0 ],
|
||||
"numoutlets" : 3,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "bang", "bang", "" ],
|
||||
"id" : "obj-10",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "message",
|
||||
"text" : "65",
|
||||
"patching_rect" : [ 354.0, 481.0, 32.5, 18.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "" ],
|
||||
"id" : "obj-9",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "sel 1",
|
||||
"patching_rect" : [ 354.0, 452.0, 36.0, 20.0 ],
|
||||
"numoutlets" : 2,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "bang", "" ],
|
||||
"id" : "obj-6",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "Serial Call-Response ASCII \n\nSends a byte out the serial port, and reads 3 ASCII enoded, comma separated in, truncated by a linefeed. It then sets foregound color, xpos, and ypos of a circle using the values returned from the serial port. \n\nNote: This patch assumes that the device on the other end of the serial port is going to send a single byte of value 65 (ASCII A) on startup. The sketch waits for that byte, then sends an ASCII A whenever it wants more data. \n\ncreated 14 Apr 2009\nby Scott Fitzgerald and Tom Igoe",
|
||||
"linecount" : 12,
|
||||
"patching_rect" : [ 401.0, 67.0, 540.0, 172.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-5",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "trigger (or [t]) forces right-left conventions. All the drawing and processing will happen before Max requests new values. When this trigger fires, it sends an ASCII A to ask Arduino for new values.",
|
||||
"linecount" : 3,
|
||||
"patching_rect" : [ 254.0, 625.0, 425.0, 48.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-65",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "reinitializes the gates when turned on and off",
|
||||
"linecount" : 2,
|
||||
"patching_rect" : [ 185.0, 385.0, 135.0, 34.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-64",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "checks for the ascii value of newline to begin communication. After initial communication is made, this block shuts down.",
|
||||
"linecount" : 3,
|
||||
"patching_rect" : [ 475.0, 370.0, 252.0, 48.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-63",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "p \"draw the circle\"",
|
||||
"patching_rect" : [ 232.0, 765.0, 269.0, 19.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 10.0,
|
||||
"outlettype" : [ "" ],
|
||||
"id" : "obj-62",
|
||||
"fontname" : "Verdana",
|
||||
"numinlets" : 3,
|
||||
"patcher" : {
|
||||
"fileversion" : 1,
|
||||
"rect" : [ 54.0, 94.0, 640.0, 480.0 ],
|
||||
"bglocked" : 0,
|
||||
"defrect" : [ 54.0, 94.0, 640.0, 480.0 ],
|
||||
"openrect" : [ 0.0, 0.0, 0.0, 0.0 ],
|
||||
"openinpresentation" : 0,
|
||||
"default_fontsize" : 10.0,
|
||||
"default_fontface" : 0,
|
||||
"default_fontname" : "Verdana",
|
||||
"gridonopen" : 0,
|
||||
"gridsize" : [ 25.0, 25.0 ],
|
||||
"gridsnaponopen" : 0,
|
||||
"toolbarvisible" : 1,
|
||||
"boxanimatetime" : 200,
|
||||
"imprint" : 0,
|
||||
"boxes" : [ {
|
||||
"box" : {
|
||||
"maxclass" : "message",
|
||||
"text" : "frgb 255 255 255",
|
||||
"patching_rect" : [ 375.0, 150.0, 98.0, 18.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 11.595187,
|
||||
"outlettype" : [ "" ],
|
||||
"id" : "obj-47",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "message",
|
||||
"text" : "frgb 0 0 0",
|
||||
"patching_rect" : [ 275.0, 125.0, 59.0, 18.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 11.595187,
|
||||
"outlettype" : [ "" ],
|
||||
"id" : "obj-46",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "sel 255 0",
|
||||
"patching_rect" : [ 300.0, 100.0, 66.0, 21.0 ],
|
||||
"numoutlets" : 3,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "bang", "bang", "" ],
|
||||
"id" : "obj-45",
|
||||
"fontname" : "Verdana",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "pack 0 0 0 0",
|
||||
"patching_rect" : [ 50.0, 125.0, 180.0, 21.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "" ],
|
||||
"id" : "obj-43",
|
||||
"fontname" : "Verdana",
|
||||
"numinlets" : 4
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "+ 10",
|
||||
"patching_rect" : [ 200.0, 100.0, 40.0, 21.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "int" ],
|
||||
"id" : "obj-42",
|
||||
"fontname" : "Verdana",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "+ 10",
|
||||
"patching_rect" : [ 75.0, 100.0, 40.0, 21.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "int" ],
|
||||
"id" : "obj-41",
|
||||
"fontname" : "Verdana",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "message",
|
||||
"text" : "clear, paintoval $1 $2 $3 $4",
|
||||
"patching_rect" : [ 50.0, 150.0, 152.0, 18.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 11.595187,
|
||||
"outlettype" : [ "" ],
|
||||
"id" : "obj-40",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "inlet",
|
||||
"patching_rect" : [ 57.5, 40.0, 25.0, 25.0 ],
|
||||
"numoutlets" : 1,
|
||||
"outlettype" : [ "int" ],
|
||||
"id" : "obj-58",
|
||||
"numinlets" : 0,
|
||||
"comment" : ""
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "inlet",
|
||||
"patching_rect" : [ 120.0, 40.0, 25.0, 25.0 ],
|
||||
"numoutlets" : 1,
|
||||
"outlettype" : [ "int" ],
|
||||
"id" : "obj-59",
|
||||
"numinlets" : 0,
|
||||
"comment" : ""
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "inlet",
|
||||
"patching_rect" : [ 300.0, 40.0, 25.0, 25.0 ],
|
||||
"numoutlets" : 1,
|
||||
"outlettype" : [ "int" ],
|
||||
"id" : "obj-60",
|
||||
"numinlets" : 0,
|
||||
"comment" : ""
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "outlet",
|
||||
"patching_rect" : [ 228.333344, 228.0, 25.0, 25.0 ],
|
||||
"numoutlets" : 0,
|
||||
"id" : "obj-61",
|
||||
"numinlets" : 1,
|
||||
"comment" : ""
|
||||
}
|
||||
|
||||
}
|
||||
],
|
||||
"lines" : [ {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-43", 0 ],
|
||||
"destination" : [ "obj-40", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-45", 0 ],
|
||||
"destination" : [ "obj-46", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-45", 1 ],
|
||||
"destination" : [ "obj-47", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-41", 0 ],
|
||||
"destination" : [ "obj-43", 2 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-42", 0 ],
|
||||
"destination" : [ "obj-43", 3 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-58", 0 ],
|
||||
"destination" : [ "obj-43", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-58", 0 ],
|
||||
"destination" : [ "obj-41", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-59", 0 ],
|
||||
"destination" : [ "obj-43", 1 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-59", 0 ],
|
||||
"destination" : [ "obj-42", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-60", 0 ],
|
||||
"destination" : [ "obj-45", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-40", 0 ],
|
||||
"destination" : [ "obj-61", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-46", 0 ],
|
||||
"destination" : [ "obj-61", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-47", 0 ],
|
||||
"destination" : [ "obj-61", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
]
|
||||
}
|
||||
,
|
||||
"saved_object_attributes" : {
|
||||
"fontface" : 0,
|
||||
"fontsize" : 10.0,
|
||||
"default_fontface" : 0,
|
||||
"default_fontname" : "Verdana",
|
||||
"default_fontsize" : 10.0,
|
||||
"fontname" : "Verdana",
|
||||
"globalpatchername" : ""
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "0",
|
||||
"patching_rect" : [ 325.0, 393.0, 32.5, 20.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "int" ],
|
||||
"id" : "obj-57",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "!- 1",
|
||||
"patching_rect" : [ 400.0, 451.0, 32.5, 20.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "int" ],
|
||||
"id" : "obj-55",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "gate 1 1",
|
||||
"patching_rect" : [ 400.0, 370.0, 54.0, 20.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "" ],
|
||||
"id" : "obj-54",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "toggle",
|
||||
"patching_rect" : [ 400.0, 420.0, 20.0, 20.0 ],
|
||||
"numoutlets" : 1,
|
||||
"outlettype" : [ "int" ],
|
||||
"id" : "obj-53",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "gate 1 0",
|
||||
"patching_rect" : [ 209.0, 470.0, 54.0, 20.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "" ],
|
||||
"id" : "obj-50",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "sel 10",
|
||||
"patching_rect" : [ 400.0, 393.0, 43.0, 20.0 ],
|
||||
"numoutlets" : 2,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "bang", "" ],
|
||||
"id" : "obj-48",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "lcd",
|
||||
"patching_rect" : [ 232.0, 815.0, 256.0, 256.0 ],
|
||||
"numoutlets" : 4,
|
||||
"outlettype" : [ "list", "list", "int", "" ],
|
||||
"id" : "obj-39",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "t 65 l",
|
||||
"patching_rect" : [ 209.0, 624.0, 42.0, 21.0 ],
|
||||
"numoutlets" : 2,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "int", "" ],
|
||||
"id" : "obj-35",
|
||||
"fontname" : "Verdana",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "val3",
|
||||
"patching_rect" : [ 553.0, 725.0, 37.0, 21.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-1",
|
||||
"fontname" : "Verdana",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "number",
|
||||
"patching_rect" : [ 482.0, 725.0, 56.0, 21.0 ],
|
||||
"numoutlets" : 2,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "int", "bang" ],
|
||||
"id" : "obj-3",
|
||||
"fontname" : "Verdana",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "val2",
|
||||
"patching_rect" : [ 425.0, 725.0, 37.0, 21.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-18",
|
||||
"fontname" : "Verdana",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "val1",
|
||||
"patching_rect" : [ 297.0, 725.0, 37.0, 21.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-20",
|
||||
"fontname" : "Verdana",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "number",
|
||||
"patching_rect" : [ 357.0, 725.0, 56.0, 21.0 ],
|
||||
"numoutlets" : 2,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "int", "bang" ],
|
||||
"id" : "obj-22",
|
||||
"fontname" : "Verdana",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "number",
|
||||
"patching_rect" : [ 232.0, 725.0, 55.0, 21.0 ],
|
||||
"numoutlets" : 2,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "int", "bang" ],
|
||||
"id" : "obj-23",
|
||||
"fontname" : "Verdana",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "unpack 0 0 0 0 0",
|
||||
"patching_rect" : [ 232.0, 690.0, 269.0, 21.0 ],
|
||||
"numoutlets" : 5,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "int", "int", "int", "int", "int" ],
|
||||
"id" : "obj-29",
|
||||
"fontname" : "Verdana",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "select 0 1",
|
||||
"patching_rect" : [ 327.0, 215.0, 62.0, 20.0 ],
|
||||
"numoutlets" : 3,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "bang", "bang", "" ],
|
||||
"id" : "obj-30",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "click here to close the serial port",
|
||||
"patching_rect" : [ 375.0, 306.0, 206.0, 20.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-26",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "click here to open the serial port",
|
||||
"patching_rect" : [ 400.0, 280.0, 206.0, 20.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-27",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "message",
|
||||
"text" : "close",
|
||||
"patching_rect" : [ 327.0, 306.0, 39.0, 18.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "" ],
|
||||
"id" : "obj-21",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "message",
|
||||
"text" : "port a",
|
||||
"patching_rect" : [ 349.0, 280.0, 41.0, 18.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "" ],
|
||||
"id" : "obj-19",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "Click here to get a list of serial ports",
|
||||
"patching_rect" : [ 420.0, 254.0, 207.0, 20.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-2",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "toggle",
|
||||
"patching_rect" : [ 244.0, 170.0, 22.0, 22.0 ],
|
||||
"numoutlets" : 1,
|
||||
"outlettype" : [ "int" ],
|
||||
"id" : "obj-11",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "qmetro 10",
|
||||
"patching_rect" : [ 244.0, 215.0, 65.0, 20.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "bang" ],
|
||||
"id" : "obj-12",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "message",
|
||||
"text" : "print",
|
||||
"patching_rect" : [ 369.0, 254.0, 36.0, 18.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "" ],
|
||||
"id" : "obj-13",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "serial a 9600",
|
||||
"patching_rect" : [ 244.0, 330.0, 84.0, 20.0 ],
|
||||
"numoutlets" : 2,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "int", "" ],
|
||||
"id" : "obj-14",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "Read serial input buffer every 10 milliseconds",
|
||||
"linecount" : 2,
|
||||
"patching_rect" : [ 28.0, 207.0, 210.0, 34.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-15",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "Click to start",
|
||||
"patching_rect" : [ 271.0, 178.0, 117.0, 20.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-17",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
],
|
||||
"lines" : [ {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-54", 0 ],
|
||||
"destination" : [ "obj-48", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-48", 0 ],
|
||||
"destination" : [ "obj-53", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-9", 0 ],
|
||||
"destination" : [ "obj-14", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-53", 0 ],
|
||||
"destination" : [ "obj-6", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 409.5, 446.5, 363.5, 446.5 ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-6", 0 ],
|
||||
"destination" : [ "obj-9", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-35", 0 ],
|
||||
"destination" : [ "obj-14", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 218.5, 656.0, 182.0, 656.0, 182.0, 315.0, 253.5, 315.0 ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-57", 0 ],
|
||||
"destination" : [ "obj-53", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 334.5, 416.0, 409.5, 416.0 ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-30", 0 ],
|
||||
"destination" : [ "obj-57", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-55", 0 ],
|
||||
"destination" : [ "obj-54", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 409.5, 474.0, 468.0, 474.0, 468.0, 366.0, 409.5, 366.0 ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-53", 0 ],
|
||||
"destination" : [ "obj-55", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-23", 0 ],
|
||||
"destination" : [ "obj-62", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-22", 0 ],
|
||||
"destination" : [ "obj-62", 1 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-3", 0 ],
|
||||
"destination" : [ "obj-62", 2 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-62", 0 ],
|
||||
"destination" : [ "obj-39", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-14", 0 ],
|
||||
"destination" : [ "obj-54", 1 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 253.5, 357.0, 444.5, 357.0 ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-53", 0 ],
|
||||
"destination" : [ "obj-50", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 409.5, 441.0, 218.5, 441.0 ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-14", 0 ],
|
||||
"destination" : [ "obj-50", 1 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-11", 0 ],
|
||||
"destination" : [ "obj-30", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 253.5, 206.0, 336.5, 206.0 ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-30", 1 ],
|
||||
"destination" : [ "obj-19", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-30", 0 ],
|
||||
"destination" : [ "obj-21", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-21", 0 ],
|
||||
"destination" : [ "obj-14", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 336.5, 326.5, 253.5, 326.5 ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-19", 0 ],
|
||||
"destination" : [ "obj-14", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 358.5, 303.5, 253.5, 303.5 ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-13", 0 ],
|
||||
"destination" : [ "obj-14", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 378.5, 275.5, 253.5, 275.5 ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-11", 0 ],
|
||||
"destination" : [ "obj-12", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-12", 0 ],
|
||||
"destination" : [ "obj-14", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-10", 2 ],
|
||||
"destination" : [ "obj-4", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 274.5, 542.0, 274.5, 542.0 ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-10", 0 ],
|
||||
"destination" : [ "obj-4", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 218.5, 529.5, 274.5, 529.5 ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-4", 0 ],
|
||||
"destination" : [ "obj-8", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-8", 0 ],
|
||||
"destination" : [ "obj-7", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-7", 0 ],
|
||||
"destination" : [ "obj-35", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 274.5, 614.0, 218.5, 614.0 ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-50", 0 ],
|
||||
"destination" : [ "obj-10", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-29", 0 ],
|
||||
"destination" : [ "obj-23", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-35", 1 ],
|
||||
"destination" : [ "obj-29", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-29", 4 ],
|
||||
"destination" : [ "obj-3", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-29", 2 ],
|
||||
"destination" : [ "obj-22", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
*/
|
@ -1,697 +0,0 @@
|
||||
/*
|
||||
This example reads three analog sensors (potentiometers are easiest)
|
||||
and sends their values serially. The Processing and Max/MSP programs at the bottom
|
||||
take those three values and use them to change the background color of the screen.
|
||||
|
||||
The circuit:
|
||||
* potentiometers attached to analog inputs 0, 1, and 2
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/VirtualColorMixer
|
||||
|
||||
created 2 Dec 2006
|
||||
by David A. Mellis
|
||||
modified 14 Apr 2009
|
||||
by Tom Igoe and Scott Fitzgerald
|
||||
|
||||
*/
|
||||
|
||||
const int redPin = 0; // sensor to control red color
|
||||
const int greenPin = 1; // sensor to control green color
|
||||
const int bluePin = 2; // sensor to control blue color
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.print(analogRead(redPin));
|
||||
Serial.print(",");
|
||||
Serial.print(analogRead(greenPin));
|
||||
Serial.print(",");
|
||||
Serial.println(analogRead(bluePin));
|
||||
}
|
||||
|
||||
/* Processing code for this example
|
||||
|
||||
|
||||
import processing.serial.*;
|
||||
|
||||
float redValue = 0; // red value
|
||||
float greenValue = 0; // green value
|
||||
float blueValue = 0; // blue value
|
||||
|
||||
Serial myPort;
|
||||
|
||||
void setup() {
|
||||
size(200, 200);
|
||||
|
||||
// List all the available serial ports
|
||||
println(Serial.list());
|
||||
// I know that the first port in the serial list on my mac
|
||||
// is always my Arduino, so I open Serial.list()[0].
|
||||
// Open whatever port is the one you're using.
|
||||
myPort = new Serial(this, Serial.list()[0], 9600);
|
||||
// don't generate a serialEvent() unless you get a newline character:
|
||||
myPort.bufferUntil('\n');
|
||||
}
|
||||
|
||||
void draw() {
|
||||
// set the background color with the color values:
|
||||
background(redValue, greenValue, blueValue);
|
||||
}
|
||||
|
||||
void serialEvent(Serial myPort) {
|
||||
// get the ASCII string:
|
||||
String inString = myPort.readStringUntil('\n');
|
||||
|
||||
if (inString != null) {
|
||||
// trim off any whitespace:
|
||||
inString = trim(inString);
|
||||
// split the string on the commas and convert the
|
||||
// resulting substrings into an integer array:
|
||||
float[] colors = float(split(inString, ","));
|
||||
// if the array has at least three elements, you know
|
||||
// you got the whole thing. Put the numbers in the
|
||||
// color variables:
|
||||
if (colors.length >=3) {
|
||||
// map them to the range 0-255:
|
||||
redValue = map(colors[0], 0, 1023, 0, 255);
|
||||
greenValue = map(colors[1], 0, 1023, 0, 255);
|
||||
blueValue = map(colors[2], 0, 1023, 0, 255);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/* Max/MSP patch for this example
|
||||
{
|
||||
"boxes" : [ {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "/ 4",
|
||||
"patching_rect" : [ 448.0, 502.0, 32.5, 20.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "int" ],
|
||||
"id" : "obj-25",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "/ 4",
|
||||
"patching_rect" : [ 398.0, 502.0, 32.5, 20.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "int" ],
|
||||
"id" : "obj-24",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "/ 4",
|
||||
"patching_rect" : [ 348.0, 502.0, 32.5, 20.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "int" ],
|
||||
"id" : "obj-23",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "Virtual color mixer\n\nThis patch takes a string, containing three comma-separated ASCII formatted numbers from 0 to 1023, with a carriage return and linefeed at the end. It converts the string to three integers and uses them to set the background color.\n\n created 2 Dec 2006\n by David A. Mellis\nmodified 14 Apr 2009\nby Scott Fitzgerald and Tom Igoe",
|
||||
"linecount" : 11,
|
||||
"patching_rect" : [ 524.0, 51.0, 398.0, 158.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-32",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "select 0 1",
|
||||
"patching_rect" : [ 372.0, 125.0, 62.0, 20.0 ],
|
||||
"numoutlets" : 3,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "bang", "bang", "" ],
|
||||
"id" : "obj-30",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "click here to close the serial port",
|
||||
"patching_rect" : [ 457.0, 276.0, 206.0, 20.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-26",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "click here to open the serial port",
|
||||
"patching_rect" : [ 457.0, 250.0, 206.0, 20.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-27",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "message",
|
||||
"text" : "close",
|
||||
"patching_rect" : [ 372.0, 276.0, 39.0, 18.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "" ],
|
||||
"id" : "obj-21",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "message",
|
||||
"text" : "port a",
|
||||
"patching_rect" : [ 394.0, 250.0, 41.0, 18.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "" ],
|
||||
"id" : "obj-19",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "Click here to get a list of serial ports",
|
||||
"patching_rect" : [ 457.0, 224.0, 207.0, 20.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-2",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "Convert ASCII to symbol",
|
||||
"patching_rect" : [ 424.0, 423.0, 147.0, 20.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-4",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "Convert integer to ASCII",
|
||||
"patching_rect" : [ 424.0, 400.0, 147.0, 20.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-5",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "fromsymbol",
|
||||
"patching_rect" : [ 347.0, 423.0, 74.0, 20.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "" ],
|
||||
"id" : "obj-7",
|
||||
"fontname" : "Arial",
|
||||
"color" : [ 1.0, 0.890196, 0.090196, 1.0 ],
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "itoa",
|
||||
"patching_rect" : [ 347.0, 400.0, 46.0, 20.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "int" ],
|
||||
"id" : "obj-8",
|
||||
"fontname" : "Arial",
|
||||
"color" : [ 1.0, 0.890196, 0.090196, 1.0 ],
|
||||
"numinlets" : 3
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "zl group",
|
||||
"patching_rect" : [ 347.0, 377.0, 53.0, 20.0 ],
|
||||
"numoutlets" : 2,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "", "" ],
|
||||
"id" : "obj-9",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "select 10 13",
|
||||
"patching_rect" : [ 289.0, 326.0, 77.0, 20.0 ],
|
||||
"numoutlets" : 3,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "bang", "bang", "" ],
|
||||
"id" : "obj-10",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "toggle",
|
||||
"patching_rect" : [ 289.0, 88.0, 15.0, 15.0 ],
|
||||
"numoutlets" : 1,
|
||||
"outlettype" : [ "int" ],
|
||||
"id" : "obj-11",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "qmetro 10",
|
||||
"patching_rect" : [ 289.0, 125.0, 65.0, 20.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "bang" ],
|
||||
"id" : "obj-12",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "message",
|
||||
"text" : "print",
|
||||
"patching_rect" : [ 414.0, 224.0, 36.0, 18.0 ],
|
||||
"numoutlets" : 1,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "" ],
|
||||
"id" : "obj-13",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 2
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "serial a 9600",
|
||||
"patching_rect" : [ 289.0, 300.0, 84.0, 20.0 ],
|
||||
"numoutlets" : 2,
|
||||
"fontsize" : 12.0,
|
||||
"outlettype" : [ "int", "" ],
|
||||
"id" : "obj-14",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "Read serial input buffer every 10 milliseconds",
|
||||
"linecount" : 2,
|
||||
"patching_rect" : [ 98.0, 117.0, 185.0, 34.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-15",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "If you get newline (ASCII 10), send the list. If you get return (ASCII 13) do nothing. Any other value, add to the list",
|
||||
"linecount" : 3,
|
||||
"patching_rect" : [ 377.0, 314.0, 320.0, 48.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-16",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "Click to open/close serial port and start/stop patch",
|
||||
"linecount" : 2,
|
||||
"patching_rect" : [ 316.0, 77.0, 199.0, 34.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-17",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "bgcolor 0 0 0",
|
||||
"patching_rect" : [ 348.0, 585.0, 169.0, 19.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 10.0,
|
||||
"id" : "obj-6",
|
||||
"fontname" : "Verdana",
|
||||
"numinlets" : 4
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "newobj",
|
||||
"text" : "unpack 0 0 0 0 0",
|
||||
"patching_rect" : [ 347.0, 470.0, 119.0, 19.0 ],
|
||||
"numoutlets" : 5,
|
||||
"fontsize" : 10.0,
|
||||
"outlettype" : [ "int", "int", "int", "int", "int" ],
|
||||
"id" : "obj-20",
|
||||
"fontname" : "Verdana",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "number",
|
||||
"patching_rect" : [ 448.0, 535.0, 50.0, 19.0 ],
|
||||
"numoutlets" : 2,
|
||||
"fontsize" : 10.0,
|
||||
"outlettype" : [ "int", "bang" ],
|
||||
"id" : "obj-18",
|
||||
"fontname" : "Verdana",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "number",
|
||||
"patching_rect" : [ 398.0, 535.0, 50.0, 19.0 ],
|
||||
"numoutlets" : 2,
|
||||
"fontsize" : 10.0,
|
||||
"outlettype" : [ "int", "bang" ],
|
||||
"id" : "obj-1",
|
||||
"fontname" : "Verdana",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "number",
|
||||
"patching_rect" : [ 348.0, 535.0, 50.0, 19.0 ],
|
||||
"numoutlets" : 2,
|
||||
"fontsize" : 10.0,
|
||||
"outlettype" : [ "int", "bang" ],
|
||||
"id" : "obj-22",
|
||||
"fontname" : "Verdana",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"box" : {
|
||||
"maxclass" : "comment",
|
||||
"text" : "Here's the numbers from Arduino's analog input",
|
||||
"linecount" : 3,
|
||||
"patching_rect" : [ 198.0, 484.0, 138.0, 48.0 ],
|
||||
"numoutlets" : 0,
|
||||
"fontsize" : 12.0,
|
||||
"id" : "obj-3",
|
||||
"fontname" : "Arial",
|
||||
"numinlets" : 1
|
||||
}
|
||||
|
||||
}
|
||||
],
|
||||
"lines" : [ {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-18", 0 ],
|
||||
"destination" : [ "obj-6", 2 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-1", 0 ],
|
||||
"destination" : [ "obj-6", 1 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-22", 0 ],
|
||||
"destination" : [ "obj-6", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-25", 0 ],
|
||||
"destination" : [ "obj-18", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-20", 4 ],
|
||||
"destination" : [ "obj-25", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-20", 2 ],
|
||||
"destination" : [ "obj-24", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-24", 0 ],
|
||||
"destination" : [ "obj-1", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-23", 0 ],
|
||||
"destination" : [ "obj-22", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-20", 0 ],
|
||||
"destination" : [ "obj-23", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-8", 0 ],
|
||||
"destination" : [ "obj-7", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-14", 0 ],
|
||||
"destination" : [ "obj-10", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-12", 0 ],
|
||||
"destination" : [ "obj-14", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-11", 0 ],
|
||||
"destination" : [ "obj-12", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-13", 0 ],
|
||||
"destination" : [ "obj-14", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 423.5, 245.5, 298.5, 245.5 ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-19", 0 ],
|
||||
"destination" : [ "obj-14", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 403.5, 273.5, 298.5, 273.5 ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-21", 0 ],
|
||||
"destination" : [ "obj-14", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 381.5, 296.5, 298.5, 296.5 ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-30", 0 ],
|
||||
"destination" : [ "obj-21", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-30", 1 ],
|
||||
"destination" : [ "obj-19", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-11", 0 ],
|
||||
"destination" : [ "obj-30", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 298.0, 116.0, 381.5, 116.0 ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-7", 0 ],
|
||||
"destination" : [ "obj-20", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-9", 0 ],
|
||||
"destination" : [ "obj-8", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-10", 0 ],
|
||||
"destination" : [ "obj-9", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 298.5, 353.0, 356.5, 353.0 ]
|
||||
}
|
||||
|
||||
}
|
||||
, {
|
||||
"patchline" : {
|
||||
"source" : [ "obj-10", 2 ],
|
||||
"destination" : [ "obj-9", 0 ],
|
||||
"hidden" : 0,
|
||||
"midpoints" : [ 356.5, 365.0, 356.5, 365.0 ]
|
||||
}
|
||||
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
*/
|
@ -1,25 +0,0 @@
|
||||
/*
|
||||
* Blink
|
||||
*
|
||||
* The basic Arduino example. Turns on an LED on for one second,
|
||||
* then off for one second, and so on... We use pin 13 because,
|
||||
* depending on your Arduino board, it has either a built-in LED
|
||||
* or a built-in resistor so that you need only an LED.
|
||||
*
|
||||
* http://www.arduino.cc/en/Tutorial/Blink
|
||||
*/
|
||||
|
||||
int ledPin = 13; // LED connected to digital pin 13
|
||||
|
||||
void setup() // run once, when the sketch starts
|
||||
{
|
||||
pinMode(ledPin, OUTPUT); // sets the digital pin as output
|
||||
}
|
||||
|
||||
void loop() // run over and over again
|
||||
{
|
||||
digitalWrite(ledPin, HIGH); // sets the LED on
|
||||
delay(1000); // waits for a second
|
||||
digitalWrite(ledPin, LOW); // sets the LED off
|
||||
delay(1000); // waits for a second
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
/* Blink without Delay
|
||||
*
|
||||
* Turns on and off a light emitting diode(LED) connected to a digital
|
||||
* pin, without using the delay() function. This means that other code
|
||||
* can run at the same time without being interrupted by the LED code.
|
||||
*
|
||||
* http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
|
||||
*/
|
||||
|
||||
int ledPin = 13; // LED connected to digital pin 13
|
||||
int value = LOW; // previous value of the LED
|
||||
long previousMillis = 0; // will store last time LED was updated
|
||||
long interval = 1000; // interval at which to blink (milliseconds)
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(ledPin, OUTPUT); // sets the digital pin as output
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// here is where you'd put code that needs to be running all the time.
|
||||
|
||||
// check to see if it's time to blink the LED; that is, is the difference
|
||||
// between the current time and last time we blinked the LED bigger than
|
||||
// the interval at which we want to blink the LED.
|
||||
if (millis() - previousMillis > interval) {
|
||||
previousMillis = millis(); // remember the last time we blinked the LED
|
||||
|
||||
// if the LED is off turn it on and vice-versa.
|
||||
if (value == LOW)
|
||||
value = HIGH;
|
||||
else
|
||||
value = LOW;
|
||||
|
||||
digitalWrite(ledPin, value);
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
/*
|
||||
* Button
|
||||
* by DojoDave <http://www.0j0.org>
|
||||
*
|
||||
* Turns on and off a light emitting diode(LED) connected to digital
|
||||
* pin 13, when pressing a pushbutton attached to pin 7.
|
||||
*
|
||||
* http://www.arduino.cc/en/Tutorial/Button
|
||||
*/
|
||||
|
||||
int ledPin = 13; // choose the pin for the LED
|
||||
int inputPin = 2; // choose the input pin (for a pushbutton)
|
||||
int val = 0; // variable for reading the pin status
|
||||
|
||||
void setup() {
|
||||
pinMode(ledPin, OUTPUT); // declare LED as output
|
||||
pinMode(inputPin, INPUT); // declare pushbutton as input
|
||||
}
|
||||
|
||||
void loop(){
|
||||
val = digitalRead(inputPin); // read input value
|
||||
if (val == HIGH) { // check if the input is HIGH
|
||||
digitalWrite(ledPin, LOW); // turn LED OFF
|
||||
} else {
|
||||
digitalWrite(ledPin, HIGH); // turn LED ON
|
||||
}
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
/* Debounce
|
||||
*
|
||||
* Each time the input pin goes from LOW to HIGH (e.g. because of a push-button
|
||||
* press), the output pin is toggled from LOW to HIGH or HIGH to LOW. There's
|
||||
* a minimum delay between toggles to debounce the circuit (i.e. to ignore
|
||||
* noise).
|
||||
*
|
||||
* David A. Mellis
|
||||
* 21 November 2006
|
||||
*
|
||||
* http://www.arduino.cc/en/Tutorial/Debounce
|
||||
*/
|
||||
|
||||
int inPin = 7; // the number of the input pin
|
||||
int outPin = 13; // the number of the output pin
|
||||
|
||||
int state = HIGH; // the current state of the output pin
|
||||
int reading; // the current reading from the input pin
|
||||
int previous = LOW; // the previous reading from the input pin
|
||||
|
||||
// the follow variables are long's because the time, measured in miliseconds,
|
||||
// will quickly become a bigger number than can be stored in an int.
|
||||
long time = 0; // the last time the output pin was toggled
|
||||
long debounce = 200; // the debounce time, increase if the output flickers
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(inPin, INPUT);
|
||||
pinMode(outPin, OUTPUT);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
reading = digitalRead(inPin);
|
||||
|
||||
// if we just pressed the button (i.e. the input went from LOW to HIGH),
|
||||
// and we've waited long enough since the last press to ignore any noise...
|
||||
if (reading == HIGH && previous == LOW && millis() - time > debounce) {
|
||||
// ... invert the output
|
||||
if (state == HIGH)
|
||||
state = LOW;
|
||||
else
|
||||
state = HIGH;
|
||||
|
||||
// ... and remember when the last button press was
|
||||
time = millis();
|
||||
}
|
||||
|
||||
digitalWrite(outPin, state);
|
||||
|
||||
previous = reading;
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Loop
|
||||
* by David A. Mellis
|
||||
*
|
||||
* Lights multiple LEDs in sequence, then in reverse. Demonstrates
|
||||
* the use of a for() loop and arrays.
|
||||
*
|
||||
* http://www.arduino.cc/en/Tutorial/Loop
|
||||
*/
|
||||
|
||||
int timer = 100; // The higher the number, the slower the timing.
|
||||
int pins[] = { 2, 3, 4, 5, 6, 7 }; // an array of pin numbers
|
||||
int num_pins = 6; // the number of pins (i.e. the length of the array)
|
||||
|
||||
void setup()
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < num_pins; i++) // the array elements are numbered from 0 to num_pins - 1
|
||||
pinMode(pins[i], OUTPUT); // set each pin as an output
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < num_pins; i++) { // loop through each pin...
|
||||
digitalWrite(pins[i], HIGH); // turning it on,
|
||||
delay(timer); // pausing,
|
||||
digitalWrite(pins[i], LOW); // and turning it off.
|
||||
}
|
||||
for (i = num_pins - 1; i >= 0; i--) {
|
||||
digitalWrite(pins[i], HIGH);
|
||||
delay(timer);
|
||||
digitalWrite(pins[i], LOW);
|
||||
}
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
/* Melody
|
||||
* (cleft) 2005 D. Cuartielles for K3
|
||||
*
|
||||
* This example uses a piezo speaker to play melodies. It sends
|
||||
* a square wave of the appropriate frequency to the piezo, generating
|
||||
* the corresponding tone.
|
||||
*
|
||||
* The calculation of the tones is made following the mathematical
|
||||
* operation:
|
||||
*
|
||||
* timeHigh = period / 2 = 1 / (2 * toneFrequency)
|
||||
*
|
||||
* where the different tones are described as in the table:
|
||||
*
|
||||
* note frequency period timeHigh
|
||||
* c 261 Hz 3830 1915
|
||||
* d 294 Hz 3400 1700
|
||||
* e 329 Hz 3038 1519
|
||||
* f 349 Hz 2864 1432
|
||||
* g 392 Hz 2550 1275
|
||||
* a 440 Hz 2272 1136
|
||||
* b 493 Hz 2028 1014
|
||||
* C 523 Hz 1912 956
|
||||
*
|
||||
* http://www.arduino.cc/en/Tutorial/Melody
|
||||
*/
|
||||
|
||||
int speakerPin = 9;
|
||||
|
||||
int length = 15; // the number of notes
|
||||
char notes[] = "ccggaagffeeddc "; // a space represents a rest
|
||||
int beats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 };
|
||||
int tempo = 300;
|
||||
|
||||
void playTone(int tone, int duration) {
|
||||
for (long i = 0; i < duration * 1000L; i += tone * 2) {
|
||||
digitalWrite(speakerPin, HIGH);
|
||||
delayMicroseconds(tone);
|
||||
digitalWrite(speakerPin, LOW);
|
||||
delayMicroseconds(tone);
|
||||
}
|
||||
}
|
||||
|
||||
void playNote(char note, int duration) {
|
||||
char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
|
||||
int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };
|
||||
|
||||
// play the tone corresponding to the note name
|
||||
for (int i = 0; i < 8; i++) {
|
||||
if (names[i] == note) {
|
||||
playTone(tones[i], duration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
pinMode(speakerPin, OUTPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
for (int i = 0; i < length; i++) {
|
||||
if (notes[i] == ' ') {
|
||||
delay(beats[i] * tempo); // rest
|
||||
} else {
|
||||
playNote(notes[i], beats[i] * tempo);
|
||||
}
|
||||
|
||||
// pause between notes
|
||||
delay(tempo / 2);
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
// ADXL3xx
|
||||
//
|
||||
// Reads an Analog Devices ADXL3xx accelerometer and communicates the
|
||||
// acceleration to the computer. The pins used are designed to be easily
|
||||
// compatible with the breakout boards from Sparkfun, available from:
|
||||
// http://www.sparkfun.com/commerce/categories.php?c=80
|
||||
//
|
||||
// http://www.arduino.cc/en/Tutorial/ADXL3xx
|
||||
|
||||
// Breakout Board Pinout
|
||||
// 0: self test
|
||||
// 1: z-axis
|
||||
// 2: y-axis
|
||||
// 3: x-axis
|
||||
// 4: ground
|
||||
// 5: vcc
|
||||
|
||||
int groundpin = 18; // analog input pin 4
|
||||
int powerpin = 19; // analog input pin 5
|
||||
int xpin = 3; // x-axis of the accelerometer
|
||||
int ypin = 2; // y-axis
|
||||
int zpin = 1; // z-axis (only on 3-axis models)
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
|
||||
// Provide ground and power by using the analog inputs as normal
|
||||
// digital pins. This makes it possible to directly connect the
|
||||
// breakout board to the Arduino. If you use the normal 5V and
|
||||
// GND pins on the Arduino, you can remove these lines.
|
||||
pinMode(groundpin, OUTPUT);
|
||||
pinMode(powerpin, OUTPUT);
|
||||
digitalWrite(groundpin, LOW);
|
||||
digitalWrite(powerpin, HIGH);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.print(analogRead(xpin));
|
||||
Serial.print(" ");
|
||||
Serial.print(analogRead(ypin));
|
||||
Serial.print(" ");
|
||||
Serial.print(analogRead(zpin));
|
||||
Serial.println();
|
||||
delay(1000);
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
/* Knock Sensor
|
||||
* by DojoDave <http://www.0j0.org>
|
||||
*
|
||||
* Program using a Piezo element as if it was a knock sensor.
|
||||
*
|
||||
* We have to basically listen to an analog pin and detect
|
||||
* if the signal goes over a certain threshold. It writes
|
||||
* "knock" to the serial port if the Threshold is crossed,
|
||||
* and toggles the LED on pin 13.
|
||||
*
|
||||
* http://www.arduino.cc/en/Tutorial/Knock
|
||||
*/
|
||||
|
||||
int ledPin = 13; // led connected to control pin 13
|
||||
int knockSensor = 0; // the knock sensor will be plugged at analog pin 0
|
||||
byte val = 0; // variable to store the value read from the sensor pin
|
||||
int statePin = LOW; // variable used to store the last LED status, to toggle the light
|
||||
int THRESHOLD = 100; // threshold value to decide when the detected sound is a knock or not
|
||||
|
||||
void setup() {
|
||||
pinMode(ledPin, OUTPUT); // declare the ledPin as as OUTPUT
|
||||
Serial.begin(9600); // use the serial port
|
||||
}
|
||||
|
||||
void loop() {
|
||||
val = analogRead(knockSensor); // read the sensor and store it in the variable "val"
|
||||
if (val >= THRESHOLD) {
|
||||
statePin = !statePin; // toggle the status of the ledPin (this trick doesn't use time cycles)
|
||||
digitalWrite(ledPin, statePin); // turn the led on or off
|
||||
Serial.println("Knock!"); // send the string "Knock!" back to the computer, followed by newline
|
||||
}
|
||||
delay(100); // we have to make a delay to avoid overloading the serial port
|
||||
}
|
||||
|
@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Memsic2125
|
||||
*
|
||||
* Read the Memsic 2125 two-axis accelerometer. Converts the
|
||||
* pulses output by the 2125 into milli-g's (1/1000 of earth's
|
||||
* gravity) and prints them over the serial connection to the
|
||||
* computer.
|
||||
*
|
||||
* http://www.arduino.cc/en/Tutorial/Memsic2125
|
||||
*/
|
||||
|
||||
int xpin = 2;
|
||||
int ypin = 3;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
pinMode(xpin, INPUT);
|
||||
pinMode(ypin, INPUT);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
int pulseX, pulseY;
|
||||
int accX, accY;
|
||||
|
||||
// read pulse from x- and y-axes
|
||||
pulseX = pulseIn(xpin,HIGH);
|
||||
pulseY = pulseIn(ypin,HIGH);
|
||||
|
||||
// convert the pulse width into acceleration
|
||||
// accX and accY are in milli-g's: earth's gravity is 1000.
|
||||
accX = ((pulseX / 10) - 500) * 8;
|
||||
accY = ((pulseY / 10) - 500) * 8;
|
||||
|
||||
// print the acceleration
|
||||
Serial.print(accX);
|
||||
Serial.print(" ");
|
||||
Serial.print(accY);
|
||||
Serial.println();
|
||||
|
||||
delay(100);
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
int pingPin = 7;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
long duration, inches, cm;
|
||||
|
||||
// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
|
||||
// We give a short LOW pulse beforehand to ensure a clean HIGH pulse.
|
||||
pinMode(pingPin, OUTPUT);
|
||||
digitalWrite(pingPin, LOW);
|
||||
delayMicroseconds(2);
|
||||
digitalWrite(pingPin, HIGH);
|
||||
delayMicroseconds(5);
|
||||
digitalWrite(pingPin, LOW);
|
||||
|
||||
// The same pin is used to read the signal from the PING))): a HIGH
|
||||
// pulse whose duration is the time (in microseconds) from the sending
|
||||
// of the ping to the reception of its echo off of an object.
|
||||
pinMode(pingPin, INPUT);
|
||||
duration = pulseIn(pingPin, HIGH);
|
||||
|
||||
// convert the time into a distance
|
||||
inches = microsecondsToInches(duration);
|
||||
cm = microsecondsToCentimeters(duration);
|
||||
|
||||
Serial.print(inches);
|
||||
Serial.print("in, ");
|
||||
Serial.print(cm);
|
||||
Serial.print("cm");
|
||||
Serial.println();
|
||||
|
||||
delay(100);
|
||||
}
|
||||
|
||||
long microsecondsToInches(long microseconds)
|
||||
{
|
||||
// According to Parallax's datasheet for the PING))), there are
|
||||
// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
|
||||
// second). This gives the distance travelled by the ping, outbound
|
||||
// and return, so we divide by 2 to get the distance of the obstacle.
|
||||
// See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
|
||||
return microseconds / 74 / 2;
|
||||
}
|
||||
|
||||
long microsecondsToCentimeters(long microseconds)
|
||||
{
|
||||
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
|
||||
// The ping travels out and back, so to find the distance of the
|
||||
// object we take half of the distance travelled.
|
||||
return microseconds / 29 / 2;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user