What is the code from the light sensor to control my waveform?

Hi, I’m having difficulties in reaching my goal, which is with the Arduino Esplora, when I point more light to the light sensor my waveform in the processing increases and when the sensor receives less this waveform disappears. However, with these codes I got, that doesn’t happen. What it does is when the light sensor receives more or less light, the volume of the music that is playing increases and decreases respectively. Can someone help me resolve this situation? Thanks

//Biclioteca 
import processing.serial.*;
import processing.sound.*;
Serial myPort;
float lightAmp;
PGraphics pg;

//Variáveis de som do processing
SoundFile sample;
Waveform waveform;
Amplitude rms;
SoundFile file;
Sound s;

//Variável de suavização para suavizar mudanças repentinas de amplitude
float smoothingFactor = 0.25;

//Variável para armazenar o valor de amplitude suavizada
float sum;

//Amostras da forma de onda que irão ser lidas de uma vez
int samples = 100;

//Variáveis para as cores e para os circulos 
float r;
float g;
float b;
float a;
float diam;
float x;
float y; 

//Janela 
void setup() {
  size(2000, 2000);
  
  myPort  =  new Serial (this, Serial.list()[0],  9600);
  myPort.bufferUntil ( '\n' );
  
  pg = createGraphics(2000, 2000); 
  pg.beginDraw();  
  pg.background(0);
  pg.endDraw();
  smooth();

//Local para a música
 //sample = new SoundFile(this, "Happy Little Elves - Audionautix.wav");
  //sample.loop();

  //s = new Sound(this);
  
  waveform = new Waveform(this, samples);
  waveform.input(sample);
  
  rms = new Amplitude(this);
  rms.input(sample);
}

void serialEvent  (Serial myPort) {
lightAmp  =  float (myPort.readStringUntil ( '\n' ) ) ;
}

void draw() {
  image(pg, 0, 0);
  pg.beginDraw();
  
//Cores aleatórias  
  r = random(255);
  g = random(255);
  b = random(255);
  
//Posição e dimensões dos círculos
  a = random(255);
  diam = random(15);
  x = random(width);
  y = random(height);
  
//Características dos círculos
  pg.noStroke();
  pg.fill(r,g,b,a);
  pg.ellipse(x,y,diam,diam); 
  pg.endDraw();
 
 strokeWeight(1);
 
//Suaviza as formas de onda
 sum += (rms.analyze() - sum) * smoothingFactor;
 
 float rms_scaled = map(lightAmp,0,1024,0,255);
 
 waveform.analyze(); 
 
//Forma de onda
 beginShape();
 {
   fill(r,g,b,a);
   for(int i = 0; i < samples; i++){
    vertex(
    map(i, 1, samples, 0, width),
    map(waveform.data[i]*(map(lightAmp, height, 0, 0, 1)), -1, 1, 0, height)
    );
  }
  endShape();
}


//Rato controla a intensidade do som
float amplitude = map(lightAmp, 0, 1024, 7, 1000);



//Volume
s.volume(amplitude);
}

Arduino IDE

#include <Esplora.h>


void setup() {
  Serial.begin(9600);
  while (!Serial) {
    
  }    
}
 


// The loop routine runs over and over again forever:
void loop () {
  // Read the input on analog pin 0:
  int sensorValue = Esplora.readLightSensor(); // Esplora.readLightSensor() replaces analogRead()
  // Print out the value you read:
  Serial.println(sensorValue);
}
  

Hello,

You received data (lightAmp is 0 to 1024) from the Arduino and mapped it to 0 to 255 but you are not using the variable rms_scaled anywhere in your code.

This is where you need to scale the amplitude of the waveform.data[]:

Instead of above consider multiplying waveform.data[i] with rms_scaled.

You are also mapping lightAmp and using it to control your volume elsewhere in the provided code.

You need to understand what each element of your code is doing and make it happen.

It is doing exactly what you coded it to do.

You have other related posts tagged as homework.
If this is homework please tag it as such.

:)