diff --git a/MiniChallenge2/flash.c b/MiniChallenge2/flash.c index 90a80d4..3b9af0e 100644 --- a/MiniChallenge2/flash.c +++ b/MiniChallenge2/flash.c @@ -1,14 +1,13 @@ task blink() { - //int blinkState = true; - while(true) + while(true) //forever... { while(SensorValue(bumpSwitch) == true) //If you are holding the bump switch { - turnLEDOn(LEDOne); - delay(1000); //...do the code - turnLEDOff(LEDOne); - delay(1000); //more code + turnLEDOn(LEDOne); //turn on the LED + delay(1000); //wait.. + turnLEDOff(LEDOne); //turn it off + delay(1000); //this second wait is here, beacuse as it loops, there needs to be a delay between turning off and then turning back on } } } diff --git a/MiniChallenge2/motorInit.c b/MiniChallenge2/motorInit.c index 9dda0fe..35c847f 100644 --- a/MiniChallenge2/motorInit.c +++ b/MiniChallenge2/motorInit.c @@ -1,11 +1,12 @@ void motorInit() { - int rev = 1000; -//motor init - startMotor(starboardMotor, 80); + int rev = 1000; //this is the revolution duration variable, it exists only inside motorInit, + + //motor init + startMotor(starboardMotor, 80); //start both motors going forward at power 80 out of 127 pwm startMotor(portMotor, 80); delay(rev); //adjust me! 1 rev - stopMotor(starboardMotor); + stopMotor(starboardMotor); //stop both motors and wait two seconds stopMotor(portMotor); delay(2000); //delay for 2 seconds } diff --git a/MiniChallenge2/source.c b/MiniChallenge2/source.c index bb103e5..8fd50be 100644 --- a/MiniChallenge2/source.c +++ b/MiniChallenge2/source.c @@ -5,42 +5,41 @@ #pragma config(Motor, port3, portMotor, tmotorVex393_MC29, openLoop) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*// -#include "flash.c" -#include "motorInit.c" +#include "flash.c" //Include the blink task, that allows us to run a blink thread +#include "motorInit.c" //motorInit.c contains a motor init void, task driveTask() //Tasks need to be defined before the task main, as they will compile in order { - int trip = false; + int trip = false; //this trip value determines if the limit switch has been triggered, if true, the motor reverse drive will not run, this allows us to shut on and off the motors in a situation other than just the limit switch - startMotor(starboardMotor, -80); + startMotor(starboardMotor, -80); //these two commands start the motors moving in reverse startMotor(portMotor, -80); - while(trip == false) + while(trip == false) //for as long as we are not tripped off... { - if(SensorValue(limitSwitch) == 1) + if(SensorValue(limitSwitch) == 1) //...but if the limit switch is not pressed right now { - trip = true; + trip = true; //trip the motors off delay(20); } - else + else //otherwise { - delay(20); + delay(20); //dont trip the motors off } } stopMotor(starboardMotor); stopMotor(portMotor); //stop motors - stopTask(driveTask); + stopTask(driveTask); //stop the drivetask daemen, this will keep the motors from restarting } task main() { - //things to run once: - motorInit(); - startTask(driveTask, 10); - startTask(blink, 5); - while(true) + motorInit(); //init the motors with the startup sequence + startTask(driveTask, 10); //begin the drivetask daemen + startTask(blink, 5); //begin the blinking daemen + while(true) //do forever... { - delay(2000); //alotocate all time for task CPU + delay(2000); //alotocate all CPUT time for tasks } }