Debian Codegraph @

examples/arduinoReadF.csd

raw
1 Arduino-Joystick2Csound1g-fm1-port (version with smoothing)
2
3 - Push Joystick button to turn on note
4 - Use JoystickX to offset and control the modulation index of
5 the foscil opcode from 0-40 via the scale opcode
6 - Use JoystickY to offset and control the Frequency of the foscil
7 opcode up/down two octaves via the scale opcode
8
9 <CsoundSynthesizer>
10
11 <CsInstruments>
12
13 sr = 44100
14 ksmps = 441
15 nchnls = 2
16 0dbfs = 1
17
18 giport init 0
19
20 // NOTE: change USB port "/dev/cu.usbmodem1414301" to correspond
21 // with USB port used by Arduino on your system
22 giport arduinoStart "//dev/ttyACM0", 9600 // for GNULinux
23
24 instr 1
25
26 kk arduinoReadF giport, 1, 2, 3
27 printks "kk=%f\n", 0.5, kk
28 endin
29
30 </CsInstruments>
31
32 <CsScore>
33
34 f 1 0 16384 10 1
35
36 i 1 0 1
37
38 e
39
40 </CsScore>
41
42 </CsoundSynthesizer>
43
44 <arduinoSketch>
45 // Float Example
46
47 // John ffitch & Richard Boulanger
48 // December 7, 2020
49
50 // BreadBoard & Arduino Setup
51
52 void setup() {
53 // NOTE: Digital pins can be either inputs or outputs.
54
55 Serial.begin(9600);
56 }
57
58 val// put_val( ) - a function to send data values to the Csound
59 // "arduinoRead" opcode
60 // The first argument of the put_val function "int senChan" sets
61 // the software channel number that Csound reads
62 // NOTE: "senChan" does "not" define the input pin that is used on
63 // the Arduino for a specific sensor
64 // The specific Arduino input pin used by any sensor is assigned
65 // and set elsewhere in the Arduino sketch and mapped to a
66 // user-defined put_val "senChan" channel
67
68 void put_val(int senChan, int senVal)
69 // Set the Csound receive channel "senChan", and read from
70 // the sensor data stream "senVal"
71 { // The packing of the data is sssssvvv 0vvvvvvv where s is a
72 // senChan bit, v a senVal bit and 0 is zero` bit
73 int low = senVal&0x7f;
74 int hi = ((senVal>>7)&0x07) | ((senChan&0x1f)<<3);
75 Serial.write(low); Serial.write(hi);
76 }
77
78 void put_float(int senChan1, int senChan2, int senChan3, float senVal)
79 {
80 typedef union {
81 float f;
82 long i;
83 } JOINT;
84 JOINT x;
85 x.f = senVal;
86 put_val(senChan1, (x.i>> 2)& 0x3ff);
87 put_val(senChan2, (x.i>>12)& 0x3ff);
88 put_val(senChan3, (x.i>>22)& 0x3ff);
89 }
90
91 void loop() {
92
93 Serial.write(0xf8); // Synchronization Byte - (essential!) marks beginning of new serial frame
94
95 put_float(1,2,3,1.23456789);
96
97 delay(10);
98
99 }
100
101 </arduinoSketch>