J3C6F


## ARDUINO MFS -- PROCESSING

  https://maker.pro/arduino/tutorial
    /how-to-make-arduino-and-processing-ide-communicate

Processing code

cat pc.pde

  // Importing the serial library to communicate with the Arduino 

  import processing.serial.*;    

  Serial myPort;
  float  background_color ;

  void setup ( ) {
    size (500,  500);
    // Set the com port and the baud rate according to the Arduino IDE
    myPort  =  new Serial (this, "COM4",  9600); 
    // Receiving the data from the Arduino IDE
    myPort.bufferUntil('\n');   
  } 

  void serialEvent  (Serial myPort) {
    // Change the background color according to received data
    background_color = float(myPort.readStringUntil('\n'));
  } 

  void draw ( ) {
    // HSB or RGB. Kind of bullshit.
    background( 150, 50, background_color );   
    if (mousePressed && (mouseButton==LEFT)) myPort.write('1');
    if (mousePressed && (mouseButton==RIGHT)) myPort.write('0');
  }

EOF   

Arduino code

cat ardu.ino

  int led_pin = 10;   // MFS: 10, 11, 12, 13
  int pot_pin = A0;   // MFS: Potentiometer 5V A0 GND
  int pot_output;

  void setup ( ) {
    pinMode(led_pin, OUTPUT);
    Serial.begin(9600);
  } 

  void loop ( ) { 
    pot_output = analogRead (pot_pin);
    int mapped_output = map(pot_output, 0, 1023, 0, 255); 
    // Sending the output to Processing IDE
    Serial.println( mapped_output);     
    // Checking if the Processing IDE has send a value or not
    if (Serial.available() > 0) {   
      char state = Serial.read();
      if (state == '1') digitalWrite(led_pin, HIGH); 
      if (state == '0') digitalWrite(led_pin, LOW);
    } 
    delay(50);
  }

EOF


## RAINBOW (PROCESSING)

      ^ B   Human eye:        Physics:
      |     3D: RGB cones     1D: Wavelenght
      |
      o-----> G               o--+-----+-------+-->
     /                           R     G       B
  R v
  
rainbow12.pde

  size(360,100);
  colorMode( HSB, 360, 100, 100); // Hue in degrees in [0, 360],
                                  // saturation/brightness in [0, 100]
  noStroke();                     // Disable stroke (outline).

  for( int i = 0; i < 360; i++) {
      fill(i*30, 100, 100);      // 30*12 = 360
      rect(i*30, 0, 30, 100);
  }

EOF

rainbowGrad.pde

  size( 360, 100);
  colorMode( HSB, 360, 100, 100);
  noStroke();

  for (int i = 0; i < 360; i++) {
      fill(i, 100, 100);
      rect(i, 0, 1, 100);
  }
  
EOF


## DICTIONARY
                        
Hue          Värvitoon   Оттенок
Saturation   Küllastus   Насыщенность
Brightness   Heledus     Яркость     







