Skip to content

Instantly share code, notes, and snippets.

@mattneary
Last active December 18, 2015 02:58
Show Gist options
  • Save mattneary/5714407 to your computer and use it in GitHub Desktop.
Save mattneary/5714407 to your computer and use it in GitHub Desktop.
#pragma config(Motor, motorA, leftMotor, tmotorNXT, PIDControl, encoder)
#pragma config(Motor, motorB, rightMotor, tmotorNXT, PIDControl, encoder)
#pragma config(Sensor, S4, colorSensor, sensorCOLORFULL)
#include "Simple Car Header.c"
/*
___________________________________
| |
| /========================\ |
| | AUTOMATED PERIOD DIAGRAM | |
| \========================/ |
| |
| | | |
| | If | |
| | Plate | |
| | is | |
| | Green | |
| | | |
| ____________| _____ |____________ |
| / \ |
| If Plate | RGB | If Plate |
| is Red | Plate | is Blue |
| ____________ \_____/ ____________ |
| | | |
| | | |
| | | |
| | | |
| | WHITE | |
| | | |
| | ___ | |
| | |CAR| | |
| | |___| | |
|___________________________________|
*/
//Global variables
int velocity = 50;
int pause = 1000;
char* red = "RED";
char* green = "GREEN";
char* blue = "BLUE";
//Instance-Specific Functions
int motorsForwardUntilChange(){
int val;
while(!(strcmp(ROBOgetColor, "RED") || strcmp(ROBOgetColor, "GREEN") || strcmp(ROBOgetColor, "BLUE"))){
ROBOforward(velocity);
}
if (strcmp(ROBOgetColor, "RED"))
val = 1;
else if (strcmp(ROBOgetColor, "BLUE"))
val = 2;
else
val = 3;
wait1Msec(500);
ROBOstop();
wait1Msec(pause);
return val;
}
void motorsForwardToEnd(){
ROBOforward(velocity);
wait1Msec(5000);
ROBOstop();
wait1Msec(pause);
}
//Actual Autonomous-Period Actions
void autonomous(){
int val = motorsForwardUntilChange();
if(val == 1)
ROBOleft(velocity);
else if(val == 2)
ROBOright(velocity);
wait1Msec(1000);
motorsForwardUntilChange();
}
//Starting Point of the program
task main(){
autonomous();
}
#pragma config(Motor, motorA, leftMotor, tmotorNXT, PIDControl, encoder)
#pragma config(Motor, motorB, rightMotor, tmotorNXT, PIDControl, encoder)
#pragma config(Sensor, S1, touchSensor, sensorTouch)
#include "JoystickDriver.c"
#define THRESHOLD 0
float speed = 1.0;
float leftMotor(joy1, joy2) {
return joy1 * speed;
}
float rightMotor(joy1, joy2) {
return joy2 * speed;
}
task main(){
long count = 0;
while(true) {
getJoystickSettings(joystick);
motor[motor1] = leftMotor(joystick.joy1_y1*100/127, joystick.joy1_y2*100/127);
motor[motor2] = rightMotor(joystick.joy1_y1*100/127, joystick.joy1_y2*100/127);
int touch = SensorValue[touchSensor];
if(count <= 50000) {
if(count == 30000){
PlaySound(soundUpwardTones);
speed = 1;
}
count++;
} else if(touch == 1) {
PlaySound(soundDownwardTones);
speed *= .37;
count = 0;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment