p5.Oscillator frequency not changing with the value contained in the index of an array

Trying to convert the user input into char code/ascii code. Trying to use a for loop to continuously parse through the array containing the char code numbers 1 by 1 and use those numbers to change the oscillator frequency. The looping char code numbers will print but wont change the frequency so I’m confused.

Probably didn’t explain it great. Very new to coding and JavaScript. Any help would be greatly appreciated.

let x;
let y = [];
let osc;

function setup() {
  
  noCanvas();
  x = createInput();
  x.changed(generate);
  
  osc = new p5.Oscillator('sine');
}

function generate() {
  
  print(x.value()); //printing letter values of user input
  y = unchar(split(x.value(), '')); //converting letters into ASCII code array
  osc.start()
  osc.amp(0.5)
  } 

function draw(){
  
    for(let i of y){
      //if(i == y.length){
        //i=0
      //}
    osc.freq(i);
    print(i);
    }
}

Try changing x.changed(generate); to: x.input(generate);

1 Like