| 1 |
/* |
| 2 |
Physical Pixel |
| 3 |
|
| 4 |
An example of using the Arduino board to receive data from the computer. In |
| 5 |
this case, the Arduino boards turns on an LED when it receives the character |
| 6 |
'H', and turns off the LED when it receives the character 'L'. |
| 7 |
|
| 8 |
The data can be sent from the Arduino Serial Monitor, or another program like |
| 9 |
Processing (see code below), Flash (via a serial-net proxy), PD, or Max/MSP. |
| 10 |
|
| 11 |
The circuit: |
| 12 |
- LED connected from digital pin 13 to ground through 220 ohm resistor |
| 13 |
|
| 14 |
created 2006 |
| 15 |
by David A. Mellis |
| 16 |
modified 30 Aug 2011 |
| 17 |
by Tom Igoe and Scott Fitzgerald |
| 18 |
|
| 19 |
This example code is in the public domain. |
| 20 |
|
| 21 |
https://www.arduino.cc/en/Tutorial/BuiltInExamples/PhysicalPixel |
| 22 |
*/ |
| 23 |
|
| 24 |
const int ledPin = 13; // the pin that the LED is attached to |
| 25 |
int incomingByte; // a variable to read incoming serial data into |
| 26 |
|
| 27 |
void setup() { |
| 28 |
// initialize serial communication: |
| 29 |
Serial.begin(9600); |
| 30 |
// initialize the LED pin as an output: |
| 31 |
pinMode(ledPin, OUTPUT); |
| 32 |
} |
| 33 |
|
| 34 |
void loop() { |
| 35 |
// see if there's incoming serial data: |
| 36 |
if (Serial.available() > 0) { |
| 37 |
// read the oldest byte in the serial buffer: |
| 38 |
incomingByte = Serial.read(); |
| 39 |
// if it's a capital H (ASCII 72), turn on the LED: |
| 40 |
if (incomingByte == 'H') { |
| 41 |
digitalWrite(ledPin, HIGH); |
| 42 |
} |
| 43 |
// if it's an L (ASCII 76) turn off the LED: |
| 44 |
if (incomingByte == 'L') { |
| 45 |
digitalWrite(ledPin, LOW); |
| 46 |
} |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
/* Processing code for this example |
| 51 |
|
| 52 |
// Mouse over serial |
| 53 |
|
| 54 |
// Demonstrates how to send data to the Arduino I/O board, in order to turn ON |
| 55 |
// a light if the mouse is over a square and turn it off if the mouse is not. |
| 56 |
|
| 57 |
// created 2003-4 |
| 58 |
// based on examples by Casey Reas and Hernando Barragan |
| 59 |
// modified 30 Aug 2011 |
| 60 |
// by Tom Igoe |
| 61 |
// This example code is in the public domain. |
| 62 |
|
| 63 |
import processing.serial.*; |
| 64 |
|
| 65 |
float boxX; |
| 66 |
float boxY; |
| 67 |
int boxSize = 20; |
| 68 |
boolean mouseOverBox = false; |
| 69 |
|
| 70 |
Serial port; |
| 71 |
|
| 72 |
void setup() { |
| 73 |
size(200, 200); |
| 74 |
boxX = width / 2.0; |
| 75 |
boxY = height / 2.0; |
| 76 |
rectMode(RADIUS); |
| 77 |
|
| 78 |
// List all the available serial ports in the output pane. |
| 79 |
// You will need to choose the port that the Arduino board is connected to |
| 80 |
// from this list. The first port in the list is port #0 and the third port |
| 81 |
// in the list is port #2. |
| 82 |
// if using Processing 2.1 or later, use Serial.printArray() |
| 83 |
println(Serial.list()); |
| 84 |
|
| 85 |
// Open the port that the Arduino board is connected to (in this case #0) |
| 86 |
// Make sure to open the port at the same speed Arduino is using (9600bps) |
| 87 |
port = new Serial(this, Serial.list()[0], 9600); |
| 88 |
} |
| 89 |
|
| 90 |
void draw() { |
| 91 |
background(0); |
| 92 |
|
| 93 |
// Test if the cursor is over the box |
| 94 |
if (mouseX > boxX - boxSize && mouseX < boxX + boxSize && |
| 95 |
mouseY > boxY - boxSize && mouseY < boxY + boxSize) { |
| 96 |
mouseOverBox = true; |
| 97 |
// draw a line around the box and change its color: |
| 98 |
stroke(255); |
| 99 |
fill(153); |
| 100 |
// send an 'H' to indicate mouse is over square: |
| 101 |
port.write('H'); |
| 102 |
} |
| 103 |
else { |
| 104 |
// return the box to its inactive state: |
| 105 |
stroke(153); |
| 106 |
fill(153); |
| 107 |
// send an 'L' to turn the LED off: |
| 108 |
port.write('L'); |
| 109 |
mouseOverBox = false; |
| 110 |
} |
| 111 |
|
| 112 |
// Draw the box |
| 113 |
rect(boxX, boxY, boxSize, boxSize); |
| 114 |
} |
| 115 |
|
| 116 |
*/ |
| 117 |
|
| 118 |
/* Max/MSP version 5 patch to run with this example: |
| 119 |
|
| 120 |
----------begin_max5_patcher---------- |
| 121 |
1672.3oc2ZszaaiCD9ryuBBebQVCQRYao8xhf1cQCPVfBzh8RRQ.sDsM2HSZ |
| 122 |
HQmlzh9eu7gjsjsEk7y0oWjiHoHm4aluYHGlueUmtiDuPy5B9Cv8fNc99Uc5 |
| 123 |
XZR2Pm726zcF4knDRlYXciDylQ4xtWa6SReQZZ+iSeMiEQR.ej8BM4A9C7OO |
| 124 |
kkAlSjQSAYTdbFfvA27o2c6sfO.Doqd6NfXgDHmRUCKkolg4hT06BfbQJGH3 |
| 125 |
5Qd2e8d.QJIQSow5tzebZ7BFW.FIHow8.2JAQpVIIYByxo9KIMkSjL9D0BRT |
| 126 |
sbGHZJIkDoZOSMuQT.8YZ5qpgGI3locF4IpQRzq2nDF+odZMIJkRjpEF44M3 |
| 127 |
A9nWAum7LKFbSOv+PSRXYOvmIhYiYpg.8A2LOUOxPyH+TjPJA+MS9sIzTRRr |
| 128 |
QP9rXF31IBZAHpVHkHrfaPRHLuUCzoj9GSoQRqIB52y6Z.tu8o4EX+fddfuj |
| 129 |
+MrXiwPL5+9cXwrOVvkbxLpomazHbQO7EyX7DpzXYgkFdF6algCQpkX4XUlo |
| 130 |
hA6oa7GWck9w0Gnmy6RXQOoQeCfWwlzsdnHLTq8n9PCHLv7Cxa6PAN3RCKjh |
| 131 |
ISRVZ+sSl704Tqt0kocE9R8J+P+RJOZ4ysp6gN0vppBbOTEN8qp0YCq5bq47 |
| 132 |
PUwfA5e766z7NbGMuncw7VgNRSyQhbnPMGrDsGaFSvKM5NcWoIVdZn44.eOi |
| 133 |
9DTRUT.7jDQzSTiF4UzXLc7tLGh4T9pwaFQkGUGIiOOkpBSJUwGsBd40krHQ |
| 134 |
9XEvwq2V6eLIhV6GuzP7uzzXBmzsXPSRYwBtVLp7s5lKVv6UN2VW7xRtYDbx |
| 135 |
7s7wRgH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kFh |
| 151 |
3NGaAsYBUAO.8N1U4WKycxbQdrWxJdXd10gNIO+hkUMmm.CZwknu7JbNUYUq |
| 152 |
0sOsTsI1QudDtjw0t+xZ85wWZd80tMCiiMADNX4UzrcSeK23su87IANqmA7j |
| 153 |
tiRzoXi2YRh67ldAk79gPmTe3YKuoY0qdEDV3X8xylCJMTN45JIakB7uY8XW |
| 154 |
uVr3PO8wWwEoTW8lsfraX7ZqzZDDXCRqNkztHsGCYpIDDAOqxDpMVUMKcOrp |
| 155 |
942acPvx2NPocMC1wQZ8glRn3myTykVaEUNLoEeJjVaAevA4EAZnsNgkeyO+ |
| 156 |
3rEZB7f0DTazDcQTNmdt8aACGi1QOWnMmd+.6YjMHH19OB5gKsMF877x8wsJ |
| 157 |
hN97JSnSfLUXGUoj6ujWXd6Pk1SAC+Pkogm.tZ.1lX1qL.pe6PE11DPeMMZ2 |
| 158 |
.P0K+3peBt3NskC |
| 159 |
-----------end_max5_patcher----------- |
| 160 |
|
| 161 |
*/ |