Skip to content
This repository has been archived by the owner on Jul 31, 2022. It is now read-only.

Housekeeping #6

Merged
merged 1 commit into from
Sep 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions MiniChallenge2/flash.c
Original file line number Diff line number Diff line change
@@ -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
}
}
}
9 changes: 5 additions & 4 deletions MiniChallenge2/motorInit.c
Original file line number Diff line number Diff line change
@@ -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
}
31 changes: 15 additions & 16 deletions MiniChallenge2/source.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}