arduivis

a bi-directional communication paradigm for programming languages & microcontrollers

Getting Started FAQ Projects
    MaxMSP Pure Data Python NodeJS

    Pure Data Model #6: Multiple Feedbacks

    Abstract

    This is an example of to read sliders from PD. An Arduino reads and parses this data, sending it from the Arduino and back into PD. This feedback data is then sent back to the Arduino from Pure Data, controlling the PWM of a LED. This is done with several streams of data in this example.

    Arduino

    
    /* 
    
    ~~~~~~~ arduivis - Pure Data ~~~~~~~
    ~~~~~ model#6: multiple feedbacks ~~~~~
    
    PD: arduivis_model6_PD_multipleFeedbacks.pd
    
    This is an example of to read sliders from PD. 
    An Arduino reads and parses this data, sending
    it from the Arduino and back into PD. This 
    feedback data is then sent back to the Arduino
    from Pure Data, controlling the PWM of a LED. 
    This is done with several streams of data in 
    this example.
    
    This code is in the public domain
    
    written by Christopher Konopka
    http://cskonopka.github.io/arduivis/
    http://christopherkonopka.com/
    
    */
    
    void setup() 
    {
      //  Create/open serial port    
        Serial.begin(9600);       
    
      // Define LED mode 
      // PWM LED
        pinMode(3, OUTPUT);
        pinMode(5, OUTPUT);  
        pinMode(6, OUTPUT);
        pinMode(9, OUTPUT);  
    }
    
    void loop() 
    { 
      // Sliders from Pure Data
        int pdSlider1, pdSlider2, pdSlider3, pdSlider4;
    
      // Feedback from Pure Data (original output from Arduino)
        int feedbackFromPD1, feedbackFromPD2, feedbackFromPD3, feedbackFromPD4;
    
      // Parse incoming Pure Data slider values
      // from Pure Data, to Arduino
        pdSlider1 = Serial.parseInt();
        pdSlider2 = Serial.parseInt();
        pdSlider3 = Serial.parseInt();
        pdSlider4 = Serial.parseInt(); 
    
    
      // Parse incoming Pure Data (feedback) values
      // from Pure Data (feedback), to Arduino 
        feedbackFromPD1 = Serial.parseInt();
        feedbackFromPD2 = Serial.parseInt();
        feedbackFromPD3 = Serial.parseInt();
        feedbackFromPD4 = Serial.parseInt(); 
    
      // Write parsed values to LEDs
      // Fading LED
      // from Pure Data (feedback), to Arduino
        analogWrite(3, feedbackFromPD1);
        analogWrite(5, feedbackFromPD2);
        analogWrite(6, feedbackFromPD3);    
        analogWrite(9, feedbackFromPD4);
      
        // Write parsed slider values to serial buffer
      // [comport] object
      // to Pure Data, from Arduino
        Serial.print(pdSlider1);
        Serial.print(" ");
        Serial.print(pdSlider2);
        Serial.print(" ");
        Serial.print(pdSlider3);
        Serial.print(" ");
        Serial.print(pdSlider4);
        Serial.print(" ");
    
      // Write feedback values to serial buffer
      // [comport] object
      // to Pure Data, from Arduino
      // This is useful for debugging
        Serial.print(feedbackFromPD1);
        Serial.print(" "); 
        Serial.print(feedbackFromPD2);
        Serial.print(" ");   
        Serial.print(feedbackFromPD3);
        Serial.print(" "); 
        Serial.println(feedbackFromPD4); 
        
        delay(2);
    }
    

    PD-Extended

    some_text