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

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; 

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

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

  //s = new Sound(this);
  waveform = new Waveform(this, samples);
  rms = new Amplitude(this);

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

void draw() {
  image(pg, 0, 0);
//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
//Suaviza as formas de onda
 sum += (rms.analyze() - sum) * smoothingFactor;
 float rms_scaled = map(lightAmp,0,1024,0,255);
//Forma de onda
   for(int i = 0; i < samples; i++){
    map(i, 1, samples, 0, width),
    map(waveform.data[i]*(map(lightAmp, height, 0, 0, 1)), -1, 1, 0, height)

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


Arduino IDE

#include <Esplora.h>

void setup() {
  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:


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.