sound control
 Software and Programming Related   Started by Ninjamann S   2015-09-11 11:11:50 -04:00   Comments: 1    Viewed: 414

  1. Ninjamann S
    Ninjamann S Member

    Postby ninjaman » Fri Jun 13, 2014 1:17 pm

    hello

    im having a problem getting this program to stop, I want it to react to sound and stop. it wont do this. I have tried a few different things but nothing seems to work. at the bottom in the main task I have precedes. I cant seem to get this to stop. I have tried StopAllTasks(); but this doesn't allow the program to work. I have two until statements that mean I click my fingers twice and the program stops.
    could some one please give me some advice on how I could get this to stop when responding to sound. or at least point me in the direction of a web site that explains it. I cant figure this out. I have tried putting the precedes program in a while statement and break; using the until statement but that doesn't work.
        #define SOUNDTHRESHOLD 60     //define the soundthreshold value of 99
        #define MIC SENSOR_2             //define input 2, call it "MIC"
        #define NEAR 30                  //set the distance the sensor can "see", cm
    
        mutex moveMutex;
    
        task turn_head()
        {
    
          while(true)                    //start a continuous loop
           {
            RotateMotor(OUT_B, 60, 30);  //rotate the US sensor left, 60 degrees, power 60
               Wait(5);                  //wait for 5 milliseconds
              if(SensorUS(IN_1) < NEAR)  //if the sensor sees something within 30cm
              {
               Acquire(moveMutex);       //acquire control of driving motors
               Off(OUT_AC);              //turn off both driving motors
               OnRev(OUT_C, 75);         //reverse right motor, power 75
               until(SensorUS(IN_1) > NEAR); //when there is nothing within range
               Off(OUT_C);                //turn off right side motor
               Release(moveMutex);        //release control of the driving motors
               }
            RotateMotor(OUT_B, 60, -30);  //rotate US sensor right, 60 degrees, power 60
                Wait(5);                  //wait for 5 milliseconds
    
            RotateMotor(OUT_B, 60, -30);  //rotate US sensor right, 60 degrees, power 60
                Wait(5);                  //wait for 5 milliseconds
              if(SensorUS(IN_1) < NEAR)   //if sensor sees something within 30cm
              {
               Acquire(moveMutex);        //acquire control of driving motors
               Off(OUT_AC);               //turn off both driving motors
               OnRev(OUT_A, 75);          //reverse left side motor, power 75
               until(SensorUS(IN_1) > NEAR); //when there is nothing within range
               Off(OUT_A);                //turn off left side motor
               Release(moveMutex);        //release control of the driving motors
              }
            RotateMotor(OUT_B, 60, 30);   //rotate US sensor right, 60 degrees, power 60
               Wait(5);                   //wait 5 milliseconds
           }
        }
    
        task move_square()
        {
    
        int x,power;                    //make x integer a power value
    
        while(true)                     //start a continuous loop
        {
          x = SENSOR_3;                  //set sensor input 3 to x
          if (x == 2)                    //if value sensed by x == 2(blue)
          {
           Acquire(moveMutex);           //acquire control of the driving motors
    
           Wait(50);                  //turn off left side motor
           OnRev(OUT_C,50);              //reverse right side motor, power 50
           Wait(50);                    //wait 300 milliseconds
           Release(moveMutex);           //release control of driving motors
          }
          if (x == 6)                    //if value sensed by x == 6(white)
          {
           Acquire(moveMutex);           //acquire control of the driving motors
           OnFwd(OUT_AC, 50);            //drive both motors forward, power 50
           Wait(50);                    //wait 300 milliseconds
           Release(moveMutex);           //release control of driving motors
           }
          }
        }
    
    
    
    
    
        task main()
        {
          SetSensorColorFull(IN_3);      //set up the color sensor, set it to input 3
          SetSensorSound(IN_2);          //set up the sound sensor, set it to input 2
          SetSensorLowspeed(IN_1);       //set up the ultra sonic sensor,  to input 1
          until(MIC > SOUNDTHRESHOLD);
          Precedes(turn_head, move_square); //turn_head to precede move_square
          Wait(100);
          until(MIC > SOUNDTHRESHOLD);
          StopAllTasks();
        }
    
    Ninjamann S, 2015-09-11 11:12:59 -04:00
  2. (You must log in or sign up to post here)

Log in | Sign up
Tems & Conditions!
Help!