|
| 1 | +/* Copyright (c) 2024 FIRST. All rights reserved. |
| 2 | + * |
| 3 | + * Redistribution and use in source and binary forms, with or without modification, |
| 4 | + * are permitted (subject to the limitations in the disclaimer below) provided that |
| 5 | + * the following conditions are met: |
| 6 | + * |
| 7 | + * Redistributions of source code must retain the above copyright notice, this list |
| 8 | + * of conditions and the following disclaimer. |
| 9 | + * |
| 10 | + * Redistributions in binary form must reproduce the above copyright notice, this |
| 11 | + * list of conditions and the following disclaimer in the documentation and/or |
| 12 | + * other materials provided with the distribution. |
| 13 | + * |
| 14 | + * Neither the name of FIRST nor the names of its contributors may be used to endorse or |
| 15 | + * promote products derived from this software without specific prior written permission. |
| 16 | + * |
| 17 | + * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS |
| 18 | + * LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 20 | + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE |
| 22 | + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 23 | + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 24 | + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 25 | + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 26 | + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 27 | + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | + */ |
| 29 | + |
| 30 | +package org.firstinspires.ftc.robotcontroller.external.samples; |
| 31 | + |
| 32 | +import com.qualcomm.robotcore.eventloop.opmode.Disabled; |
| 33 | +import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode; |
| 34 | +import com.qualcomm.robotcore.eventloop.opmode.TeleOp; |
| 35 | +import com.qualcomm.robotcore.hardware.DigitalChannel; |
| 36 | + |
| 37 | +/* |
| 38 | + * This OpMode demonstrates how to use a digital channel. |
| 39 | + * |
| 40 | + * The OpMode assumes that the digital channel is configured with a name of "digitalTouch". |
| 41 | + * |
| 42 | + * Use Android Studio to Copy this Class, and Paste it into your team's code folder with a new name. |
| 43 | + * Remove or comment out the @Disabled line to add this OpMode to the Driver Station OpMode list. |
| 44 | + */ |
| 45 | +@TeleOp(name = "Sensor: digital channel", group = "Sensor") |
| 46 | +@Disabled |
| 47 | +public class SensorDigitalTouch extends LinearOpMode { |
| 48 | + DigitalChannel digitalTouch; // Digital channel Object |
| 49 | + |
| 50 | + @Override |
| 51 | + public void runOpMode() { |
| 52 | + |
| 53 | + // get a reference to our touchSensor object. |
| 54 | + digitalTouch = hardwareMap.get(DigitalChannel.class, "digitalTouch"); |
| 55 | + |
| 56 | + digitalTouch.setMode(DigitalChannel.Mode.INPUT); |
| 57 | + telemetry.addData("DigitalTouchSensorExample", "Press start to continue..."); |
| 58 | + telemetry.update(); |
| 59 | + |
| 60 | + // wait for the start button to be pressed. |
| 61 | + waitForStart(); |
| 62 | + |
| 63 | + // while the OpMode is active, loop and read the digital channel. |
| 64 | + // Note we use opModeIsActive() as our loop condition because it is an interruptible method. |
| 65 | + while (opModeIsActive()) { |
| 66 | + |
| 67 | + // button is pressed if value returned is LOW or false. |
| 68 | + // send the info back to driver station using telemetry function. |
| 69 | + if (digitalTouch.getState() == false) { |
| 70 | + telemetry.addData("Button", "PRESSED"); |
| 71 | + } else { |
| 72 | + telemetry.addData("Button", "NOT PRESSED"); |
| 73 | + } |
| 74 | + |
| 75 | + telemetry.update(); |
| 76 | + } |
| 77 | + } |
| 78 | +} |
0 commit comments