Debian Codegraph @

opcodes/serialWrite.xml

raw symbols SCIP
1 <refentry id="serialWrite">
2 <indexterm
3 id="IndexSerialWrite"><primary>serialrite</primary></indexterm>
4
5 <refentryinfo><title>Serial I/O</title></refentryinfo>
6 <refmeta>
7 <refentrytitle>serialWrite</refentrytitle>
8 </refmeta>
9
10 <refnamediv>
11 <refname>serialWrite</refname>
12 <refpurpose>
13 Write data to a serial port.
14 </refpurpose>
15 </refnamediv>
16
17 <refsect1>
18 <title>Description</title>
19 <para>Plugin opcode in serial.</para>
20 <para>
21 Write data to a serial port for arduino.
22 </para>
23 </refsect1>
24
25 <refsect1>
26 <title>Syntax</title>
27 <synopsis> <command>serialWrite</command> iPort, iByte</synopsis>
28 <synopsis> <command>serialWrite</command> iPort, kByte</synopsis>
29 <synopsis> <command>serialWrite</command> iPort, SBytes</synopsis>
30 </refsect1>
31
32 <refsect1>
33 <title>Performance</title>
34 <para>
35 <emphasis>iPort</emphasis> -- port number optained from a
36 <emphasis>serialBegin</emphasis> opcode.
37 </para>
38 <para>
39 <emphasis>iByte</emphasis> -- a byte of data to write.
40 </para>
41 </refsect1>
42
43 <refsect1>
44 <title>Examples</title>
45 <para>
46 Here is an example of the serialWrite opcode. It uses the file <ulink url="examples/serialWrite.csd"><citetitle>serialWrite.csd</citetitle></ulink>.
47 <example>
48 <title>Example of the serialWrite opcode.</title>
49 <para>See the sections <link linkend="UsingRealTime"><citetitle>Real-time Audio</citetitle></link> and <link linkend="CommandFlags"><citetitle>Command Line Flags</citetitle></link> for more information on using command line flags.</para>
50 <xi:include href="examples-xml/serialWrite.csd.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
51 </example>
52 This is the matching Arduino code :
53 <screen>
54 void setup() {
55 // enable serial communication
56 Serial.begin(9600);
57
58 // declare pin 9 to be an output:
59 pinMode(9, OUTPUT);
60 }
61
62 void loop() {
63 // only do something if we received something (this should be at csound's k-rate)
64 if (Serial.available()) {
65 // set the brightness of LED (connected to pin 9) to our input value
66 int brightness = Serial.read();
67 analogWrite(9, brightness);
68
69 // while we are here, get our knob value and send it to csound
70 int sensorValue = analogRead(A0);
71 Serial.write(sensorValue/4); // scale to 1-byte range (0-255)
72 }
73 }
74 .....</screen>
75 </para>
76 </refsect1>
77
78 <refsect1>
79 <title>See Also</title>
80 <para><link linkend="nonMIDIdevices"><citetitle>non-MIDI Devices</citetitle></link></para>
81 </refsect1>
82
83 <refsect1>
84 <title>Credits</title>
85 <para>
86 <simplelist>
87 <member>Author: &namematt;</member>
88 <member>2011</member>
89 </simplelist>
90 </para>
91 <para>New in version 5.14</para>
92 </refsect1>
93 </refentry>