SuperCollider: Light Dependent Resistor

System Message: ERROR/3 (<string>, line 2)

Document or section may not begin with a transition.


Breadboard Circuit

/images/basics/ldr_input_fritzing.png

Arduino Code

  • install osc from cnmat

void setup() {

   Serial.begin(9600);
}

void loop() {


 int sensorValue = analogRead(A0);

 // scale to 0..1
 float voltage   = sensorValue/1024.0 ;

 Serial.println(voltage);

}

SC Code

(
p = SerialPort(
  "/dev/ttyACM0",
  baudrate: 9600,
  crtscts: true);
)
~sensorBUS = Bus.control(s,1);
~sensorBUS.scope;
(
r= Routine({
    var byte, str, res;
    inf.do{|i|
        if(p.read==10, {
            str = "";
            while({byte = p.read; byte !=13 }, {
                str= str++byte.asAscii;
            });
            res= str.asFloat;

            // ("read value:"+res).postln;

                    ~sensorBUS.set(res);
        });
    };
}).play;
)

External Resources

The SuperCollider Tutorial by Eli Fieldsteel shows a similar solution for getting Arduino sensors into SuperCollider via USB.