View unanswered posts | View active topics It is currently Fri Jul 25, 2014 11:03 am






Reply to topic  [ 1 post ] 
Will this code work 
Author Message
Rookie

Joined: Wed Feb 08, 2012 8:28 pm
Posts: 13
Post Will this code work
I need the code to run the task Mario at the same time as task main but it cant give the tasks timeslices task main needs to always work and task mario need to always work they cant switch between tasks they need to run at the same time. I figured maybe the wait1msec after the starttask mario might make it not hog cpu but i dont know take a look and make any suggestions about any part of the code you want; thanks
Thekid986



Code:
#pragma config(Hubs,  S1, HTMotor,  HTMotor,  HTServo,  HTMotor)
#pragma config(Sensor, S1,     ,               sensorI2CMuxController)
#pragma config(Motor,  motorA,          motorA,        tmotorNormal, PIDControl, encoder)
#pragma config(Motor,  motorB,          motorB,        tmotorNormal, PIDControl, encoder)
#pragma config(Motor,  mtr_S1_C1_1,     motorD,        tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C1_2,     motorE,        tmotorNormal, openLoop, reversed)
#pragma config(Motor,  mtr_S1_C2_1,     motorF,        tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C2_2,     motorG,        tmotorNone, openLoop)
#pragma config(Motor,  mtr_S1_C4_1,     motorH,        tmotorNormal, openLoop, reversed)
#pragma config(Motor,  mtr_S1_C4_2,     motorI,        tmotorNormal, openLoop)
#pragma config(Servo,  srvo_S1_C3_1,    lift,                 tServoStandard)
#pragma config(Servo,  srvo_S1_C3_2,    balldoor,             tServoStandard)
#pragma config(Servo,  srvo_S1_C3_3,    servo3,               tServoStandard)
#pragma config(Servo,  srvo_S1_C3_4,    servo4,               tServoStandard)
#pragma config(Servo,  srvo_S1_C3_5,    servo5,               tServoStandard)
#pragma config(Servo,  srvo_S1_C3_6,    servo6,               tServoNone)
#pragma config(SrvoPosition,  Position02,            136, 128, 128, 128, 128, 128, 128, 128)
#pragma config(SrvoPosition,  Position01,            136, 128, 128, 128, 128, 128, 128, 128)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#include "JoystickDriver.c"

task Mario()
{
  //        100 = Tempo
  //          5 = Default octave
  //    Quarter = Default note length
  //        10% = Break between notes
  //
  PlayTone(  988,   14); wait1Msec( 150);  // Note(E6, Duration(16th))
  PlayTone(  988,   14); wait1Msec( 150);  // Note(E6, Duration(16th))
  PlayTone(    0,    7); wait1Msec(  75);  // Note(Rest, Duration(32th))
  PlayTone(  988,   27); wait1Msec( 300);  // Note(E6, Duration(Eighth))
  PlayTone(  784,   14); wait1Msec( 150);  // Note(C6, Duration(16th))
  PlayTone(  988,   27); wait1Msec( 300);  // Note(E6, Duration(Eighth))
  PlayTone( 1175,   27); wait1Msec( 300);  // Note(G6, Duration(Eighth))
  PlayTone(    0,   27); wait1Msec( 300);  // Note(Rest, Duration(Eighth))
  PlayTone(  783,   27); wait1Msec( 300);  // Note(G, Duration(Eighth))
  PlayTone(    0,   27); wait1Msec( 300);  // Note(Rest, Duration(Eighth))
  PlayTone(  784,   27); wait1Msec( 300);  // Note(C6, Duration(Eighth))
  PlayTone(    0,   14); wait1Msec( 150);  // Note(Rest, Duration(16th))
  PlayTone(  783,   27); wait1Msec( 300);  // Note(G, Duration(Eighth))
  PlayTone(    0,   14); wait1Msec( 150);  // Note(Rest, Duration(16th))
  PlayTone(  659,   27); wait1Msec( 300);  // Note(E, Duration(Eighth))
  PlayTone(    0,   14); wait1Msec( 150);  // Note(Rest, Duration(16th))
  PlayTone(  880,   27); wait1Msec( 300);  // Note(A, Duration(Eighth))
  PlayTone(  987,   27); wait1Msec( 300);  // Note(B, Duration(Eighth))
  PlayTone(  932,   14); wait1Msec( 150);  // Note(A#, Duration(16th))
  PlayTone(  880,   27); wait1Msec( 300);  // Note(A, Duration(Eighth))
  PlayTone(  783,   20); wait1Msec( 225);  // Note(G, Duration(16th .))
  PlayTone(  988,   14); wait1Msec( 150);  // Note(E6, Duration(16th))
  PlayTone( 1175,   14); wait1Msec( 150);  // Note(G6, Duration(16th))
  PlayTone( 1320,   27); wait1Msec( 300);  // Note(A6, Duration(Eighth))
  PlayTone( 1047,   14); wait1Msec( 150);  // Note(F6, Duration(16th))
  PlayTone( 1175,   27); wait1Msec( 300);  // Note(G6, Duration(Eighth))
  PlayTone(  988,   27); wait1Msec( 300);  // Note(E6, Duration(Eighth))
  PlayTone(  784,   14); wait1Msec( 150);  // Note(C6, Duration(16th))
  PlayTone(  880,   14); wait1Msec( 150);  // Note(D6, Duration(16th))
  PlayTone(  987,   27); wait1Msec( 300);  // Note(B, Duration(Eighth))
  PlayTone(    0,   14); wait1Msec( 150);  // Note(Rest, Duration(16th))
  PlayTone(  784,   27); wait1Msec( 300);  // Note(C6, Duration(Eighth))
  PlayTone(    0,   14); wait1Msec( 150);  // Note(Rest, Duration(16th))
  PlayTone(  783,   27); wait1Msec( 300);  // Note(G, Duration(Eighth))
  PlayTone(    0,   14); wait1Msec( 150);  // Note(Rest, Duration(16th))
  PlayTone(  659,   27); wait1Msec( 300);  // Note(E, Duration(Eighth))
  PlayTone(    0,   14); wait1Msec( 150);  // Note(Rest, Duration(16th))
  PlayTone(  880,   27); wait1Msec( 300);  // Note(A, Duration(Eighth))
  PlayTone(  987,   27); wait1Msec( 300);  // Note(B, Duration(Eighth))
  PlayTone(  932,   14); wait1Msec( 150);  // Note(A#, Duration(16th))
  PlayTone(  880,   27); wait1Msec( 300);  // Note(A, Duration(Eighth))
  PlayTone(  783,   20); wait1Msec( 225);  // Note(G, Duration(16th .))
  PlayTone(  988,   14); wait1Msec( 150);  // Note(E6, Duration(16th))
  PlayTone( 1175,   14); wait1Msec( 150);  // Note(G6, Duration(16th))
  PlayTone( 1320,   27); wait1Msec( 300);  // Note(A6, Duration(Eighth))
  PlayTone( 1047,   14); wait1Msec( 150);  // Note(F6, Duration(16th))
  PlayTone( 1175,   27); wait1Msec( 300);  // Note(G6, Duration(Eighth))
  PlayTone(  988,   27); wait1Msec( 300);  // Note(E6, Duration(Eighth))
  PlayTone(  784,   14); wait1Msec( 150);  // Note(C6, Duration(16th))
  PlayTone(  880,   14); wait1Msec( 150);  // Note(D6, Duration(16th))
  PlayTone(  987,   27); wait1Msec( 300);  // Note(B, Duration(Eighth))
  PlayTone(    0,   27); wait1Msec( 300);  // Note(Rest, Duration(Eighth))
  PlayTone( 1175,   14); wait1Msec( 150);  // Note(G6, Duration(16th))
  PlayTone( 1109,   14); wait1Msec( 150);  // Note(F#6, Duration(16th))
  PlayTone( 1047,   14); wait1Msec( 150);  // Note(F6, Duration(16th))
  PlayTone(  933,   14); wait1Msec( 150);  // Note(D#6, Duration(16th))
  PlayTone(    0,   14); wait1Msec( 150);  // Note(Rest, Duration(16th))
  PlayTone(  988,   14); wait1Msec( 150);  // Note(E6, Duration(16th))
  PlayTone(    0,   14); wait1Msec( 150);  // Note(Rest, Duration(16th))
  PlayTone(  830,   14); wait1Msec( 150);  // Note(G#, Duration(16th))
  PlayTone(  880,   14); wait1Msec( 150);  // Note(A, Duration(16th))
  PlayTone(  784,   14); wait1Msec( 150);  // Note(C6, Duration(16th))
  PlayTone(    0,   14); wait1Msec( 150);  // Note(Rest, Duration(16th))
  PlayTone(  880,   14); wait1Msec( 150);  // Note(A, Duration(16th))
  PlayTone(  784,   14); wait1Msec( 150);  // Note(C6, Duration(16th))
  PlayTone(  880,   14); wait1Msec( 150);  // Note(D6, Duration(16th))
  PlayTone(    0,   27); wait1Msec( 300);  // Note(Rest, Duration(Eighth))
  PlayTone( 1175,   14); wait1Msec( 150);  // Note(G6, Duration(16th))
  PlayTone( 1109,   14); wait1Msec( 150);  // Note(F#6, Duration(16th))
  PlayTone( 1047,   14); wait1Msec( 150);  // Note(F6, Duration(16th))
  PlayTone(  933,   14); wait1Msec( 150);  // Note(D#6, Duration(16th))
  PlayTone(    0,   14); wait1Msec( 150);  // Note(Rest, Duration(16th))
  PlayTone(  988,   14); wait1Msec( 150);  // Note(E6, Duration(16th))
  PlayTone(    0,   14); wait1Msec( 150);  // Note(Rest, Duration(16th))
  PlayTone( 1046,   14); wait1Msec( 150);  // Note(C7, Duration(16th))
  PlayTone(    0,   14); wait1Msec( 150);  // Note(Rest, Duration(16th))
  PlayTone( 1046,   14); wait1Msec( 150);  // Note(C7, Duration(16th))
  PlayTone( 1046,   14); wait1Msec( 150);  // Note(C7, Duration(16th))
  PlayTone(    0,   54); wait1Msec( 600);  // Note(Rest)
  PlayTone( 1175,   14); wait1Msec( 150);  // Note(G6, Duration(16th))
  PlayTone( 1109,   14); wait1Msec( 150);  // Note(F#6, Duration(16th))
  PlayTone( 1047,   14); wait1Msec( 150);  // Note(F6, Duration(16th))
  PlayTone(  933,   14); wait1Msec( 150);  // Note(D#6, Duration(16th))
  PlayTone(    0,   14); wait1Msec( 150);  // Note(Rest, Duration(16th))
  PlayTone(  988,   14); wait1Msec( 150);  // Note(E6, Duration(16th))
  PlayTone(    0,   14); wait1Msec( 150);  // Note(Rest, Duration(16th))
  PlayTone(  830,   14); wait1Msec( 150);  // Note(G#, Duration(16th))
  PlayTone(  880,   14); wait1Msec( 150);  // Note(A, Duration(16th))
  PlayTone(  784,   14); wait1Msec( 150);  // Note(C6, Duration(16th))
  PlayTone(    0,   14); wait1Msec( 150);  // Note(Rest, Duration(16th))
  PlayTone(  880,   14); wait1Msec( 150);  // Note(A, Duration(16th))
  PlayTone(  784,   14); wait1Msec( 150);  // Note(C6, Duration(16th))
  PlayTone(  880,   14); wait1Msec( 150);  // Note(D6, Duration(16th))
  PlayTone(    0,   27); wait1Msec( 300);  // Note(Rest, Duration(Eighth))
  PlayTone(  933,   14); wait1Msec( 150);  // Note(D#6, Duration(16th))
  PlayTone(    0,   27); wait1Msec( 300);  // Note(Rest, Duration(Eighth))
  PlayTone(  880,   14); wait1Msec( 150);  // Note(D6, Duration(16th))
  PlayTone(    0,   27); wait1Msec( 300);  // Note(Rest, Duration(Eighth))
  PlayTone(  784,   14); wait1Msec( 150);  // Note(C6, Duration(16th))
  return;
}



task main()
{
  StartTask(Mario);
  wait1Msec(1);
  int X;
  X=100;
  while(1==1)  //Loops whole program//
{
  int threshold= 18;                  /* Int 'threshold' will allow us to ignore low readings*/
  getJoystickSettings(joystick); //gets settings for whole program//

    ////////////Drive//Code////////////////////////
    if(abs(joystick.joy1_y2) > threshold)   // If the right analog stick's Y-axis readings are either above or below the threshold:
    {
      motor[motorD] = joystick.joy1_y2;         // Motor B is assigned a power level equal to the right analog stick's Y-axis reading.
    }
    else                                    // Else if the readings are within the threshold:
    {
      motor[motorD] = 0;                        // Motor B is stopped with a power level of 0.
    }


    if(abs(joystick.joy1_y1) > threshold)   // If the left analog stick's Y-axis readings are either above or below the threshold:
    {
      motor[motorE] = joystick.joy1_y1;         // Motor C is assigned a power level equal to the left analog stick's Y-axis reading.
    }
    else                                    // Else if the readings are within the threshold:
    {
      motor[motorE] = 0;                        // Motor C is stopped with a power level of 0.
    }

//////////////////////flippers/////////////////////////////////////
    if(joy1Btn(4)==1)
    {
        motor[motorA]=X;
        motor[motorB]=X;
    }
    if(joy1Btn(3)==1)                      //else/else works but you have to hold down button// if(joy1Btn(4)!=1);  // I switched to else instead of extra if
    {
        motor[motorA]=0;
        motor[motorB]=0;
    }


  //////////////////////Scissor Jack will be on D-pad//////////////
    if(joy1Btn(9) == 1)
    {
        motor[motorH]=100;
        motor[motorI]=100;
    }

    if(joy1Btn(10) == 1)
    {
        motor[motorH]=-100;
        motor[motorI]=-100;
    }
    if(joy1Btn(11) == 1)
    {
      motor[motorH]=0;
      motor[motorI]=0;
    }

//////////////////Sweeper////////////////////////
    if(joy1Btn(5)==1)
    {
        motor[motorF]=-100;
    }

    if(joy1Btn(7)==1)
    {
        motor[motorF]=0;
    }

////////////////Servo balldoor////////
    if(joy1Btn(6)==1)
    {
      servo[balldoor]=120;
    }
    if(joy1Btn(8)==1)
    {
      servo[balldoor]=130;
    }
/////////////////Servo lift///////////
    if(joy1Btn(1)==1)
    {
      servo[lift]=50;  // There are 2 servos but they are piggybacked so we dont need to worry about seperate ones//
    }
    if(joy1Btn(2)==1)
    {
      servo[lift]=100;
    }

}
}


Tue Feb 14, 2012 4:51 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 1 post ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.