EV3 Touch Sensor / how to check if it's pressed

This is where you talk about the EV3 software itself, installation issues, and programming talk.

Moderators: roger, gloomyandy, skoehler

EV3 Touch Sensor / how to check if it's pressed

Postby aspire4higher » Wed Jul 16, 2014 10:47 pm

I'm trying to figure out how I would go about checking to see if an ev3 touch sensor is pressed.

What would the methods look like? I am going to be programming it in such a way ....
--------------------------------------------------------------------------------------------------------------------------------

import lejos.hardware.lcd.LCD;
import lejos.hardware.motor.EV3LargeRegulatedMotor;
import lejos.hardware.port.AnalogPort;
import lejos.hardware.port.MotorPort;
import lejos.hardware.sensor.EV3TouchSensor;
import lejos.robotics.RegulatedMotor;
import lejos.utility.Delay;


public class Calibrator {

AnalogPort s4;


void calibrate() {

RegulatedMotor xMotor = new EV3LargeRegulatedMotor(MotorPort.A);
EV3TouchSensor t = new EV3TouchSensor(s4);


LCD.drawString("Calibrating", 4, 4);
xMotor.setAcceleration(20);

// Need some code that makes it so that if touch sensor is pressed, stop xMotor. Otherwise, if button is not pressed, xMotor goes backward




LCD.drawString("Done Calibrating", 0, 4);
Delay.msDelay(3000);





xMotor.close();
t.close();
}


}
aspire4higher
New User
 
Posts: 8
Joined: Wed Jun 25, 2014 6:20 pm

Re: EV3 Touch Sensor / how to check if it's pressed

Postby gloomyandy » Thu Jul 17, 2014 8:14 am

You probably need to spend a bit of time exploring the way that leJOS handles EV3 sensors. Take a look at the following:
https://sourceforge.net/p/lejos/wiki/Se ... Framework/

Then write a small program to test how this works when using a touch sensor. Print out the values returned by fetchSample for the touch sensor, when it is pressed and when not. Once you see this I'm sure you will be able to work out how to detect that the sensor has been pressed.

Andy
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4004
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK


Return to EV3 Software

Who is online

Users browsing this forum: No registered users and 2 guests

more stuff