Can someone revise my code

i am having problems with the push button not working along with other things really not working verry well with the code can someone rewrite it for me and just kinda explain what you changed so i can learn for next time
thanks!

#pragma config(Sensor, dgtl1, au, sensorTouch)
#pragma config(Sensor, dgtl2, ad, sensorTouch)
#pragma config(Sensor, dgtl7, solenoid, sensorDigitalOut)
#pragma config(Motor, port1, lift, tmotorVex393_HBridge, openLoop)
#pragma config(Motor, port2, a1, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port3, a2, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port4, a3, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port5, a4, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port6, d1, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port7, d2, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port8, d3, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port9, d4, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port10, hd, tmotorVex393_HBridge, openLoop)
//!!Code automatically generated by ‘ROBOTC’ configuration wizard !!//

#pragma platform(VEX)

//Competition Control and Duration Settings
#pragma competitionControl(Competition)
#pragma autonomousDuration(20)
#pragma userControlDuration(120)

#include “Vex_Competition_Includes.c” //Main competition background code…do not modify!

// You may want to perform some actions before the competition starts. Do them in the
// following function.

void pre_auton()
{
// Set bStopTasksBetweenModes to false if you want to keep user created tasks running between
// Autonomous and Tele-Op modes. You will need to manage all user created tasks if set to false.
bStopTasksBetweenModes = true;

// All activities that occur before the competition starts
// Example: clearing encoders, setting servo positions, …
}

task autonomous()
{
// …
// Insert user code here.
// …

AutonomousCodePlaceholderForTesting(); // Remove this function call once you have “real” code.
}

task usercontrol()
{
while (true)
{
motor[d1] = vexRT[Ch2];
motor[d3] = vexRT[Ch2];

motor[d2] = vexRT[Ch3];
motor[d4] = vexRT[Ch3];

motor[a1] = (vexRT[Btn5U] - vexRT[Btn5D]) * 127;
motor[a2] = (vexRT[Btn5U] - vexRT[Btn5D]) * 127;
motor[a3] = (vexRT[Btn5U] - vexRT[Btn5D]) * 127;
motor[a4] = (vexRT[Btn5U] - vexRT[Btn5D]) * 127;

while(SensorValue(au) == 1) // Loop while robot's upper sensor is pressed in(add in pneumatic pistons when we get some)
{
 SensorValue[solenoid] = 1;
 sleep(50);
 motor[a1] = 0;
 motor[a2] = 0;
 motor[a3] = 0;
 motor[a4] = 0;
 
{
if(vexRT[Btn8D] == 1)         // If button 6U (upper right shoulder button) is pressed:
{
  SensorValue[solenoid] = 1;  // ...activate the solenoid.
}
else                          // If button 6U (upper right shoulder button) is  NOT pressed:
{
  SensorValue[solenoid] = 0;  // ..deactivate the solenoid.
}

}
}
}
}

In the future, please post your code in the code tags to make it easier for us to read it.


Code Tag Example

What do you mean by other things not working very well?

think I found it
while(SensorValue(au) == 1) // Loop while robot’s upper sensor is pressed in(add in pneumatic pistons when we get some) // I’m not sure you want a while loop here, because it will execute over and over and prevent your robot from obeying anything in the outside loop
{
SensorValue[solenoid] = 1;
sleep(50);
motor[a1] = 0;
motor[a2] = 0;
motor[a3] = 0;
motor[a4] = 0;

{ // don’t see definition for this bracket, seems like something is missing here
if(vexRT[Btn8D] == 1) // If button 6U (upper right shoulder button) is pressed:
{
SensorValue[solenoid] = 1; // …activate the solenoid.
}
else // If button 6U (upper right shoulder button) is NOT pressed:
{
SensorValue[solenoid] = 0; // …deactivate the solenoid.
}
}
}

The formatting was just killing me


#pragma config(Sensor, dgtl1, au, sensorTouch)
#pragma config(Sensor, dgtl2, ad, sensorTouch)
#pragma config(Sensor, dgtl7, solenoid, sensorDigitalOut)
#pragma config(Motor, port1, lift, tmotorVex393_HBridge, openLoop)
#pragma config(Motor, port2, a1, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port3, a2, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port4, a3, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port5, a4, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port6, d1, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port7, d2, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port8, d3, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port9, d4, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port10, hd, tmotorVex393_HBridge, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

#pragma platform(VEX)

//Competition Control and Duration Settings
#pragma competitionControl(Competition)
#pragma autonomousDuration(20)
#pragma userControlDuration(120)

#include "Vex_Competition_Includes.c" //Main competition background code...do  not modify!

// You may want to perform some actions before the competition starts. Do them in the
// following function.

void pre_auton()
{
	// Set bStopTasksBetweenModes to false if you want to keep user created tasks running between
	// Autonomous and Tele-Op modes. You will need to manage all user created tasks if set to false.
	bStopTasksBetweenModes = true;

	// All activities that occur before the competition starts
	// Example: clearing encoders, setting servo positions, ...
}

task autonomous()
{
	// .....................................................................................
	// Insert user code here.
	// .....................................................................................

	AutonomousCodePlaceholderForTesting(); // Remove this function call once you have "real" code.
}

task usercontrol()
{
	while (true)
	{
		motor[d1] = vexRT[Ch2];
		motor[d3] = vexRT[Ch2];

		motor[d2] = vexRT[Ch3];
		motor[d4] = vexRT[Ch3];

		motor[a1] = (vexRT[Btn5U] - vexRT[Btn5D]) * 127;
		motor[a2] = (vexRT[Btn5U] - vexRT[Btn5D]) * 127;
		motor[a3] = (vexRT[Btn5U] - vexRT[Btn5D]) * 127;
		motor[a4] = (vexRT[Btn5U] - vexRT[Btn5D]) * 127;

		while(SensorValue(au) == 1) // Loop while robot's upper sensor is pressed in(add in pneumatic pistons when we get some)
		{
			SensorValue[solenoid] = 1;
			sleep(50);
			motor[a1] = 0;
			motor[a2] = 0;
			motor[a3] = 0;
			motor[a4] = 0;

			{
				if(vexRT[Btn8D] == 1) // If button 6U (upper right shoulder button) is pressed:
				{
					SensorValue[solenoid] = 1; // ...activate the solenoid.
				}
				else // If button 6U (upper right shoulder button) is NOT pressed:
				{
					SensorValue[solenoid] = 0; // ..deactivate the solenoid.
				}
			}
		}
	}
}

the button is not stopping the motors when the arm is at the top and it is also not activating the pistons when it hits that button

Video (contains adult words):

#pragma config(Sensor, dgtl1, au, sensorTouch)
#pragma config(Sensor, dgtl2, ad, sensorTouch)
#pragma config(Sensor, dgtl7, solenoid, sensorDigitalOut)
#pragma config(Motor, port1, lift, tmotorVex393_HBridge, openLoop)
#pragma config(Motor, port2, a1, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port3, a2, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port4, a3, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port5, a4, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port6, d1, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port7, d2, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port8, d3, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port9, d4, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port10, hd, tmotorVex393_HBridge, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

#pragma platform(VEX)

//Competition Control and Duration Settings
#pragma competitionControl(Competition)
#pragma autonomousDuration(20)
#pragma userControlDuration(120)

#include "Vex_Competition_Includes.c"

void pre_auton() {

	// Set bStopTasksBetweenModes to false if you want to keep user created tasks running between
	// Autonomous and Tele-Op modes.
	bStopTasksBetweenModes = true;

}

task autonomous() {

	// TODO: Insert user code here.

	// Remove this function call once you have "real" code.
	AutonomousCodePlaceholderForTesting(); 
}

task usercontrol() {

	while(true) {

		// Set drive motors
		setMultipleMotors(vexRT[Ch2], d1, d3);
		setMultipleMotors(vexRT[Ch3], d2, d4);

		// Loop while robot's upper sensor is pressed in (add in pneumatic pistons when we get some)
		if(SensorValue(au)) {

			SensorValue[solenoid] = 1;

			// Stop all motors
			setMultipleMotors(0, a1, a2, a3, a4);

			// If button 6U (upper right shoulder button) is pressed, active solenoid
			//SensorValue[solenoid] = vexRT[Btn8D];

		} else {

			// If B5U is pressed, motors gets set to full forward speed
			// If B5D is pressed, motors get set to full backward speed
			setMultipleMotors((vexRT[Btn5U] - vexRT[Btn5D]) * 127, a1, a2, a3, a4);

		}

		sleep(20);

	}

}

the pneumatics do not work still but everything else works great

i had to change the code a little ill repost it


#pragma config(Sensor, dgtl1,  au,             sensorTouch)
#pragma config(Sensor, dgtl2,  ad,             sensorTouch)
#pragma config(Sensor, dgtl7,  solenoid,       sensorDigitalOut)
#pragma config(Motor,  port2,           a1,            tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor,  port3,           a2,            tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor,  port4,           a3,            tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor,  port5,           a4,            tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port6,           a5,            tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port7,           a6,            tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port8,           d1,            tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor,  port9,           d2,            tmotorVex393_MC29, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#pragma platform(VEX)

//Competition Control and Duration Settings
#pragma competitionControl(Competition)
#pragma autonomousDuration(20)
#pragma userControlDuration(120)

#include "Vex_Competition_Includes.c"

void pre_auton() {

	// Set bStopTasksBetweenModes to false if you want to keep user created tasks running between
	// Autonomous and Tele-Op modes.
	bStopTasksBetweenModes = true;

}

task autonomous() {

	// TODO: Insert user code here.

	// Remove this function call once you have "real" code.
	AutonomousCodePlaceholderForTesting(); 
}

task usercontrol() {

	while(true) {

		// Set drive motors
		setMultipleMotors(vexRT[Ch2], d1);
		setMultipleMotors(vexRT[Ch3], d2);

		// Loop while robot's upper sensor is pressed in (add in pneumatic pistons when we get some)
		if(SensorValue(au)) {

			SensorValue[solenoid] = 1;

			// Stop all motors
			setMultipleMotors(0, a1, a2, a3, a4,);
			setMultipleMotors(0, a5, a6,);

			// If button 6U (upper right shoulder button) is pressed, active solenoid
			//SensorValue[solenoid] = vexRT[Btn8D];

		} else {

			// If B5U is pressed, motors gets set to full forward speed
			// If B5D is pressed, motors get set to full backward speed
			setMultipleMotors((vexRT[Btn5U] - vexRT[Btn5D]) * 127, a1, a2, a3, a4,);
      setMultipleMotors((vexRT[Btn5U] - vexRT[Btn5D]) * 127, a5, a6,);
		}

		sleep(20);

	}

}

This is the part where you put some effort in and figure it out.

Is the value firing?
Is it plugged into the correct I/O port?
Is it plugged in the right way?
Is there air in the system?
Are you calling the right function to fire it?
Is your code in that area getting triggered at all (hint use a print statement)?
Is the button in the right I/O port?
Do the motors stop?

I will double check with a different solenoid when i get to school but all the other things i tried