Coding Buttons- I just can't figure it out

Well I got the rest of my code working per my post earlier but now I’m trying to add in a solenoid to be in one state while the button is pressed and return to the other when released. How would one do this using the logitech joystick and the trigger button? I’ve tried all the things online but always have one error or another

Edit-- Using Java for code

What language are you using.
Also do you know about this:

using java (should have mentioned that). I have been looking around on that site and am just kinda lost. Our original head programmer graduated last year and we swapped to vex so our new coder didn’t bother learning the FRC stuff.

Which Template are you guys using? Command-Based, TimedRobot, or another one?

What have you tried already? Could you post your code?

This is what i have so far the button code at the bottom was my most recent try

/* Copyright (c) 2017-2018 FIRST. All Rights Reserved.                        */
/* Open Source Software - may be modified and shared by FRC teams. The code   */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project.                                                               */

package frc.robot;

import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.TimedRobot;
//import edu.wpi.first.wpilibj.hal.FRCNetComm.tResourceType;
//import edu.wpi.first.wpilibj.hal.HAL;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.CameraServer;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.Solenoid;
import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj.Spark;
import edu.wpi.first.wpilibj.buttons.JoystickButton;

 * This is a demo program showing how to use Mecanum control with the RobotDrive
 * class.
public class Robot extends TimedRobot {
  private static final int kFrontLeftChannel = 2;
  private static final int kRearLeftChannel = 3;
  private static final int kFrontRightChannel = 1;
  private static final int kRearRightChannel = 0;

  private static final int kJoystickChannel = 0;

  private MecanumDrive m_robotDrive;
  private Joystick m_stick;

  public void robotInit() {
    var m_frontLeft = new Spark(0);	
    var m_rearLeft = new Spark(1);
	var m_frontRight = new Spark(14);	
	var m_rearRight = new Spark(15);

    // Invert the left side motors.
    // You may need to change or remove this to match your robot.

    var m_robotDrive = new MecanumDrive(m_frontLeft, m_rearLeft, m_frontRight, m_rearRight);

    var m_stick = new Joystick(kJoystickChannel);

  JoystickButton button1 = new JoystickButton(m_stick, 1);




  public void teleopPeriodic() {
    // Use the joystick X axis for lateral movement, Y axis for forward
    // movement, and Z axis for rotation.
    m_robotDrive.driveCartesian(m_stick.getX(), m_stick.getY(),
        m_stick.getZ(), 0.0);

        DoubleSolenoid launchersolenoid = new DoubleSolenoid(1, 2);





as for the template I started with the meccanum example and change out motor controllers

You need to have your if statements inside a method (probably teleopPeriodic() in this instance)

ok I’ll try that

your syntax for the if statement is also incorrect.
you probably just want

Thanks I just fixed that too and it worked correctly thanks.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.