mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-18 07:52:14 +01:00
Adding Tom's new examples.
This commit is contained in:
parent
8d73929f5d
commit
29c339013a
@ -0,0 +1,50 @@
|
||||
/*
|
||||
Analog input, analog output, serial output
|
||||
|
||||
Reads an analog input pin, maps the result to a range from 0 to 255
|
||||
and uses the result to set the pulsewidth modulation (PWM) of an output pin.
|
||||
Also prints the results to the serial monitor.
|
||||
|
||||
The circuit:
|
||||
* potentiometer connected to analog pin 0.
|
||||
Center pin of the potentiometer goes to the analog pin.
|
||||
side pins of the potentiometer go to +5V and ground
|
||||
* LED connected from digital pin 9 to ground
|
||||
|
||||
created 29 Dec. 2008
|
||||
by Tom Igoe
|
||||
|
||||
*/
|
||||
|
||||
// These constants won't change. They're used to give names
|
||||
// to the pins used:
|
||||
const int analogInPin = 0; // Analog input pin that the potentiometer is attached to
|
||||
const int analogOutPin = 9; // Analog output pin that the LED is attached to
|
||||
|
||||
int sensorValue = 0; // value read from the pot
|
||||
int outputValue = 0; // value output to the PWM (analog out)
|
||||
|
||||
void setup() {
|
||||
// initialize serial communications at 9600 bps:
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// read the analog in value:
|
||||
sensorValue = analogRead(analogInPin);
|
||||
// map it to the range of the analog out:
|
||||
outputValue = map(sensorValue, 0, 1023, 0, 255);
|
||||
// change the analog out value:
|
||||
analogWrite(analogOutPin, outputValue);
|
||||
|
||||
// print the results to the serial monitor:
|
||||
Serial.print("sensor = " );
|
||||
Serial.print(sensorValue);
|
||||
Serial.print("\t output = ");
|
||||
Serial.println(outputValue);
|
||||
|
||||
// wait 10 milliseconds before the next loop
|
||||
// for the analog-to-digital converter to settle
|
||||
// after the last reading:
|
||||
delay(10);
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
Analog input, serial output
|
||||
|
||||
Reads an analog input pin, prints the results to the serial monitor.
|
||||
|
||||
The circuit:
|
||||
|
||||
* potentiometer connected to analog pin 0.
|
||||
Center pin of the potentiometer goes to the analog pin.
|
||||
side pins of the potentiometer go to +5V and ground
|
||||
|
||||
created over and over again
|
||||
by Tom Igoe and everyone who's ever used Arduino
|
||||
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// read the analog input into a variable:
|
||||
int analogValue = analogRead(0);
|
||||
// print the result:
|
||||
Serial.println(analogValue);
|
||||
// wait 10 milliseconds for the analog-to-digital converter
|
||||
// to settle after the last reading:
|
||||
delay(10);
|
||||
}
|
48
build/shared/examples/Analog/AnalogInput/AnalogInput.pde
Normal file
48
build/shared/examples/Analog/AnalogInput/AnalogInput.pde
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
Analog Input
|
||||
Demonstrates analog input by reading an analog sensor on analog pin 0 and
|
||||
turning 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().
|
||||
|
||||
The circuit:
|
||||
* Potentiometer attached to analog input 0
|
||||
* center pin of the potentiometer to the analog pin
|
||||
* one side pin (either one) to ground
|
||||
* the other side pin to +5V
|
||||
* LED anode (long leg) attached to digital output 13
|
||||
* LED cathode (short leg) attached to ground
|
||||
|
||||
* Note: because most Arduinos have a built-in LED attached
|
||||
to pin 13 on the board, the LED is optional.
|
||||
|
||||
|
||||
Created by David Cuartielles
|
||||
Modified 16 Jun 2009
|
||||
By Tom Igoe
|
||||
|
||||
http://arduino.cc/en/Tutorial/AnalogInput
|
||||
|
||||
*/
|
||||
|
||||
int sensorPin = 0; // select the input pin for the potentiometer
|
||||
int ledPin = 13; // select the pin for the LED
|
||||
int sensorValue = 0; // variable to store the value coming from the sensor
|
||||
|
||||
void setup() {
|
||||
// declare the ledPin as an OUTPUT:
|
||||
pinMode(ledPin, OUTPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// read the value from the sensor:
|
||||
sensorValue = analogRead(sensorPin);
|
||||
// turn the ledPin on
|
||||
digitalWrite(ledPin, HIGH);
|
||||
// stop the program for <sensorValue> milliseconds:
|
||||
delay(sensorValue);
|
||||
// turn the ledPin off:
|
||||
digitalWrite(ledPin, LOW);
|
||||
// stop the program for for <sensorValue> milliseconds:
|
||||
delay(sensorValue);
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
Mega analogWrite() test
|
||||
|
||||
This sketch fades LEDs up and down one at a time on digital pins 2 through 13.
|
||||
This sketch was written for the Arduino Mega, and will not work on previous boards.
|
||||
|
||||
The circuit:
|
||||
* LEDs attached from pins 2 through 13 to ground.
|
||||
|
||||
created 8 Feb 2009
|
||||
by Tom Igoe
|
||||
*/
|
||||
// These constants won't change. They're used to give names
|
||||
// to the pins used:
|
||||
const int lowestPin = 2;
|
||||
const int highestPin = 13;
|
||||
|
||||
|
||||
void setup() {
|
||||
// set pins 2 through 13 as outputs:
|
||||
for (int thisPin =lowestPin; thisPin <= highestPin; thisPin++) {
|
||||
pinMode(thisPin, OUTPUT);
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// iterate over the pins:
|
||||
for (int thisPin =lowestPin; thisPin <= highestPin; thisPin++) {
|
||||
// fade the LED on thisPin from off to brightest:
|
||||
for (int brightness = 0; brightness < 255; brightness++) {
|
||||
analogWrite(thisPin, brightness);
|
||||
delay(2);
|
||||
}
|
||||
// fade the LED on thisPin from brithstest to off:
|
||||
for (int brightness = 255; brightness >= 0; brightness--) {
|
||||
analogWrite(thisPin, brightness);
|
||||
delay(2);
|
||||
}
|
||||
// pause between LEDs:
|
||||
delay(100);
|
||||
}
|
||||
}
|
73
build/shared/examples/Analog/Calibration/Calibration.pde
Normal file
73
build/shared/examples/Analog/Calibration/Calibration.pde
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
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
|
||||
attached to the sensor pin.
|
||||
|
||||
The sensor minumum and maximum initial values may seem backwards.
|
||||
Initially, you set the minimum high and listen for anything
|
||||
lower, saving it as the new minumum. Likewise, you set the
|
||||
maximum low and listen for anything higher as the new maximum.
|
||||
|
||||
The circuit:
|
||||
* Analog sensor (potentiometer will do) attached to analog input 0
|
||||
* LED attached from digital pin 9 to ground
|
||||
|
||||
created 29 Oct 2008
|
||||
By David A Mellis
|
||||
Modified 17 Jun 2009
|
||||
By Tom Igoe
|
||||
|
||||
http://arduino.cc/en/Tutorial/Calibration
|
||||
|
||||
*/
|
||||
|
||||
// These constants won't change:
|
||||
const int sensorPin = 2; // pin that the sensor is attached to
|
||||
const int ledPin = 9; // pin that the LED is attached to
|
||||
|
||||
// variables:
|
||||
int sensorValue = 0; // the sensor value
|
||||
int sensorMin = 1023; // minimum sensor value
|
||||
int sensorMax = 0; // maximum sensor value
|
||||
|
||||
|
||||
void setup() {
|
||||
// turn on LED to signal the start of the calibration period:
|
||||
pinMode(13, OUTPUT);
|
||||
digitalWrite(13, HIGH);
|
||||
|
||||
// calibrate during the first five seconds
|
||||
while (millis() < 5000) {
|
||||
sensorValue = analogRead(sensorPin);
|
||||
|
||||
// record the maximum sensor value
|
||||
if (sensorValue > sensorMax) {
|
||||
sensorMax = sensorValue;
|
||||
}
|
||||
|
||||
// record the minimum sensor value
|
||||
if (sensorValue < sensorMin) {
|
||||
sensorMin = sensorValue;
|
||||
}
|
||||
}
|
||||
|
||||
// signal the end of the calibration period
|
||||
digitalWrite(13, LOW);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// read the sensor:
|
||||
sensorValue = analogRead(sensorPin);
|
||||
|
||||
// apply the calibration to the sensor reading
|
||||
sensorValue = map(sensorValue, sensorMin, sensorMax, 0, 255);
|
||||
|
||||
// in case the sensor value is outside the range seen during calibration
|
||||
sensorValue = constrain(sensorValue, 0, 255);
|
||||
|
||||
// fade the LED using the calibrated value:
|
||||
analogWrite(ledPin, sensorValue);
|
||||
}
|
43
build/shared/examples/Analog/Fading/Fading.pde
Normal file
43
build/shared/examples/Analog/Fading/Fading.pde
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
Fading
|
||||
|
||||
This example shows how to fade an LED using the analogWrite() function.
|
||||
|
||||
The circuit:
|
||||
* LED attached from digital pin 9 to ground.
|
||||
|
||||
Created 1 Nov 2008
|
||||
By David A. Mellis
|
||||
Modified 17 June 2009
|
||||
By Tom Igoe
|
||||
|
||||
http://arduino.cc/en/Tutorial/Fading
|
||||
|
||||
*/
|
||||
|
||||
|
||||
int ledPin = 9; // LED connected to digital pin 9
|
||||
|
||||
void setup() {
|
||||
// nothing happens in setup
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// fade in from min to max in increments of 5 points:
|
||||
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
|
||||
// sets the value (range from 0 to 255):
|
||||
analogWrite(ledPin, fadeValue);
|
||||
// wait for 30 milliseconds to see the dimming effect
|
||||
delay(30);
|
||||
}
|
||||
|
||||
// fade out from max to min in increments of 5 points:
|
||||
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
|
||||
// sets the value (range from 0 to 255):
|
||||
analogWrite(ledPin, fadeValue);
|
||||
// wait for 30 milliseconds to see the dimming effect
|
||||
delay(30);
|
||||
}
|
||||
}
|
||||
|
||||
|
64
build/shared/examples/Analog/Smoothing/Smoothing.pde
Normal file
64
build/shared/examples/Analog/Smoothing/Smoothing.pde
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
|
||||
Smoothing
|
||||
|
||||
Reads repeatedly from an analog input, calculating a running average
|
||||
and printing it to the computer. Keeps ten readings in an array and
|
||||
continually averages them.
|
||||
|
||||
The circuit:
|
||||
* Analog sensor (potentiometer will do) attached to analog input 0
|
||||
|
||||
Created 22 April 2007
|
||||
By David A. Mellis <dam@mellis.org>
|
||||
|
||||
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 constant rather than a normal variable lets
|
||||
// use this value to determine the size of the readings array.
|
||||
const int 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()
|
||||
{
|
||||
// initialize serial communication with computer:
|
||||
Serial.begin(9600);
|
||||
// initialize all the readings to 0:
|
||||
for (int thisReading = 0; thisReading < numReadings; thisReading++)
|
||||
readings[thisReading] = 0;
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// subtract the last reading:
|
||||
total= total - readings[index];
|
||||
// read from the sensor:
|
||||
readings[index] = analogRead(inputPin);
|
||||
// add the reading to the total:
|
||||
total= total + readings[index];
|
||||
// advance to the next position in the array:
|
||||
index = index + 1;
|
||||
|
||||
// if we're at the end of the array...
|
||||
if (index >= numReadings)
|
||||
// ...wrap around to the beginning:
|
||||
index = 0;
|
||||
|
||||
// calculate the average:
|
||||
average = total / numReadings;
|
||||
// send it to the computer (as ASCII digits)
|
||||
Serial.println(average, DEC);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,73 @@
|
||||
/*
|
||||
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++;
|
||||
}
|
360
build/shared/examples/Communication/Dimmer/Dimmer.pde
Normal file
360
build/shared/examples/Communication/Dimmer/Dimmer.pde
Normal file
@ -0,0 +1,360 @@
|
||||
/*
|
||||
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 ]
|
||||
}
|
||||
|
||||
}
|
||||
]
|
||||
}
|
||||
*/
|
578
build/shared/examples/Communication/Graph/Graph.pde
Normal file
578
build/shared/examples/Communication/Graph/Graph.pde
Normal file
@ -0,0 +1,578 @@
|
||||
/*
|
||||
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 ]
|
||||
}
|
||||
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
*/
|
47
build/shared/examples/Communication/MIDI/Midi.pde
Normal file
47
build/shared/examples/Communication/MIDI/Midi.pde
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
MIDI note player
|
||||
|
||||
This sketch shows how to use the serial transmit pin (pin 1) to send MIDI note data.
|
||||
If this circuit is connected to a MIDI synth, it will play
|
||||
the notes F#-0 (0x1E) to F#-5 (0x5A) in sequence.
|
||||
|
||||
|
||||
The circuit:
|
||||
* digital in 1 connected to MIDI jack pin 5
|
||||
* MIDI jack pin 2 connected to ground
|
||||
* MIDI jack pin 4 connected to +5V through 220-ohm resistor
|
||||
Attach a MIDI cable to the jack, then to a MIDI synth, and play music.
|
||||
|
||||
created 13 Jun 2006
|
||||
modified 2 Jul 2009
|
||||
by Tom Igoe
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/MIDI
|
||||
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
// Set MIDI baud rate:
|
||||
Serial.begin(31250);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// play notes from F#-0 (0x1E) to F#-5 (0x5A):
|
||||
for (intnote = 0x1E; note < 0x5A; note ++) {
|
||||
//Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
|
||||
noteOn(0x90, note, 0x45);
|
||||
delay(100);
|
||||
//Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
|
||||
noteOn(0x90, note, 0x00);
|
||||
delay(100);
|
||||
}
|
||||
}
|
||||
|
||||
// plays a MIDI note. Doesn't check to see that
|
||||
// cmd is greater than 127, or that data values are less than 127:
|
||||
void noteOn(int cmd, int pitch, int velocity) {
|
||||
Serial.print(cmd, BYTE);
|
||||
Serial.print(pitch, BYTE);
|
||||
Serial.print(velocity, BYTE);
|
||||
}
|
||||
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
Mega multple serial test
|
||||
|
||||
Receives from the main serial port, sends to the others.
|
||||
Receives from serial port 1, sends to the main serial (Serial 0).
|
||||
|
||||
This example works only on the Arduino Mega
|
||||
|
||||
The circuit:
|
||||
* Any serial device attached to Serial port 1
|
||||
* Serial monitor open on Serial port 0:
|
||||
|
||||
created 30 Dec. 2008
|
||||
by Tom Igoe
|
||||
|
||||
*/
|
||||
|
||||
|
||||
void setup() {
|
||||
// initialize both serial ports:
|
||||
Serial.begin(9600);
|
||||
Serial1.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// read from port 1, send to port 0:
|
||||
if (Serial1.available()) {
|
||||
int inByte = Serial1.read();
|
||||
Serial.print(inByte, BYTE);
|
||||
}
|
||||
}
|
@ -0,0 +1,707 @@
|
||||
/*
|
||||
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 ]
|
||||
}
|
||||
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
*/
|
@ -0,0 +1,1193 @@
|
||||
/*
|
||||
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" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
*/
|
@ -0,0 +1,1267 @@
|
||||
/*
|
||||
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" : [ ]
|
||||
}
|
||||
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
*/
|
@ -0,0 +1,697 @@
|
||||
/*
|
||||
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 ]
|
||||
}
|
||||
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
*/
|
55
build/shared/examples/Control/Arrays/Arrays.pde
Normal file
55
build/shared/examples/Control/Arrays/Arrays.pde
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
Arrays
|
||||
|
||||
Demonstrates the use of an array to hold pin numbers
|
||||
in order to iterate over the pins in a sequence.
|
||||
Lights multiple LEDs in sequence, then in reverse.
|
||||
|
||||
Unlike the For Loop tutorial, where the pins have to be
|
||||
contiguous, here the pins can be in any random order.
|
||||
|
||||
The circuit:
|
||||
* LEDs from pins 2 through 7 to ground
|
||||
|
||||
created 2006
|
||||
by David A. Mellis
|
||||
modified 5 Jul 2009
|
||||
by Tom Igoe
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/Array
|
||||
*/
|
||||
|
||||
int timer = 100; // The higher the number, the slower the timing.
|
||||
int ledPins[] = {
|
||||
2, 7, 4, 6, 5, 3 }; // an array of pin numbers to which LEDs are attached
|
||||
int pinCount = 6; // the number of pins (i.e. the length of the array)
|
||||
|
||||
void setup() {
|
||||
int thisPin;
|
||||
// the array elements are numbered from 0 to (pinCount - 1).
|
||||
// use a for loop to initialize each pin as an output:
|
||||
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
|
||||
pinMode(ledPins[thisPin], OUTPUT);
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// loop from the lowest pin to the highest:
|
||||
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
|
||||
// turn the pin on:
|
||||
digitalWrite(ledPins[thisPin], HIGH);
|
||||
delay(timer);
|
||||
// turn the pin off:
|
||||
digitalWrite(ledPins[thisPin], LOW);
|
||||
|
||||
}
|
||||
|
||||
// loop from the highest pin to the lowest:
|
||||
for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) {
|
||||
// turn the pin on:
|
||||
digitalWrite(ledPins[thisPin], HIGH);
|
||||
delay(timer);
|
||||
// turn the pin off:
|
||||
digitalWrite(ledPins[thisPin], LOW);
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
For Loop Iteration
|
||||
|
||||
Demonstrates the use of a for() loop.
|
||||
Lights multiple LEDs in sequence, then in reverse.
|
||||
|
||||
The circuit:
|
||||
* LEDs from pins 2 through 7 to ground
|
||||
|
||||
created 2006
|
||||
by David A. Mellis
|
||||
modified 5 Jul 2009
|
||||
by Tom Igoe
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/ForLoop
|
||||
*/
|
||||
|
||||
int timer = 100; // The higher the number, the slower the timing.
|
||||
|
||||
void setup() {
|
||||
// use a for loop to initialize each pin as an output:
|
||||
for (int thisPin = 2; thisPin < 8; thisPin++) {
|
||||
pinMode(thisPin, OUTPUT);
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// loop from the lowest pin to the highest:
|
||||
for (int thisPin = 0; thisPin < 8; thisPin++) {
|
||||
// turn the pin on:
|
||||
digitalWrite(thisPin, HIGH);
|
||||
delay(timer);
|
||||
// turn the pin off:
|
||||
digitalWrite(thisPin, LOW);
|
||||
}
|
||||
|
||||
// loop from the highest pin to the lowest:
|
||||
for (int thisPin = 7; thisPin >= 2; thisPin--) {
|
||||
// turn the pin on:
|
||||
digitalWrite(thisPin, HIGH);
|
||||
delay(timer);
|
||||
// turn the pin off:
|
||||
digitalWrite(thisPin, LOW);
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
Conditionals - If statement
|
||||
|
||||
This example demonstrates the use of if() statements.
|
||||
It reads the state of a potentiometer (an analog input) and turns on an LED
|
||||
only if the LED goes above a certain threshold level. It prints the analog value
|
||||
regardless of the level.
|
||||
|
||||
The circuit:
|
||||
* potentiometer connected to analog pin 0.
|
||||
Center pin of the potentiometer goes to the analog pin.
|
||||
side pins of the potentiometer go to +5V and ground
|
||||
* LED connected from digital pin 13 to ground
|
||||
|
||||
* Note: On most Arduino boards, there is already an LED on the board
|
||||
connected to pin 13, so you don't need any extra components for this example.
|
||||
|
||||
created 17 Jan 2009
|
||||
by Tom Igoe
|
||||
|
||||
http://arduino.cc/en/Tutorial/
|
||||
|
||||
*/
|
||||
|
||||
// These constants won't change:
|
||||
const int analogPin = 0; // pin that the sensor is attached to
|
||||
const int ledPin = 13; // pin that the LED is attached to
|
||||
const int threshold = 400; // an arbitrary threshold level that's in the range of the analog input
|
||||
|
||||
void setup() {
|
||||
// initialize the LED pin as an output:
|
||||
pinMode(LED, OUTPUT);
|
||||
// initialize serial communications:
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// read the value of the potentiometer:
|
||||
int analogValue = analogRead(analogPin);
|
||||
|
||||
// if the analog value is high enough, turn on the LED:
|
||||
if (analogValue > threshold) {
|
||||
digitalWrite(ledPin, HIGH);
|
||||
}
|
||||
else {
|
||||
digitalWrite(ledPin,LOW);
|
||||
}
|
||||
|
||||
// print the analog value:
|
||||
Serial.println(analogValue, DEC);
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,86 @@
|
||||
/*
|
||||
Conditionals - while statement
|
||||
|
||||
This example demonstrates the use of while() statements.
|
||||
|
||||
While the pushbutton is pressed, the sketch runs the calibration routine.
|
||||
The sensor readings during the while loop define the minimum and maximum
|
||||
of expected values from the photo resistor.
|
||||
|
||||
This is a variation on the calibrate example.
|
||||
|
||||
The circuit:
|
||||
* photo resistor connected from +5V to analog in pin 0
|
||||
* 10K resistor connected from ground to analog in pin 0
|
||||
* LED connected from digital pin 9 to ground through 220 ohm resistor
|
||||
* pushbutton attached from pin 2 to +5V
|
||||
* 10K resistor attached from pin 2 to ground
|
||||
|
||||
created 17 Jan 2009
|
||||
modified 25 Jun 2009
|
||||
by Tom Igoe
|
||||
|
||||
http://arduino.cc/en/Tutorial/WhileLoop
|
||||
|
||||
*/
|
||||
|
||||
|
||||
// These constants won't change:
|
||||
const int sensorPin = 2; // pin that the sensor is attached to
|
||||
const int ledPin = 9; // pin that the LED is attached to
|
||||
const int indicatorLedPin = 13; // pin that the built-in LED is attached to
|
||||
const int buttonPin = 2; // pin that the button is attached to
|
||||
|
||||
|
||||
// These variables will change:
|
||||
int sensorMin = 1023; // minimum sensor value
|
||||
int sensorMax = 0; // maximum sensor value
|
||||
int sensorValue = 0; // the sensor value
|
||||
|
||||
|
||||
void setup() {
|
||||
// set the LED pins as outputs and the switch pin as input:
|
||||
pinMode(indicatorLedPin, OUTPUT);
|
||||
pinMode (ledPin, OUTPUT);
|
||||
pinMode (buttonPin, INPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// while the button is pressed, take calibration readings:
|
||||
while (digitalRead(buttonPin) == HIGH) {
|
||||
calibrate();
|
||||
}
|
||||
// signal the end of the calibration period
|
||||
digitalWrite(indicatorLedPin, LOW);
|
||||
|
||||
// read the sensor:
|
||||
sensorValue = analogRead(sensorPin);
|
||||
|
||||
// apply the calibration to the sensor reading
|
||||
sensorValue = map(sensorValue, sensorMin, sensorMax, 0, 255);
|
||||
|
||||
// in case the sensor value is outside the range seen during calibration
|
||||
sensorValue = constrain(sensorValue, 0, 255);
|
||||
|
||||
// fade the LED using the calibrated value:
|
||||
analogWrite(ledPin, sensorValue);
|
||||
}
|
||||
|
||||
void calibrate() {
|
||||
// turn on the indicator LED to indicate that calibration is happening:
|
||||
digitalWrite(indicatorLedPin, HIGH);
|
||||
// read the sensor:
|
||||
sensorValue = analogRead(sensorPin);
|
||||
|
||||
// record the maximum sensor value
|
||||
if (sensorValue > sensorMax) {
|
||||
sensorMax = sensorValue;
|
||||
}
|
||||
|
||||
// record the minimum sensor value
|
||||
if (sensorValue < sensorMin) {
|
||||
sensorMin = sensorValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,86 @@
|
||||
/*
|
||||
Conditionals - while statement
|
||||
|
||||
This example demonstrates the use of while() statements.
|
||||
|
||||
It reads the state of a potentiometer (an analog input) and blinks an LED
|
||||
while the LED remains above a certain threshold level. It prints the analog value
|
||||
only if it's below the threshold.
|
||||
|
||||
This example uses principles explained in the BlinkWithoutDelay example as well.
|
||||
|
||||
The circuit:
|
||||
* potentiometer connected to analog pin 0.
|
||||
Center pin of the potentiometer goes to the analog pin.
|
||||
side pins of the potentiometer go to +5V and ground
|
||||
* LED connected from digital pin 13 to ground
|
||||
|
||||
* Note: On most Arduino boards, there is already an LED on the board
|
||||
connected to pin 13, so you don't need any extra components for this example.
|
||||
|
||||
created 17 Jan 2009
|
||||
by Tom Igoe
|
||||
|
||||
*/
|
||||
|
||||
#define ledPin 13 // the pin for the LED
|
||||
#define analogPin 0 // the analog pin that the potentiometer is attached to
|
||||
|
||||
#include "WProgram.h"
|
||||
void setup();
|
||||
void loop();
|
||||
int threshold = 400; // an arbitrary threshold level that's in the range of the analog input
|
||||
int ledState = LOW; // the state of the LED
|
||||
int lastBlinkTime = 0; // last time the LED changed
|
||||
int blinkDelay = 500; // how long to hold between changes of the LED
|
||||
int analogValue; // variable to hold the value of the analog input
|
||||
void setup() {
|
||||
// initialize the LED pin as an output:
|
||||
pinMode(ledPin, OUTPUT);
|
||||
// initialize serial communications:
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// read the value of the potentiometer:
|
||||
analogValue = analogRead(analogPin);
|
||||
|
||||
// if the analog value is high enough, turn on the LED:
|
||||
while (analogValue > threshold) {
|
||||
// if enough time has passed since the last change of the LED,
|
||||
// then change it. Note you're using the technique from BlinkWithoutDelay
|
||||
// here so that the while loop doesn't delay the rest of the program:
|
||||
|
||||
if (millis() - lastBlinkTime > blinkDelay) {
|
||||
// if the ledState is high, this makes it low, and vice versa:
|
||||
ledState = !ledState;
|
||||
digitalWrite(ledPin, ledState);
|
||||
|
||||
// save the last time the LED changed in a variable:
|
||||
lastBlinkTime = millis();
|
||||
}
|
||||
// while you're in the while loop, you have to read the
|
||||
// input again:
|
||||
analogValue = analogRead(analogPin);
|
||||
}
|
||||
|
||||
// if you're below the threshold, print the analog value:
|
||||
Serial.println(analogValue, DEC);
|
||||
// turn the LED off:
|
||||
digitalWrite(ledPin, LOW);
|
||||
|
||||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
init();
|
||||
|
||||
setup();
|
||||
|
||||
for (;;)
|
||||
loop();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -0,0 +1 @@
|
||||
:00000001FF
|
Binary file not shown.
@ -0,0 +1,155 @@
|
||||
:100000000C9462000C94DC020C94F9020C948A00AB
|
||||
:100010000C948A000C948A000C948A000C948A0038
|
||||
:100020000C948A000C948A000C948A000C948A0028
|
||||
:100030000C948A000C948A000C948A000C948A0018
|
||||
:100040000C9416030C948A000C94F6000C948A000D
|
||||
:100050000C948A000C948A000C948A000C948A00F8
|
||||
:100060000C948A000C948A000000000024002700F1
|
||||
:100070002A0000000000250028002B0000000000DE
|
||||
:1000800023002600290004040404040404040202DA
|
||||
:100090000202020203030303030301020408102007
|
||||
:1000A0004080010204081020010204081020000012
|
||||
:1000B0000007000201000003040600000000000029
|
||||
:1000C0000000AF0111241FBECFEFD4E0DEBFCDBFD3
|
||||
:1000D00011E0A0E0B1E0EAE8F9E002C005900D927D
|
||||
:1000E000AC30B107D9F711E0ACE0B1E001C01D922E
|
||||
:1000F000A83BB107E1F710E0C4ECD0E004C02297C0
|
||||
:10010000FE010E94BF04C23CD107C9F70E94EF0064
|
||||
:100110000C94C3040C94000032C00E94860320910A
|
||||
:100120000E0130910F01442737FD4095542F621B7B
|
||||
:10013000730B840B950B209102013091030144272E
|
||||
:1001400037FD4095542F2617370748075907B8F44D
|
||||
:1001500060E070E080910C0190910D01892B11F409
|
||||
:1001600061E070E070930D0160930C018DE00E94DE
|
||||
:100170000C040E94860370930F0160930E0180E0CF
|
||||
:100180000E94CE03909311018093100120911001E1
|
||||
:100190003091110180910001909101018217930724
|
||||
:1001A0000CF4BBCFA901662757FD6095762F2AE096
|
||||
:1001B00030E086E991E00E94D10260E08DE00E948B
|
||||
:1001C0000C04089561E08DE00E94EC0340E855E2E4
|
||||
:1001D00060E070E086E991E00E94330108950E949A
|
||||
:1001E00094030E94E2000E948C00FDCF1F920F92A8
|
||||
:1001F0000FB60F9211242F933F934F935F936F93FA
|
||||
:100200007F938F939F93AF93BF93EF93FF9340910F
|
||||
:10021000C600E0919201F0919301CF01019660E850
|
||||
:1002200070E00E9459049C01809194019091950185
|
||||
:100230002817390739F0EE5EFE4F40833093930163
|
||||
:1002400020939201FF91EF91BF91AF919F918F9178
|
||||
:100250007F916F915F914F913F912F910F900FBEC2
|
||||
:100260000F901F901895AF92BF92CF92DF92EF92AE
|
||||
:10027000FF920F931F93CF93DF936C017A018B0151
|
||||
:10028000DC011496AD90BC901597CB01BA0122E029
|
||||
:1002900030E040E050E00E948E04205C3D4B404F37
|
||||
:1002A0005F4FCA01B901A80197010E948E04C901DC
|
||||
:1002B000DA010197A109B109292F3A2F4B2F5527B0
|
||||
:1002C00047FD5A950196A11DB11DE5012883E60160
|
||||
:1002D000EE81FF8181508083EA85FB85208141E0AA
|
||||
:1002E00050E0CA010E8402C0880F991F0A94E2F7F9
|
||||
:1002F000282B2083EA85FB852081CA010F8402C058
|
||||
:10030000880F991F0A94E2F7282B2083EA85FB8542
|
||||
:100310008081088802C0440F551F0A94E2F7842B9D
|
||||
:100320008083DF91CF911F910F91FF90EF90DF902D
|
||||
:10033000CF90BF90AF900895FC01A085B185218931
|
||||
:100340008C9190E0022E02C0959587950A94E2F771
|
||||
:1003500080FFF6CF0484F585E02D6083089589E061
|
||||
:1003600091E0909397018093960182E191E09093C0
|
||||
:1003700099018093980185EC90E090939B01809384
|
||||
:100380009A0184EC90E090939D0180939C0180EC15
|
||||
:1003900090E090939F0180939E0181EC90E0909378
|
||||
:1003A000A1018093A00186EC90E09093A30180933B
|
||||
:1003B000A20184E08093A40183E08093A50187E0FB
|
||||
:1003C0008093A60185E08093A70108950F931F9362
|
||||
:1003D0008C01DC01ED91FC910190F081E02D6DE04C
|
||||
:1003E0000995D801ED91FC910190F081E02D6AE032
|
||||
:1003F000C80109951F910F9108952F923F924F9236
|
||||
:100400005F926F927F928F929F92AF92BF92CF92A4
|
||||
:10041000DF92EF92FF920F931F93DF93CF93CDB7AD
|
||||
:10042000DEB7A0970FB6F894DEBF0FBECDBF1C019C
|
||||
:100430006A017B01411551056105710549F4DC0133
|
||||
:10044000ED91FC910190F081E02D60E3099554C09D
|
||||
:10045000882499245401422E55246624772401E0EF
|
||||
:1004600010E00C0F1D1F080D191DC701B601A301D7
|
||||
:1004700092010E946C04F80160830894811C911C15
|
||||
:10048000A11CB11CC701B601A30192010E946C041A
|
||||
:10049000C901DA016C017D01C114D104E104F10448
|
||||
:1004A000F1F681E0E82EF12CEC0EFD1EE80CF91CB3
|
||||
:1004B0003E010894611C711CD501C4010197A1097A
|
||||
:1004C000B1096C01C818D90814C0F601EE0DFF1D62
|
||||
:1004D00060816A3010F4605D01C0695CD101ED910A
|
||||
:1004E000FC910190F081E02DC10109950894E1088B
|
||||
:1004F000F1086E147F0449F7A0960FB6F894DEBF9A
|
||||
:100500000FBECDBFCF91DF911F910F91FF90EF9064
|
||||
:10051000DF90CF90BF90AF909F908F907F906F9023
|
||||
:100520005F904F903F902F900895EF92FF920F931E
|
||||
:100530001F93CF93DF93EC017A018B0177FF0FC0FC
|
||||
:10054000E881F9810190F081E02D6DE20995109527
|
||||
:100550000095F094E094E11CF11C011D111D2AE0AE
|
||||
:10056000B801A701CE010E94FD01DF91CF911F913B
|
||||
:100570000F91FF90EF900895DC012115310541F4B2
|
||||
:10058000ED91FC910190F081E02D642F0995089583
|
||||
:100590002A30310519F40E94950208950E94FD0148
|
||||
:1005A00008950F931F938C010E94BC02C8010E9402
|
||||
:1005B000E6011F910F9108951F920F920FB60F92AF
|
||||
:1005C00011248F939F93EF93FF938091A8019091B3
|
||||
:1005D000A901892B29F0E091A801F091A9010995C1
|
||||
:1005E000FF91EF919F918F910F900FBE0F901F90F1
|
||||
:1005F00018951F920F920FB60F9211248F939F930D
|
||||
:10060000EF93FF938091AA019091AB01892B29F080
|
||||
:10061000E091AA01F091AB010995FF91EF919F91B3
|
||||
:100620008F910F900FBE0F901F9018951F920F92F1
|
||||
:100630000FB60F9211242F938F939F93AF93BF9375
|
||||
:100640008091AC019091AD01A091AE01B091AF014C
|
||||
:100650000196A11DB11D8093AC019093AD01A093B3
|
||||
:10066000AE01B093AF018091B0019091B101A09122
|
||||
:10067000B201B091B3018050904CAF4FBF4F809307
|
||||
:10068000B0019093B101A093B201B093B30127C020
|
||||
:100690008091B0019091B101A091B201B091B301EC
|
||||
:1006A00080589E43A040B0408093B0019093B10128
|
||||
:1006B000A093B201B093B3018091B4019091B501C0
|
||||
:1006C000A091B601B091B7010196A11DB11D809313
|
||||
:1006D000B4019093B501A093B601B093B701809196
|
||||
:1006E000B0019091B101A091B201B091B3018158D4
|
||||
:1006F0009E43A040B04060F6BF91AF919F918F9113
|
||||
:100700002F910F900FBE0F901F9018958FB7F894F0
|
||||
:100710002091B4013091B5014091B6015091B701DB
|
||||
:100720008FBFB901CA010895789484B5826084BDF1
|
||||
:1007300084B5816084BD85B5826085BD85B58160E5
|
||||
:1007400085BDEEE6F0E0808181608083E1E8F0E045
|
||||
:10075000808182608083808181608083E0E8F0E036
|
||||
:10076000808181608083E1EBF0E080818460808320
|
||||
:10077000E0EBF0E0808181608083EAE7F0E0808157
|
||||
:1007800084608083808182608083808181608083B7
|
||||
:100790008081806880831092C10008958770909155
|
||||
:1007A00004019295990F990F907C982B90937C005F
|
||||
:1007B00080917A00806480937A0080917A0086FD2F
|
||||
:1007C000FCCF2091780040917900942F80E030E0B8
|
||||
:1007D000282B392BC9010895282F30E0C9018656EE
|
||||
:1007E0009F4FFC0194912A573F4FF9018491882330
|
||||
:1007F00091F0E82FF0E0EE0FFF1FE859FF4FA591B1
|
||||
:10080000B491662329F48C91909589238C93089553
|
||||
:100810008C91892B8C930895482F50E0CA01825502
|
||||
:100820009F4FFC012491CA0186569F4FFC01949171
|
||||
:100830004A575F4FFA0134913323D1F1222331F12A
|
||||
:10084000233021F4809180008F7705C0243031F46B
|
||||
:10085000809180008F7D8093800018C0213019F432
|
||||
:1008600084B58F7704C0223021F484B58F7D84BD98
|
||||
:100870000DC0263021F48091B0008F7705C027305D
|
||||
:1008800029F48091B0008F7D8093B000E32FF0E0D9
|
||||
:10089000EE0FFF1FEE58FF4FA591B491662329F488
|
||||
:1008A0008C91909589238C9308958C91892B8C93AE
|
||||
:1008B000089597FB092E07260AD077FD04D049D06A
|
||||
:1008C00006D000201AF4709561957F4F0895F6F7D1
|
||||
:1008D000909581959F4F0895A1E21A2EAA1BBB1BEC
|
||||
:1008E000FD010DC0AA1FBB1FEE1FFF1FA217B307FC
|
||||
:1008F000E407F50720F0A21BB30BE40BF50B661F12
|
||||
:10090000771F881F991F1A9469F7609570958095D5
|
||||
:1009100090959B01AC01BD01CF01089597FB092E75
|
||||
:1009200005260ED057FD04D0D7DF0AD0001C38F4BE
|
||||
:1009300050954095309521953F4F4F4F5F4F08950B
|
||||
:10094000F6F790958095709561957F4F8F4F9F4FEB
|
||||
:100950000895AA1BBB1B51E107C0AA1FBB1FA61706
|
||||
:10096000B70710F0A61BB70B881F991F5A95A9F758
|
||||
:1009700080959095BC01CD010895EE0FFF1F059065
|
||||
:0A098000F491E02D0994F894FFCFE4
|
||||
:0C098A009001F40101000000009C01003D
|
||||
:00000001FF
|
@ -0,0 +1,70 @@
|
||||
/*
|
||||
Conditionals - while statement
|
||||
|
||||
This example demonstrates the use of while() statements.
|
||||
|
||||
It reads the state of a potentiometer (an analog input) and blinks an LED
|
||||
while the LED remains above a certain threshold level. It prints the analog value
|
||||
only if it's below the threshold.
|
||||
|
||||
This example uses principles explained in the BlinkWithoutDelay example as well.
|
||||
|
||||
The circuit:
|
||||
* potentiometer connected to analog pin 0.
|
||||
Center pin of the potentiometer goes to the analog pin.
|
||||
side pins of the potentiometer go to +5V and ground
|
||||
* LED connected from digital pin 13 to ground
|
||||
|
||||
* Note: On most Arduino boards, there is already an LED on the board
|
||||
connected to pin 13, so you don't need any extra components for this example.
|
||||
|
||||
created 17 Jan 2009
|
||||
by Tom Igoe
|
||||
|
||||
*/
|
||||
|
||||
#define ledPin 13 // the pin for the LED
|
||||
#define analogPin 0 // the analog pin that the potentiometer is attached to
|
||||
|
||||
int threshold = 400; // an arbitrary threshold level that's in the range of the analog input
|
||||
int ledState = LOW; // the state of the LED
|
||||
int lastBlinkTime = 0; // last time the LED changed
|
||||
int blinkDelay = 500; // how long to hold between changes of the LED
|
||||
int analogValue; // variable to hold the value of the analog input
|
||||
void setup() {
|
||||
// initialize the LED pin as an output:
|
||||
pinMode(ledPin, OUTPUT);
|
||||
// initialize serial communications:
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// read the value of the potentiometer:
|
||||
analogValue = analogRead(analogPin);
|
||||
|
||||
// if the analog value is high enough, turn on the LED:
|
||||
while (analogValue > threshold) {
|
||||
// if enough time has passed since the last change of the LED,
|
||||
// then change it. Note you're using the technique from BlinkWithoutDelay
|
||||
// here so that the while loop doesn't delay the rest of the program:
|
||||
|
||||
if (millis() - lastBlinkTime > blinkDelay) {
|
||||
// if the ledState is high, this makes it low, and vice versa:
|
||||
ledState = !ledState;
|
||||
digitalWrite(ledPin, ledState);
|
||||
|
||||
// save the last time the LED changed in a variable:
|
||||
lastBlinkTime = millis();
|
||||
}
|
||||
// while you're in the while loop, you have to read the
|
||||
// input again:
|
||||
analogValue = analogRead(analogPin);
|
||||
}
|
||||
|
||||
// if you're below the threshold, print the analog value:
|
||||
Serial.println(analogValue, DEC);
|
||||
// turn the LED off:
|
||||
digitalWrite(ledPin, LOW);
|
||||
|
||||
}
|
||||
|
BIN
build/shared/examples/Control/switchCase/applet/core.a
Normal file
BIN
build/shared/examples/Control/switchCase/applet/core.a
Normal file
Binary file not shown.
@ -0,0 +1,45 @@
|
||||
|
||||
#include "WProgram.h"
|
||||
void setup();
|
||||
void loop();
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
}
|
||||
void loop() {
|
||||
int distance = analogRead(0);
|
||||
|
||||
int range = map(distance, 0, 600, 0, 3);
|
||||
|
||||
switch (range) {
|
||||
case 0:
|
||||
Serial.println("dark");
|
||||
break;
|
||||
case 1:
|
||||
Serial.println("dim");
|
||||
break;
|
||||
case 2:
|
||||
Serial.println("medium");
|
||||
break;
|
||||
case 3:
|
||||
Serial.println("bright");
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
init();
|
||||
|
||||
setup();
|
||||
|
||||
for (;;)
|
||||
loop();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -0,0 +1 @@
|
||||
:00000001FF
|
BIN
build/shared/examples/Control/switchCase/applet/switchCase.cpp.elf
Executable file
BIN
build/shared/examples/Control/switchCase/applet/switchCase.cpp.elf
Executable file
Binary file not shown.
@ -0,0 +1,119 @@
|
||||
:100000000C9435000C945D000C945D000C945D0024
|
||||
:100010000C945D000C945D000C945D000C945D00EC
|
||||
:100020000C945D000C945D000C945D000C945D00DC
|
||||
:100030000C945D000C945D000C945D000C945D00CC
|
||||
:100040000C94CD000C945D000C946D010C945D003B
|
||||
:100050000C945D000C945D000C945D000C945D00AC
|
||||
:100060000C945D000C945D00260211241FBECFEF9E
|
||||
:10007000D4E0DEBFCDBF11E0A0E0B1E0E4E2F7E004
|
||||
:1000800002C005900D92A232B107D9F711E0A2E2A9
|
||||
:10009000B1E001C01D92A13CB107E1F710E0CAE652
|
||||
:1000A000D0E004C02297FE010E948C03C836D1071D
|
||||
:1000B000C9F70E94C6000C9490030C940000AF9204
|
||||
:1000C000BF92CF92DF92EF92FF920F931F9380E047
|
||||
:1000D0000E944F0100D000D0AA2797FDA095BA2F0B
|
||||
:1000E00023E030E040E050E0EDB7FEB721833283FB
|
||||
:1000F00043835483BC01CD0120E030E040E050E078
|
||||
:10010000E8E5EE2EE2E0FE2E012D112DAA24BB24FF
|
||||
:1001100065010E94BE020F900F900F900F9061300A
|
||||
:10012000710591F0623071051CF4672B41F01CC021
|
||||
:100130006230710571F063307105B1F40FC08FEA60
|
||||
:1001400091E060E071E00EC08FEA91E065E071E05F
|
||||
:1001500009C08FEA91E069E071E004C08FEA91E0A4
|
||||
:1001600060E171E00E94B3021F910F91FF90EF9048
|
||||
:10017000DF90CF90BF90AF9008958FEA91E040E874
|
||||
:1001800055E260E070E00E94AA0108950E94150106
|
||||
:100190000E94BD000E945F00FDCF1F920F920FB61C
|
||||
:1001A0000F9211242F933F938F939F93AF93BF93FD
|
||||
:1001B0008091260190912701A0912801B0912901F9
|
||||
:1001C00030912A010196A11DB11D232F2D5F2D37DE
|
||||
:1001D00020F02D570196A11DB11D20932A01809377
|
||||
:1001E000260190932701A0932801B09329018091C3
|
||||
:1001F000220190912301A0912401B0912501019643
|
||||
:10020000A11DB11D8093220190932301A09324018D
|
||||
:10021000B0932501BF91AF919F918F913F912F9105
|
||||
:100220000F900FBE0F901F901895789484B5826040
|
||||
:1002300084BD84B5816084BD85B5826085BD85B58A
|
||||
:10024000816085BDEEE6F0E0808181608083E1E839
|
||||
:10025000F0E0808182608083808181608083E0E83B
|
||||
:10026000F0E0808181608083E1EBF0E08081846058
|
||||
:100270008083E0EBF0E0808181608083EAE7F0E05A
|
||||
:1002800080818460808380818260808380818160BE
|
||||
:1002900080838081806880831092C1000895877078
|
||||
:1002A000909117019295990F990F907C982B9093AC
|
||||
:1002B0007C0080917A00806480937A0080917A003B
|
||||
:1002C00086FDFCCF2091780040917900942F80E04A
|
||||
:1002D00030E0282B392BC90108951F920F920FB6D9
|
||||
:1002E0000F9211242F933F934F935F936F937F93BC
|
||||
:1002F0008F939F93AF93BF93EF93FF934091C6006B
|
||||
:10030000E091AB01F091AC01CF01019660E870E0A3
|
||||
:100310000E9426039C018091AD019091AE012817A7
|
||||
:10032000390739F0E55DFE4F40833093AC012093EF
|
||||
:10033000AB01FF91EF91BF91AF919F918F917F9111
|
||||
:100340006F915F914F913F912F910F900FBE0F9042
|
||||
:100350001F901895AF92BF92CF92DF92EF92FF92CB
|
||||
:100360000F931F93CF93DF936C017A018B01DC0114
|
||||
:100370001496AD90BC901597CB01BA0122E030E005
|
||||
:1003800040E050E00E945B03205C3D4B404F5F4FDC
|
||||
:10039000CA01B901A80197010E945B03C901DA01F2
|
||||
:1003A0000197A109B109292F3A2F4B2F552747FD56
|
||||
:1003B0005A950196A11DB11DE5012883E601EE8144
|
||||
:1003C000FF8181508083EA85FB85208141E050E0F8
|
||||
:1003D000CA010E8402C0880F991F0A94E2F7282BE5
|
||||
:1003E0002083EA85FB852081CA010F8402C0880F23
|
||||
:1003F000991F0A94E2F7282B2083EA85FB858081E8
|
||||
:10040000088802C0440F551F0A94E2F7842B8083AA
|
||||
:10041000DF91CF911F910F91FF90EF90DF90CF90E0
|
||||
:10042000BF90AF900895FC01A085B18521898C9182
|
||||
:1004300090E0022E02C0959587950A94E2F780FF1E
|
||||
:10044000F6CF0484F585E02D608308958CE191E07A
|
||||
:100450009093B0018093AF018BE291E09093B20151
|
||||
:100460008093B10185EC90E09093B4018093B30147
|
||||
:1004700084EC90E09093B6018093B50180EC90E01D
|
||||
:100480009093B8018093B70181EC90E09093BA010A
|
||||
:100490008093B90186EC90E09093BC018093BB01FE
|
||||
:1004A00084E08093BD0183E08093BE0187E0809368
|
||||
:1004B000BF0185E08093C00108950F931F93CF93F0
|
||||
:1004C000DF938C01EB0109C02196D801ED91FC91DD
|
||||
:1004D0000190F081E02DC801099568816623A1F79C
|
||||
:1004E000DF91CF911F910F910895EF92FF920F939B
|
||||
:1004F0001F93CF93DF938C017B01EA010CC0D701DE
|
||||
:100500006D917D01D801ED91FC910190F081E02D7C
|
||||
:10051000C80109952197209791F7DF91CF911F91FD
|
||||
:100520000F91FF90EF900895DC01ED91FC91028016
|
||||
:10053000F381E02D099508950F931F938C01DC0141
|
||||
:10054000ED91FC910190F081E02D6DE00995D801CD
|
||||
:10055000ED91FC910190F081E02DC8016AE00995D0
|
||||
:100560001F910F9108950F931F938C010E94940285
|
||||
:10057000C8010E949C021F910F9108952F923F92F3
|
||||
:100580004F925F926F927F928F929F92AF92BF92A3
|
||||
:10059000CF92DF92EF92FF920F931F93DF93CF934F
|
||||
:1005A000CDB7DEB73B014C0119012A016D897E8967
|
||||
:1005B0008F89988D6A197B098C099D09621A730AC3
|
||||
:1005C000840A950AA40193010E940703E218F30824
|
||||
:1005D00004091509A80197010E945B032A0D3B1D20
|
||||
:1005E0004C1D5D1DB901CA01CF91DF911F910F9183
|
||||
:1005F000FF90EF90DF90CF90BF90AF909F908F9043
|
||||
:100600007F906F905F904F903F902F900895629FE2
|
||||
:10061000D001739FF001829FE00DF11D649FE00DFA
|
||||
:10062000F11D929FF00D839FF00D749FF00D659F5B
|
||||
:10063000F00D9927729FB00DE11DF91F639FB00D5A
|
||||
:10064000E11DF91FBD01CF011124089597FB092E6B
|
||||
:1006500007260AD077FD04D049D006D000201AF42E
|
||||
:10066000709561957F4F0895F6F7909581959F4F0E
|
||||
:100670000895A1E21A2EAA1BBB1BFD010DC0AA1FE3
|
||||
:10068000BB1FEE1FFF1FA217B307E407F50720F0FB
|
||||
:10069000A21BB30BE40BF50B661F771F881F991F76
|
||||
:1006A0001A9469F760957095809590959B01AC01BF
|
||||
:1006B000BD01CF01089597FB092E05260ED057FDE9
|
||||
:1006C00004D0D7DF0AD0001C38F4509540953095FF
|
||||
:1006D00021953F4F4F4F5F4F0895F6F790958095C6
|
||||
:1006E000709561957F4F8F4F9F4F0895AA1BBB1B3D
|
||||
:1006F00051E107C0AA1FBB1FA617B70710F0A61B22
|
||||
:10070000B70B881F991F5A95A9F780959095BC0142
|
||||
:10071000CD010895EE0FFF1F0590F491E02D09948F
|
||||
:04072000F894FFCF7B
|
||||
:100724006461726B0064696D006D656469756D0068
|
||||
:1007340062726967687400010000000013025D02C0
|
||||
:0207440075023C
|
||||
:00000001FF
|
59
build/shared/examples/Control/switchCase/switchCase.pde
Normal file
59
build/shared/examples/Control/switchCase/switchCase.pde
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
Switch statement
|
||||
|
||||
Demonstrates the use of a switch statement. The switch
|
||||
statement allows you to choose from among a set of discrete values
|
||||
of a variable. It's like a series of if statements.
|
||||
|
||||
To see this sketch in action, but the board and sensor in a well-lit
|
||||
room, open the serial monitor, and and move your hand gradually
|
||||
down over the sensor.
|
||||
|
||||
The circuit:
|
||||
* photoresistor from analog in 0 to +5V
|
||||
* 10K resistor from analog in 0 to ground
|
||||
|
||||
created 1 Jul 2009
|
||||
by Tom Igoe
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/SwitchCase
|
||||
*/
|
||||
|
||||
// these constants won't change:
|
||||
const int sensorMin = 0; // sensor minimum, discovered through experiment
|
||||
const int sensorMax = 600; // sensor maximum, discovered through experiment
|
||||
|
||||
void setup() {
|
||||
// initialize serial communication:
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// read the sensor:
|
||||
int sensorReading = analogRead(0);
|
||||
// map the sensor range to a range of four options:
|
||||
int range = map(sensorReading, sensorMin, sensorMax, 0, 3);
|
||||
|
||||
// do something different depending on the
|
||||
// range value:
|
||||
switch (range) {
|
||||
case 0: // your hand is on the sensor
|
||||
Serial.println("dark");
|
||||
break;
|
||||
case 1: // your hand is close to the sensor
|
||||
Serial.println("dim");
|
||||
break;
|
||||
case 2: // your hand is a few inches from the sensor
|
||||
Serial.println("medium");
|
||||
break;
|
||||
case 3: // your hand is nowhere near the sensor
|
||||
Serial.println("bright");
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
64
build/shared/examples/Control/switchCase2/switchCase2.pde
Normal file
64
build/shared/examples/Control/switchCase2/switchCase2.pde
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
Switch statement with serial input
|
||||
|
||||
Demonstrates the use of a switch statement. The switch
|
||||
statement allows you to choose from among a set of discrete values
|
||||
of a variable. It's like a series of if statements.
|
||||
|
||||
To see this sketch in action, open the Serial monitor and send any character.
|
||||
The characters a, b, c, d, and e, will turn on LEDs. Any other character will turn
|
||||
the LEDs off.
|
||||
|
||||
The circuit:
|
||||
* 5 LEDs attached to digital pins 2 through 6 through 220-ohm resistors
|
||||
|
||||
created 1 Jul 2009
|
||||
by Tom Igoe
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/SwitchCase2
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
// initialize serial communication:
|
||||
Serial.begin(9600);
|
||||
// initialize the LED pins:
|
||||
for (int thisPin = 2; thisPin < 7; thisPin++) {
|
||||
pinMode(thisPin, OUTPUT);
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// read the sensor:
|
||||
if (Serial.available() > 0) {
|
||||
int inByte = Serial.read();
|
||||
// do something different depending on the character received.
|
||||
// The switch statement expects single number values for each case;
|
||||
// in this exmaple, though, you're using single quotes to tell
|
||||
// the controller to get the ASCII value for the character. For
|
||||
// example 'a' = 97, 'b' = 98, and so forth:
|
||||
|
||||
switch (inByte) {
|
||||
case 'a':
|
||||
digitalWrite(2, HIGH);
|
||||
break;
|
||||
case 'b':
|
||||
digitalWrite(3, HIGH);
|
||||
break;
|
||||
case 'c':
|
||||
digitalWrite(4, HIGH);
|
||||
break;
|
||||
case 'd':
|
||||
digitalWrite(5, HIGH);
|
||||
break;
|
||||
case 'e':
|
||||
digitalWrite(6, HIGH);
|
||||
break;
|
||||
default:
|
||||
// turn all the LEDs off:
|
||||
for (int thisPin = 2; thisPin < 7; thisPin++) {
|
||||
digitalWrite(thisPin, LOW);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
40
build/shared/examples/Digital/Blink/Blink.pde
Normal file
40
build/shared/examples/Digital/Blink/Blink.pde
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
Blink
|
||||
|
||||
Turns on an LED on for one second, then off for one second, repeatedly.
|
||||
|
||||
The circuit:
|
||||
* LED connected from digital pin 13 to ground.
|
||||
|
||||
* Note: On most Arduino boards, there is already an LED on the board
|
||||
connected to pin 13, so you don't need any extra components for this example.
|
||||
|
||||
|
||||
Created 1 June 2005
|
||||
By David Cuartielles
|
||||
|
||||
http://arduino.cc/en/Tutorial/Blink
|
||||
|
||||
based on an orginal by H. Barragan for the Wiring i/o board
|
||||
|
||||
*/
|
||||
|
||||
int ledPin = 13; // LED connected to digital pin 13
|
||||
|
||||
// The setup() method runs once, when the sketch starts
|
||||
|
||||
void setup() {
|
||||
// initialize the digital pin as an output:
|
||||
pinMode(ledPin, OUTPUT);
|
||||
}
|
||||
|
||||
// the loop() method runs over and over again,
|
||||
// as long as the Arduino has power
|
||||
|
||||
void loop()
|
||||
{
|
||||
digitalWrite(ledPin, HIGH); // set the LED on
|
||||
delay(1000); // wait for a second
|
||||
digitalWrite(ledPin, LOW); // set the LED off
|
||||
delay(1000); // wait for a second
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
/* 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.
|
||||
|
||||
The circuit:
|
||||
* LED attached from pin 13 to ground.
|
||||
* Note: on most Arduinos, there is already an LED on the board
|
||||
that's attached to pin 13, so no hardware is needed for this example.
|
||||
|
||||
|
||||
created 2005
|
||||
by David A. Mellis
|
||||
modified 17 Jun 2009
|
||||
by Tom Igoe
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
|
||||
*/
|
||||
|
||||
// constants won't change. Used here to
|
||||
// set pin numbers:
|
||||
const int ledPin = 13; // the number of the LED pin
|
||||
|
||||
// Variables will change:
|
||||
int ledState = LOW; // ledState used to set the LED
|
||||
long previousMillis = 0; // will store last time LED was updated
|
||||
|
||||
// the follow variables is a long because the time, measured in miliseconds,
|
||||
// will quickly become a bigger number than can be stored in an int.
|
||||
long interval = 1000; // interval at which to blink (milliseconds)
|
||||
|
||||
void setup() {
|
||||
// set the digital pin as output:
|
||||
pinMode(ledPin, 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) {
|
||||
// save the last time you blinked the LED
|
||||
previousMillis = millis();
|
||||
|
||||
// if the LED is off turn it on and vice-versa:
|
||||
if (ledState == LOW)
|
||||
ledState = HIGH;
|
||||
else
|
||||
ledState = LOW;
|
||||
|
||||
// set the LED with the ledState of the variable:
|
||||
digitalWrite(ledPin, ledState);
|
||||
}
|
||||
}
|
54
build/shared/examples/Digital/Button/Button.pde
Normal file
54
build/shared/examples/Digital/Button/Button.pde
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
Button
|
||||
|
||||
Turns on and off a light emitting diode(LED) connected to digital
|
||||
pin 13, when pressing a pushbutton attached to pin 7.
|
||||
|
||||
|
||||
The circuit:
|
||||
* LED attached from pin 13 to ground
|
||||
* pushbutton attached to pin 2 from +5V
|
||||
* 10K resistor attached to pin 2 from ground
|
||||
|
||||
* Note: on most Arduinos there is already an LED on the board
|
||||
attached to pin 13.
|
||||
|
||||
|
||||
created 2005
|
||||
by DojoDave <http://www.0j0.org>
|
||||
modified 17 Jun 2009
|
||||
by Tom Igoe
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/Button
|
||||
*/
|
||||
|
||||
// constants won't change. They're used here to
|
||||
// set pin numbers:
|
||||
const int buttonPin = 2; // the number of the pushbutton pin
|
||||
const int ledPin = 13; // the number of the LED pin
|
||||
|
||||
// variables will change:
|
||||
int buttonState = 0; // variable for reading the pushbutton status
|
||||
|
||||
void setup() {
|
||||
// initialize the LED pin as an output:
|
||||
pinMode(ledPin, OUTPUT);
|
||||
// initialize the pushbutton pin as an input:
|
||||
pinMode(buttonPin, INPUT);
|
||||
}
|
||||
|
||||
void loop(){
|
||||
// read the state of the pushbutton value:
|
||||
buttonState = digitalRead(buttonPin);
|
||||
|
||||
// check if the pushbutton is pressed.
|
||||
// if it is, the buttonState is HIGH:
|
||||
if (buttonState == HIGH) {
|
||||
// turn LED on:
|
||||
digitalWrite(ledPin, HIGH);
|
||||
}
|
||||
else {
|
||||
// turn LED off:
|
||||
digitalWrite(ledPin, LOW);
|
||||
}
|
||||
}
|
74
build/shared/examples/Digital/Debounce/Debounce.pde
Normal file
74
build/shared/examples/Digital/Debounce/Debounce.pde
Normal file
@ -0,0 +1,74 @@
|
||||
/*
|
||||
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).
|
||||
|
||||
The circuit:
|
||||
* LED attached from pin 13 to ground
|
||||
* pushbutton attached from pin 2 to +5V
|
||||
* 10K resistor attached from pin 2 to ground
|
||||
|
||||
* Note: On most Arduino boards, there is already an LED on the board
|
||||
connected to pin 13, so you don't need any extra components for this example.
|
||||
|
||||
|
||||
created 21 November 2006
|
||||
by David A. Mellis
|
||||
modified 3 Jul 2009
|
||||
by Limor Fried
|
||||
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/Debounce
|
||||
*/
|
||||
|
||||
// constants won't change. They're used here to
|
||||
// set pin numbers:
|
||||
const int buttonPin = 2; // the number of the pushbutton pin
|
||||
const int ledPin = 13; // the number of the LED pin
|
||||
|
||||
// Variables will change:
|
||||
int ledState = HIGH; // the current state of the output pin
|
||||
int buttonState; // the current reading from the input pin
|
||||
int lastButtonState = LOW; // the previous reading from the input pin
|
||||
|
||||
// the following variables are long's because the time, measured in miliseconds,
|
||||
// will quickly become a bigger number than can be stored in an int.
|
||||
long lastDebounceTime = 0; // the last time the output pin was toggled
|
||||
long debounceDelay = 50; // the debounce time; increase if the output flickers
|
||||
|
||||
void setup() {
|
||||
pinMode(buttonPin, INPUT);
|
||||
pinMode(ledPin, OUTPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// read the state of the switch into a local variable:
|
||||
int reading = digitalRead(buttonPin);
|
||||
|
||||
// check to see if you just pressed the button
|
||||
// (i.e. the input went from LOW to HIGH), and you've waited
|
||||
// long enough since the last press to ignore any noise:
|
||||
|
||||
// If the switch changed, due to noise or pressing:
|
||||
if (reading != lastButtonState) {
|
||||
// reset the debouncing timer
|
||||
lastDebounceTime = millis();
|
||||
}
|
||||
|
||||
if ((millis() - lastDebounceTime) > debounceDelay) {
|
||||
// whatever the reading is at, it's been there for longer
|
||||
// than the debounce delay, so take it as the actual current state:
|
||||
buttonState = reading;
|
||||
}
|
||||
|
||||
// set the LED using the state of the button:
|
||||
digitalWrite(ledPin, buttonState);
|
||||
|
||||
// save the reading. Next time through the loop,
|
||||
// it'll be the lastButtonState:
|
||||
lastButtonState = reading;
|
||||
}
|
||||
|
71
build/shared/examples/Digital/Melody/Melody.pde
Normal file
71
build/shared/examples/Digital/Melody/Melody.pde
Normal file
@ -0,0 +1,71 @@
|
||||
/* 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);
|
||||
}
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
/*
|
||||
State change detection (edge detection)
|
||||
|
||||
Often, you don't need to know the state of a digital input all the time,
|
||||
but you just need to know when the input changes from one state to another.
|
||||
For example, you want to know when a button goes from OFF to ON. This is called
|
||||
state change detection, or edge detection.
|
||||
|
||||
This example shows how to detect when a button or button changes from off to on
|
||||
and on to off.
|
||||
|
||||
The circuit:
|
||||
* pushbutton attached to pin 2 from +5V
|
||||
* 10K resistor attached to pin 2 from ground
|
||||
* LED attached from pin 13 to ground (or use the built-in LED on
|
||||
most Arduino boards)
|
||||
|
||||
created 27 Sep 2005
|
||||
modified 17 Jun 2009
|
||||
by Tom Igoe
|
||||
|
||||
http://arduino.cc/en/Tutorial/ButtonStateChange
|
||||
|
||||
*/
|
||||
|
||||
// this constant won't change:
|
||||
const int buttonPin = 2; // the pin that the pushbutton is attached to
|
||||
const int ledPin = 13; // the pin that the LED is attached to
|
||||
|
||||
// Variables will change:
|
||||
int buttonPushCounter = 0; // counter for the number of button presses
|
||||
int buttonState = 0; // current state of the button
|
||||
int lastButtonState = 0; // previous state of the button
|
||||
|
||||
void setup() {
|
||||
// initialize the button pin as a input:
|
||||
pinMode(buttonPin, INPUT);
|
||||
// initialize serial communication:
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
// read the pushbutton input pin:
|
||||
buttonState = digitalRead(buttonPin);
|
||||
|
||||
// compare the buttonState to its previous state
|
||||
if (buttonState != lastButtonState) {
|
||||
// if the state has changed, increment the counter
|
||||
if (buttonState == HIGH) {
|
||||
// if the current state is HIGH then the button
|
||||
// wend from off to on:
|
||||
buttonPushCounter++;
|
||||
Serial.println("on");
|
||||
Serial.print("number of button pushes: ");
|
||||
Serial.println(buttonPushCounter, DEC);
|
||||
}
|
||||
else {
|
||||
// if the current state is LOW then the button
|
||||
// wend from on to off:
|
||||
Serial.println("off");
|
||||
}
|
||||
|
||||
// save the current state as the last state,
|
||||
//for next time through the loop
|
||||
lastButtonState = buttonState;
|
||||
}
|
||||
|
||||
// turns on the LED every four button pushes by
|
||||
// checking the modulo of the button push counter.
|
||||
// the modulo function gives you the remainder of
|
||||
// the division of two numbers:
|
||||
if (buttonPushCounter % 4 == 0) {
|
||||
digitalWrite(ledPin, HIGH);
|
||||
} else {
|
||||
digitalWrite(ledPin, LOW);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,112 @@
|
||||
/*
|
||||
Row-Column Scanning an 8x8 LED matrix with X-Y input
|
||||
|
||||
This example controls an 8x8 LED matrix using two analog inputs
|
||||
|
||||
created 27 May 2009
|
||||
modified 29 Jun 2009
|
||||
by Tom Igoe
|
||||
|
||||
This example works for the Lumex LDM-24488NI Matrix. See
|
||||
http://sigma.octopart.com/140413/datasheet/Lumex-LDM-24488NI.pdf
|
||||
for the pin connections
|
||||
|
||||
For other LED cathode column matrixes, you should only need to change
|
||||
the pin numbers in the row[] and column[] arrays
|
||||
|
||||
rows are the anodes
|
||||
cols are the cathodes
|
||||
---------
|
||||
|
||||
Pin numbers:
|
||||
Matrix:
|
||||
* Digital pins 2 through 13,
|
||||
* analog pins 2 through 5 used as digital 16 through 19
|
||||
Potentiometers:
|
||||
* center pins are attached to analog pins 0 and 1, respectively
|
||||
* side pins attached to +5V and ground, respectively.
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/RowColumnScanning
|
||||
|
||||
see also http://www.tigoe.net/pcomp/code/category/arduinowiring/514 for more
|
||||
*/
|
||||
|
||||
|
||||
// 2-dimensional array of row pin numbers:
|
||||
const int row[8] = {
|
||||
2,7,19,5,18,12,16 };
|
||||
|
||||
// 2-dimensional array of column pin numbers:
|
||||
const int col[8] = {
|
||||
6,11,10,3,17,4,8,9 };
|
||||
|
||||
// 2-dimensional array of pixels:
|
||||
int pixels[8][8];
|
||||
|
||||
// cursor position:
|
||||
int x = 5;
|
||||
int y = 5;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
// initialize the I/O pins as outputs:
|
||||
|
||||
// iterate over the pins:
|
||||
for (int thisPin = 0; thisPin < 8; thisPin++) {
|
||||
// initialize the output pins:
|
||||
pinMode(col[thisPin], OUTPUT);
|
||||
pinMode(row[thisPin], OUTPUT);
|
||||
// take the col pins (i.e. the cathodes) high to ensure that
|
||||
// the LEDS are off:
|
||||
digitalWrite(col[thisPin], HIGH);
|
||||
}
|
||||
|
||||
// initialize the pixel matrix:
|
||||
for (int x = 0; x < 8; x++) {
|
||||
for (int y = 0; y < 8; y++) {
|
||||
pixels[x][y] = HIGH;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// read input:
|
||||
readSensors();
|
||||
|
||||
// draw the screen:
|
||||
refreshScreen();
|
||||
}
|
||||
|
||||
void readSensors() {
|
||||
// turn off the last position:
|
||||
pixels[x][y] = HIGH;
|
||||
// read the sensors for X and Y values:
|
||||
x = 7 - map(analogRead(0), 0, 1023, 0, 7);
|
||||
y = map(analogRead(1), 0, 1023, 0, 7);
|
||||
// set the new pixel position low so that the LED will turn on
|
||||
// in the next screen refresh:
|
||||
pixels[x][y] = LOW;
|
||||
|
||||
}
|
||||
|
||||
void refreshScreen() {
|
||||
// iterate over the rows (anodes):
|
||||
for (int thisRow = 0; thisRow < 8; thisRow++) {
|
||||
// take the row pin (anode) high:
|
||||
digitalWrite(row[thisRow], HIGH);
|
||||
// iterate over the cols (cathodes):
|
||||
for (int thisCol = 0; thisCol < 8; thisCol++) {
|
||||
// get the state of the current pixel;
|
||||
int thisPixel = pixels[thisRow][thisCol];
|
||||
// when the row is HIGH and the col is LOW,
|
||||
// the LED where they meet turns on:
|
||||
digitalWrite(col[thisCol], thisPixel);
|
||||
// turn the pixel off:
|
||||
if (thisPixel == LOW) {
|
||||
digitalWrite(col[thisCol], HIGH);
|
||||
}
|
||||
}
|
||||
// take the row pin low to turn off the whole row:
|
||||
digitalWrite(row[thisRow], LOW);
|
||||
}
|
||||
}
|
56
build/shared/examples/Display/barGraph/applet/barGraph.cpp
Normal file
56
build/shared/examples/Display/barGraph/applet/barGraph.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
|
||||
|
||||
|
||||
// these constants won't change:
|
||||
#include "WProgram.h"
|
||||
void setup();
|
||||
void loop();
|
||||
const int analogPin = 0; // the pin that the potentiometer is attached to
|
||||
const int ledCount = 10; // the number of LEDs in the bar graph
|
||||
|
||||
int ledPins[] = {
|
||||
2, 3, 4, 5, 6, 7,8,9,10,11 }; // an array of pin numbers to which LEDs are attached
|
||||
|
||||
|
||||
void setup() {
|
||||
// loop over the pin array and set them all to output:
|
||||
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
|
||||
pinMode(ledPins[thisLed], OUTPUT);
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// read the potentiometer:
|
||||
int sensorReading = analogRead(analogPin);
|
||||
// map the result to a range from 0 to the number of LEDs:
|
||||
int ledLevel = map(sensorReading, 0, 1023, 0, ledCount);
|
||||
|
||||
// loop over the LED array:
|
||||
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
|
||||
// if the array element's index is less than ledLevel,
|
||||
// turn the pin for this element on:
|
||||
if (thisLed < ledLevel) {
|
||||
digitalWrite(ledPins[thisLed], HIGH);
|
||||
}
|
||||
// turn off all pins higher than the ledLevel:
|
||||
else {
|
||||
digitalWrite(ledPins[thisLed], LOW);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
init();
|
||||
|
||||
setup();
|
||||
|
||||
for (;;)
|
||||
loop();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -0,0 +1 @@
|
||||
:00000001FF
|
BIN
build/shared/examples/Display/barGraph/applet/barGraph.cpp.elf
Executable file
BIN
build/shared/examples/Display/barGraph/applet/barGraph.cpp.elf
Executable file
Binary file not shown.
@ -0,0 +1,87 @@
|
||||
:100000000C9461000C947E000C947E000C947E0095
|
||||
:100010000C947E000C947E000C947E000C947E0068
|
||||
:100020000C947E000C947E000C947E000C947E0058
|
||||
:100030000C947E000C947E000C947E000C947E0048
|
||||
:100040000C94E9000C947E000C947E000C947E00CD
|
||||
:100050000C947E000C947E000C947E000C947E0028
|
||||
:100060000C947E000C947E00000000002400270009
|
||||
:100070002A0000000000250028002B0000000000DE
|
||||
:1000800023002600290004040404040404040202DA
|
||||
:100090000202020203030303030301020408102007
|
||||
:1000A0004080010204081020010204081020000012
|
||||
:1000B0000007000201000003040600000000000029
|
||||
:1000C000000011241FBECFEFD4E0DEBFCDBF11E092
|
||||
:1000D000A0E0B1E0EAE3F5E002C005900D92A631A0
|
||||
:1000E000B107D9F711E0A6E1B1E001C01D92AF312F
|
||||
:1000F000B107E1F70E94E2000C949B020C9400000F
|
||||
:10010000AF92BF92CF92DF92EF92FF920F931F9325
|
||||
:10011000CF93DF9380E00E946B0100D000D0AA272C
|
||||
:1001200097FDA095BA2F2AE030E040E050E0EDB70F
|
||||
:10013000FEB72183328343835483BC01CD0120E089
|
||||
:1001400030E040E050E0EFEFEE2EE3E0FE2E012D38
|
||||
:10015000112DAA24BB2465010E94F6017B01C0E099
|
||||
:10016000D1E000E010E00F900F900F900F900E156F
|
||||
:100170001F051CF4888161E002C0888160E00E9454
|
||||
:10018000A9010F5F1F4F22960A30110581F7DF91F9
|
||||
:10019000CF911F910F91FF90EF90DF90CF90BF9084
|
||||
:1001A000AF900895CF93DF93C0E0D1E0888161E004
|
||||
:1001B0000E948901229681E0C431D807B9F7DF9106
|
||||
:1001C000CF9108950E9431010E94D2000E948000C8
|
||||
:1001D000FDCF1F920F920FB60F9211242F933F93D2
|
||||
:1001E0008F939F93AF93BF9380911A0190911B01BE
|
||||
:1001F000A0911C01B0911D0130911E010196A11D1D
|
||||
:10020000B11D232F2D5F2D3720F02D570196A11DF5
|
||||
:10021000B11D20931E0180931A0190931B01A0939E
|
||||
:100220001C01B0931D018091160190911701A091BE
|
||||
:100230001801B09119010196A11DB11D80931601FD
|
||||
:1002400090931701A0931801B0931901BF91AF913A
|
||||
:100250009F918F913F912F910F900FBE0F901F9004
|
||||
:100260001895789484B5826084BD84B5816084BD1E
|
||||
:1002700085B5826085BD85B5816085BDEEE6F0E01F
|
||||
:10028000808181608083E1E8F0E08081826080830A
|
||||
:10029000808181608083E0E8F0E0808181608083FC
|
||||
:1002A000E1EBF0E0808184608083E0EBF0E080812E
|
||||
:1002B00081608083EAE7F0E08081846080838081D0
|
||||
:1002C0008260808380818160808380818068808378
|
||||
:1002D0001092C10008958770909114019295990F22
|
||||
:1002E000990F907C982B90937C0080917A00806489
|
||||
:1002F00080937A0080917A0086FDFCCF209178006F
|
||||
:1003000040917900942F80E030E0282B392BC901EF
|
||||
:100310000895282F30E0C90186569F4FFC01949123
|
||||
:100320002A573F4FF9018491882391F0E82FF0E09C
|
||||
:10033000EE0FFF1FE859FF4FA591B491662329F4F2
|
||||
:100340008C91909589238C9308958C91892B8C9313
|
||||
:100350000895482F50E0CA0182559F4FFC01249117
|
||||
:10036000CA0186569F4FFC0194914A575F4FFA018C
|
||||
:1003700034913323D1F1222331F1233021F48091C0
|
||||
:1003800080008F7705C0243031F4809180008F7D0C
|
||||
:100390008093800018C0213019F484B58F7704C091
|
||||
:1003A000223021F484B58F7D84BD0DC0263021F428
|
||||
:1003B0008091B0008F7705C0273029F48091B0007C
|
||||
:1003C0008F7D8093B000E32FF0E0EE0FFF1FEE581B
|
||||
:1003D000FF4FA591B491662329F48C9190958923C0
|
||||
:1003E0008C9308958C91892B8C9308952F923F9232
|
||||
:1003F0004F925F926F927F928F929F92AF92BF9235
|
||||
:10040000CF92DF92EF92FF920F931F93DF93CF93E0
|
||||
:10041000CDB7DEB73B014C0119012A016D897E89F8
|
||||
:100420008F89988D6A197B098C099D09621A730A54
|
||||
:10043000840A950AA40193010E943F02E218F3087E
|
||||
:1004400004091509A80197010E945E022A0D3B1DAF
|
||||
:100450004C1D5D1DB901CA01CF91DF911F910F9114
|
||||
:10046000FF90EF90DF90CF90BF90AF909F908F90D4
|
||||
:100470007F906F905F904F903F902F900895629F74
|
||||
:10048000D001739FF001829FE00DF11D649FE00D8C
|
||||
:10049000F11D929FF00D839FF00D749FF00D659FED
|
||||
:1004A000F00D9927729FB00DE11DF91F639FB00DEC
|
||||
:1004B000E11DF91FBD01CF011124089597FB092EFD
|
||||
:1004C00005260ED057FD04D014D00AD0001C38F4F5
|
||||
:1004D00050954095309521953F4F4F4F5F4F089570
|
||||
:1004E000F6F790958095709561957F4F8F4F9F4F50
|
||||
:1004F0000895A1E21A2EAA1BBB1BFD010DC0AA1F65
|
||||
:10050000BB1FEE1FFF1FA217B307E407F50720F07C
|
||||
:10051000A21BB30BE40BF50B661F771F881F991FF7
|
||||
:100520001A9469F760957095809590959B01AC0140
|
||||
:0A053000BD01CF010895F894FFCF3C
|
||||
:10053A000200030004000500060007000800090085
|
||||
:06054A000A000B00010095
|
||||
:00000001FF
|
BIN
build/shared/examples/Display/barGraph/applet/core.a
Normal file
BIN
build/shared/examples/Display/barGraph/applet/core.a
Normal file
Binary file not shown.
58
build/shared/examples/Display/barGraph/barGraph.pde
Normal file
58
build/shared/examples/Display/barGraph/barGraph.pde
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
LED bar graph
|
||||
|
||||
Turns on a series of LEDs based on the value of an analog sensor.
|
||||
This is a simple way to make a bar graph display. Though this graph
|
||||
uses 10 LEDs, you can use any number by changing the LED count
|
||||
and the pins in the array.
|
||||
|
||||
This method can be used to control any series of digital outputs that
|
||||
depends on an analog input.
|
||||
|
||||
The circuit:
|
||||
* LEDs from pins 2 through 11 to ground
|
||||
|
||||
created 26 Jun 2009
|
||||
by Tom Igoe
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/BarGraph
|
||||
*/
|
||||
|
||||
|
||||
// these constants won't change:
|
||||
const int analogPin = 0; // the pin that the potentiometer is attached to
|
||||
const int ledCount = 10; // the number of LEDs in the bar graph
|
||||
|
||||
int ledPins[] = {
|
||||
2, 3, 4, 5, 6, 7,8,9,10,11 }; // an array of pin numbers to which LEDs are attached
|
||||
|
||||
|
||||
void setup() {
|
||||
// loop over the pin array and set them all to output:
|
||||
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
|
||||
pinMode(ledPins[thisLed], OUTPUT);
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// read the potentiometer:
|
||||
int sensorReading = analogRead(analogPin);
|
||||
// map the result to a range from 0 to the number of LEDs:
|
||||
int ledLevel = map(sensorReading, 0, 1023, 0, ledCount);
|
||||
|
||||
// loop over the LED array:
|
||||
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
|
||||
// if the array element's index is less than ledLevel,
|
||||
// turn the pin for this element on:
|
||||
if (thisLed < ledLevel) {
|
||||
digitalWrite(ledPins[thisLed], HIGH);
|
||||
}
|
||||
// turn off all pins higher than the ledLevel:
|
||||
else {
|
||||
digitalWrite(ledPins[thisLed], LOW);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
62
build/shared/examples/Sensors/ADXL3xx/ADXL3xx.pde
Normal file
62
build/shared/examples/Sensors/ADXL3xx/ADXL3xx.pde
Normal file
@ -0,0 +1,62 @@
|
||||
|
||||
/*
|
||||
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
|
||||
|
||||
The circuit:
|
||||
analog 0: accelerometer self test
|
||||
analog 1: z-axis
|
||||
analog 2: y-axis
|
||||
analog 3: x-axis
|
||||
analog 4: ground
|
||||
analog 5: vcc
|
||||
|
||||
created 2 Jul 2008
|
||||
by David A. Mellis
|
||||
modified 26 Jun 2009
|
||||
by Tom Igoe
|
||||
|
||||
*/
|
||||
|
||||
// these constants describe the pins. They won't change:
|
||||
const int groundPin = 18; // analog input pin 4 -- ground
|
||||
const int powerPin = 19; // analog input pin 5 -- voltage
|
||||
const int xPin = 3; // x-axis of the accelerometer
|
||||
const int yPin = 2; // y-axis
|
||||
const int zPin = 1; // z-axis (only on 3-axis models)
|
||||
|
||||
void setup()
|
||||
{
|
||||
// initialize the serial communications:
|
||||
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()
|
||||
{
|
||||
// print the sensor values:
|
||||
Serial.print(analogRead(xpin));
|
||||
// print a tab between values:
|
||||
Serial.print("\t");
|
||||
Serial.print(analogRead(ypin));
|
||||
// print a tab between values:
|
||||
Serial.print("\t");
|
||||
Serial.print(analogRead(zpin));
|
||||
Serial.println();
|
||||
// delay before next reading:
|
||||
delay(100);
|
||||
}
|
53
build/shared/examples/Sensors/Knock/Knock.pde
Normal file
53
build/shared/examples/Sensors/Knock/Knock.pde
Normal file
@ -0,0 +1,53 @@
|
||||
/* Knock Sensor
|
||||
|
||||
This sketch reads a piezo element to detect a knocking sound.
|
||||
It reads an analog pin and compares the result to a set threshold.
|
||||
If the result is greater than the threshold, it writes
|
||||
"knock" to the serial port, and toggles the LED on pin 13.
|
||||
|
||||
The circuit:
|
||||
* + connection of the piezo attached to analog in 0
|
||||
* - connection of the piezo attached to ground
|
||||
* 1-megohm resistor attached from analog in 0 to ground
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/Knock
|
||||
|
||||
created 25 Mar 2007
|
||||
by David Cuartielles <http://www.0j0.org>
|
||||
modified 30 Jun 2009
|
||||
by Tom Igoe
|
||||
|
||||
*/
|
||||
|
||||
|
||||
// these constants won't change:
|
||||
const int ledPin = 13; // led connected to digital pin 13
|
||||
const int knockSensor = 0; // the piezo is connected to analog pin 0
|
||||
const int threshold = 100; // threshold value to decide when the detected sound is a knock or not
|
||||
|
||||
|
||||
// these variables will change:
|
||||
int sensorReading = 0; // variable to store the value read from the sensor pin
|
||||
int ledState = LOW; // variable used to store the last LED status, to toggle the light
|
||||
|
||||
void setup() {
|
||||
pinMode(ledPin, OUTPUT); // declare the ledPin as as OUTPUT
|
||||
Serial.begin(9600); // use the serial port
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// read the sensor and store it in the variable sensorReading:
|
||||
sensorReading = analogRead(knockSensor);
|
||||
|
||||
// if the sensor reading is greater than the threshold:
|
||||
if (sensorReading >= threshold) {
|
||||
// toggle the status of the ledPin:
|
||||
ledState = !ledState;
|
||||
// update the LED pin itself:
|
||||
digitalWrite(ledPin, ledState);
|
||||
// send the string "Knock!" back to the computer, followed by newline
|
||||
Serial.println("Knock!");
|
||||
}
|
||||
delay(100); // delay to avoid overloading the serial port buffer
|
||||
}
|
||||
|
61
build/shared/examples/Sensors/Memsic2125/Memsic2125.pde
Normal file
61
build/shared/examples/Sensors/Memsic2125/Memsic2125.pde
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
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.
|
||||
|
||||
The circuit:
|
||||
* X output of accelerometer to digital pin 2
|
||||
* Y output of accelerometer to digital pin 3
|
||||
* +V of accelerometer to +5V
|
||||
* GND of accelerometer to ground
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/Memsic2125
|
||||
|
||||
created 6 Nov 2008
|
||||
by David A. Mellis
|
||||
modified 30 Jun 2009
|
||||
by Tom Igoe
|
||||
|
||||
*/
|
||||
|
||||
// these constants won't change:
|
||||
const int xPin = 2; // X output of the accelerometer
|
||||
const int yPin = 3; // Y output of the accelerometer
|
||||
|
||||
void setup() {
|
||||
// initialize serial communications:
|
||||
Serial.begin(9600);
|
||||
// initialize the pins connected to the accelerometer
|
||||
// as inputs:
|
||||
pinMode(xPin, INPUT);
|
||||
pinMode(yPin, INPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// variables to read the pulse widths:
|
||||
int pulseX, pulseY;
|
||||
// variables to contain the resulting accelerations
|
||||
int accelerationX, accelerationY;
|
||||
|
||||
// read pulse from x- and y-axes:
|
||||
pulseX = pulseIn(xPin,HIGH);
|
||||
pulseY = pulseIn(yPin,HIGH);
|
||||
|
||||
// convert the pulse width into acceleration
|
||||
// accelerationX and accelerationY are in milli-g's:
|
||||
// earth's gravity is 1000 milli-g's, or 1g.
|
||||
accelerationX = ((pulseX / 10) - 500) * 8;
|
||||
accelerationY = ((pulseY / 10) - 500) * 8;
|
||||
|
||||
// print the acceleration
|
||||
Serial.print(accelerationX);
|
||||
// print a tab character:
|
||||
Serial.print("\t");
|
||||
Serial.print(accelerationY);
|
||||
Serial.println();
|
||||
|
||||
delay(100);
|
||||
}
|
82
build/shared/examples/Sensors/Ping/Ping.pde
Normal file
82
build/shared/examples/Sensors/Ping/Ping.pde
Normal file
@ -0,0 +1,82 @@
|
||||
/* Ping))) Sensor
|
||||
|
||||
This sketch reads a PING))) ultrasonic rangefinder and returns the
|
||||
distance to the closest object in range. To do this, it sends a pulse
|
||||
to the sensor to initiate a reading, then listens for a pulse
|
||||
to return. The length of the returning pulse is proportional to
|
||||
the distance of the object from the sensor.
|
||||
|
||||
The circuit:
|
||||
* +V connection of the PING))) attached to +5V
|
||||
* GND connection of the PING))) attached to ground
|
||||
* SIG connection of the PING))) attached to digital pin 7
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/Ping
|
||||
|
||||
created 3 Nov 2008
|
||||
by David A. Mellis
|
||||
modified 30 Jun 2009
|
||||
by Tom Igoe
|
||||
|
||||
*/
|
||||
|
||||
// this constant won't change. It's the pin number
|
||||
// of the sensor's output:
|
||||
const int pingPin = 7;
|
||||
|
||||
void setup() {
|
||||
// initialize serial communication:
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// establish variables for duration of the ping,
|
||||
// and the distance result in inches and centimeters:
|
||||
long duration, inches, cm;
|
||||
|
||||
// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
|
||||
// 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;
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
int sensorValue = analogRead(0);
|
||||
Serial.println(sensorValue, DEC);
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,13 @@
|
||||
|
||||
void setup() {
|
||||
pinMode(6, OUTPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
int sensorValue = analogRead(2);
|
||||
int ledFadeValue = map(sensorValue, 0, 1023, 0, 255);
|
||||
analogWrite(6, ledFadeValue);
|
||||
}
|
||||
|
||||
|
||||
|
9
build/shared/examples/Stubs/BareMinumum/BareMinumum.pde
Normal file
9
build/shared/examples/Stubs/BareMinumum/BareMinumum.pde
Normal file
@ -0,0 +1,9 @@
|
||||
void setup() {
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,13 @@
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
pinMode(2, INPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
int sensorValue = digitalRead(2);
|
||||
Serial.println(sensorValue, DEC);
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,12 @@
|
||||
|
||||
void setup() {
|
||||
pinMode(13, OUTPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
int switchValue = digitalRead(2);
|
||||
digitalWrite(13, switchValue);
|
||||
}
|
||||
|
||||
|
||||
|
9
build/shared/examples/Stubs/HelloWorld/HelloWorld.pde
Normal file
9
build/shared/examples/Stubs/HelloWorld/HelloWorld.pde
Normal file
@ -0,0 +1,9 @@
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Serial.println("Hello World!");
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user