Help for a noob?

edited May 2015 in Arduino

Hey everyone, i know this is probably a really simple thing to do but after a couple of days running into a brick wall i was wondering if i could just ask for some help. Basically I'm trying to get a button connected through the arduino/ firmata to activate my control p 5 button, which currently works like a switch going through iterations to change a wave form. I am getting 0/1 signal from the pin but can't make it trigger the button or increase the current value of the iteration to effect anything. sorry i know most of the questions on this site are from people doing much more complicated things, but any help is appreciated

Answers

  • if it helps i've been trying to use if (arduino.digitalRead(2) == Arduino.HIGH) { wave3Iteration++;

    to no avail will keep looking tho

  • edited May 2015

    Hello ! Please send your code ! - it's a kind of proof that you tryed something by yourself and it's easier for us to help you from somewhere instead of nowhere -

  • edited May 2015
    import processing.serial.*;
    
    import cc.arduino.*;
    
    
    import ddf.minim.*;
    import ddf.minim.ugens.*;
    import controlP5.*;
    
    ControlP5 controlP5;   
    Arduino arduino;
    
    
    Minim minim;
    AudioOutput out;
    MoogFilter  moog;
    
    
    Oscil fm;
    Oscil wave;
    int joyIteration = 1;
    int FilterIteration = 0;
    int wave3Iteration = 1;
    int FMPatchIteration = 1;
    
    
    
    
    void setup()
    {
    
    size( 512, 300);
    
    minim = new Minim( this );
    out   = minim.getLineOut();
    controlP5 = new ControlP5(this);
    
    
    controlP5.addKnob("ampknob",-50,50,0,310,220,50);
    controlP5.addKnob("Waveknob",0,2000,10,370,220,50);
    controlP5.addKnob("FMknob",0,400,10,430,220,50);
    controlP5.addButton("joy",1,30,250,60,20);
    controlP5.addButton("Filter",1,100,250,60,20);
    controlP5.addButton("wave3",1,170,250,60,20);
    controlP5.addButton("FMPatch",1,240,250,60,20);
    
    
    arduino = new Arduino(this, "COM4", 57600);
    
        // Set the Arduino digital pins as inputs.
    
    
    for (int i = 0; i <= 13; i++)
    arduino.pinMode(i, Arduino.INPUT);
    
     // Generate oscilators and filter
    
    
      wave = new Oscil( 200 , 0.8, Waves.SINE );
    
      fm   = new Oscil( 10, 2, Waves.SINE );
    
      fm.offset.setLastValue(10 );
    
      wave.patch( out );
    
    
     moog    = new MoogFilter( 1200, 0.5 );
     wave.patch( moog ).patch( out );
    
    }
    
    void Waveknob(int theValue) {
     wave.setFrequency( theValue *10);
     println(theValue); 
    
    } 
    
    void FMknob (int FMValue){
    fm.offset.setLastValue (FMValue);
    }
    void ampknob (int ampvalue)
    {
    out.setGain(ampvalue);
    
    }
    
    void FMPatch (int theValue5)
    {
      FMPatchIteration++;
    
      switch( FMPatchIteration )
      {
        case 1: 
          fm.unpatch(wave);
    
          break;
    
        case 2:
         fm.patch( wave.frequency );
          break;
    
        case 3:
    
          break;
    
    
        default: break; 
      }
    
       if (FMPatchIteration ==2 )
      {
        FMPatchIteration =0;
      }
    }
    
    void joy (int theValue)
    {
      joyIteration++;
    
      switch( joyIteration ) 
    {
    
       case 1:
    
          break;
    
        case 2:
    
          break;
    
        case 3:
    
          break;
    
    
        default: break; 
      }
    
       if (joyIteration ==4 )
      {
        joyIteration =1;
      }
    
    }
    
    void wave3 (int theValue5)
    
    {
    
      wave3Iteration++;
    
    
      switch( wave3Iteration  ) 
    
      {
        case 1: 
          wave.setWaveform( Waves.SINE );
          break;
    
        case 2:
          wave.setWaveform( Waves.TRIANGLE );
          break;
    
        case 3:
        wave.setWaveform( Waves.SAW );
          break;
    
        case 4:
    wave.setWaveform( Waves.SQUARE );
          break;
    
        case 5:
         wave.setWaveform( Waves.QUARTERPULSE );
          break;
    
        default: break; 
         }
    
       if (wave3Iteration > 5)
      {
        wave3Iteration =0;
    
      }
     println(wave3Iteration);
    }
    
    
    void Filter (int theValue2)
    {
      FilterIteration++;
    
      switch( FilterIteration )
      {
        case 1: 
          moog.type = MoogFilter.Type.LP;
          break;
    
        case 2:
          moog.type = MoogFilter.Type.HP;
          break;
    
        case 3:
          moog.type = MoogFilter.Type.BP;
          break;
    
    
        default: break; 
      }
    
    
       if (FilterIteration == 3)
    
      {
    
        FilterIteration =0;
      }
    }
    
    
    void draw()
    {
    
      background( 0 );
    
      stroke( 255 );
    
    for( int i = 0; i < out.bufferSize() - 1; i++ )
    {
    float x1  =  map( i, 0, out.bufferSize(), 0, width );
    float x2  =  map( i+1, 0, out.bufferSize(), 0, width );
    
    line( x1, 50 + out.left.get(i)*50, x2, 50 + out.left.get(i+1)*50);
    line( x1, 150 + out.right.get(i)*50, x2, 150 + out.right.get(i+1)*50);
    }  
    
    
    {
    
    }
    
    }
     void mouseMoved()
    {
      if (joyIteration == 1)
    {
    float amp = map( mouseY, 0, height, 1, 0 );
      wave.setAmplitude( amp );
    
      float freq = map( mouseX, 0, width, 110, 880 );
      wave.setFrequency( freq );
    
    }
    
    if(joyIteration == 2)
    
    
    {
       float modulateAmount = map( mouseY, 0, height, 220, 1 );
      float modulateFrequency = map( mouseX, 0, width, 0.1, 100 );
    
      fm.setFrequency( modulateFrequency );
      fm.setAmplitude( modulateAmount );
    
    
    }
    if(joyIteration == 3)
    
    
    {
      float freq = constrain( map( mouseX, 0, width, 200, 12000 ), 200, 12000 );
      float rez  = constrain( map( mouseY, height, 0, 0, 1 ), 0, 1 );
    
      moog.frequency.setLastValue( freq );
      moog.resonance.setLastValue( rez  );
    }
    
    int digitalValue = arduino.digitalRead(2);
     if (arduino.digitalRead(2) == Arduino.HIGH) 
     { 
    wave3Iteration ++;
         println (arduino.digitalRead(2));
     }
    
  • edited May 2015

    Hey thanks for the quick response and sorry for the wall of code i'm still trying to figure out the best way to upload it and make it easier to read as the formatting is a bit weird and this is all pretty new to me (gonna try to get it on github or something in the morning). the bit im really stuck with is if (arduino.digitalRead(2) == Arduino.HIGH) { wave3Iteration ++; println (arduino.digitalRead(2)); }

    I have tried several other things variations on that idea but that is kind of where i'm stuck with making the button activate the button, i was reading input signal but i haven't found the probably very simple way of making it interact with the cp5 button function.

  • I think it has uploaded to the Arduino the sketch "standardFirmata" from Firmata example.     With wave3Iteration ++, when you press the button after 1 second the countour is very fast, we need a state variable.   Not works well in mouseMoved

  • edited May 2015

    Hey, cheers and yeah i know thats bad place to put it had it in the wave button area but moved it to the bottom when i pasted it over, but the other two things have got me thinking, ive just got back from work so gonna wait till the morning but your right i probably need a variable set up based off the input from the arduino and some kind of delay as well maybe so it has more time to read? will give it a go, thanks for the suggestions :D

  • edited May 2015

    arduino with "standardFirmata" sketch, in Processing try this int state=0;

    void draw(){
    ...
    ...
    pushButton();
    }
    

    debouncing for button not necessary

    void pushButton(){
    int digitalValue = arduino.digitalRead(2);
     if (arduino.digitalRead(2) == Arduino.HIGH && state ==0) 
     { 
     wave.setWaveform( Waves.SINE ); 
       state=1;
     }
    else if (arduino.digitalRead(2) == Arduino.LOW && state ==1)
    {
      state=2;
    }
    else if (arduino.digitalRead(2) == Arduino.HIGH && state ==2)
    {
    wave.setWaveform( Waves.TRIANGLE );
      state=3;
    }
    else if (arduino.digitalRead(2) == Arduino.LOW && state ==3)
    {
      state=4;
    }
    else if (arduino.digitalRead(2) == Arduino.HIGH && state ==4)
    {
    wave.setWaveform( Waves.SAW );
      state=5;
    }
    else if (arduino.digitalRead(2) == Arduino.LOW && state ==5)
    { 
      state=0;
    }
     println (state);
      }
    
Sign In or Register to comment.