coding help

Hello. ive been trying to create a tank drive arm robot for a while. im on version 8.0 now and its a two motor drive train with one claw motor, one arm lift motor, two vex flashlights, and two aditional motors for the arm. however, i am trying to make it so there is also an indicator sensor led that will blink if the arm is up. to do this i thought i could use a code that links to a potentiometer, saying that if the potentiometer is above 50, the indicator will begin a blink cycle. however, when i did this, it formed multiple problems. if the drive motors were running when the potentiometer went above the selected level, the motors would run without any joystick control response. and if the motors were not running when the potentiometer went to the selected level, the drive would be locked at 0. furthermore, i was using a light sensor to opperate the flashlights as an almost “auto-headlight” system. however, the potentiometer would lock that out as well, as it did with the motors. could i get some help writing a code so that the indicator will flash if the potentiometer is above 50, as well as the lights turn on if the light sensor detects less than 700, without having any sensor interfere with the motors or responsiveness to the joystick controller? i have the file i was working on, the one that i keep having trouble with.

#pragma config(Sensor, in1, , sensorReflection)
#pragma config(Sensor, in2, , sensorPotentiometer)
#pragma config(Sensor, dgtl1, , sensorLEDtoVCC)
#pragma config(Motor, port2, , tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port3, , tmotorVex393_MC29, openLoop)
#pragma config(Motor, port4, , tmotorVexFlashlight, openLoop, reversed)
//!!Code automatically generated by ‘ROBOTC’ configuration wizard !!//

task main()
{
while(1==1)
{
motor[port2] = vexRT[Ch3]; // Left Joystick Y value
motor[port3] = vexRT[Ch2]; // Right Joystick Y value
{
if(SensorValue[in1] > 700)
motor[port4] = 127 ;

else
	motor[port4] = 0 ;
		{
		if(SensorValue[in2] > 500)
		{
			SensorValue[dgtl1] = 1;
		 wait1Msec(1000);
		 SensorValue[dgtl1] = 0;
		 wait1Msec(1000);
	}
}

}
}
}

additionally, i was hoping to convert the drive code to a single-joystick control such as this one:

#pragma config(Motor, port1, , tmotorVex393_HBridge, openLoop)
#pragma config(Motor, port2, , tmotorVex393_MC29, openLoop)
#pragma config(Motor, port10, , tmotorVex393_HBridge, openLoop, reversed)
//!!Code automatically generated by ‘ROBOTC’ configuration wizard !!//

task main()
{
while(1 == 1)
{
motor[port1] = (vexRT[Ch1] + vexRT[Ch2])/2; // (y + x)/2
motor[port10] = (vexRT[Ch1] - vexRT[Ch2])/2; // (y - x)/2
}

}

Hi. @LauranceDarkez
the cause of your problem is the wait statement, this pauses all your code including you drive and flashlight functions. one of the solutions for this is to have a separate task for flashing, and enable it when the arm is above a certain point.


#pragma config(Sensor, in1, , sensorReflection)
#pragma config(Sensor, in2, , sensorPotentiometer)
#pragma config(Sensor, dgtl1, , sensorLEDtoVCC)
#pragma config(Motor, port2, , tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port3, , tmotorVex393_MC29, openLoop)
#pragma config(Motor, port4, , tmotorVexFlashlight, openLoop, reversed)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//


bool flash;
task flash_loop()
{
	while(flash == true)
	{
	SensorValue[dgtl1] = 1;
	wait1Msec(1000);
	SensorValue[dgtl1] = 0;
	wait1Msec(1000);
	}
}


task main()
{
	startTask(flash_loop);
	while(1==1)
	{
		motor[port2] = vexRT[Ch3]; // Left Joystick Y value
		motor[port3] = vexRT[Ch2]; // Right Joystick Y value
		//motor[port2] = (vexRT[Ch1] + vexRT[Ch2])/2; // (y + x)/2
		//motor[port3] = (vexRT[Ch1] - vexRT[Ch2])/2; // (y - x)/2
		
		if(SensorValue[in1] > 700)
		{
			motor[port4] = 127;
		}
		else
		{
			motor[port4] = 0 ;
		}
		if(SensorValue[in2] > 500)
		{
			flash = true;
		}
		else
		{
			flash = false;
		}
	}
}

thank you. ill test that out

the potentiometer wont activate the system of the led. but at least the potentiometer isnt effecting the motors

i figured out a way to make it work. but i have a question. is there a way to set the light sensor make the lights brighter as the room gets darker? or would i have to set different levels of headlight strenght to different levels of light sensor?

look at a simple PID loop for motor control. the same principle should work for you.

Assuming you can control the headlight strength, you could simply multiply the light sensor reading by a predetermined (negative) coefficient.

E.g.
Headlight strength: 0-127
Light sensor input: 0-1024 (1000 being lightest and 0 being darkest)
Constant Coefficient: 0.124
Headlight = light sensor input * -1 * constant coefficient

Make sure you have no syntax errors. Those can be annoying to find sometimes.