EV3TouchSensor - How does it work?

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

Moderators: roger, gloomyandy, skoehler

EV3TouchSensor - How does it work?

Postby leJosNeedHelp » Mon Jan 27, 2014 8:32 am

Hi Comm,

I'm pretty sure you'll think something like "uhm, just another newbie who can't use the search function!" but I used it, and i didnt find a post, which helps me :cry:
I found code for the TouchSensor too, but I read something about an SampleProvider interface and now the .isPressed() methode doesnt work anymore ... :-D
I tried to collect some informations about interfaces and it seems to me, they are almost the same like abstract classes, expect fot the fact, interfaces supports inherit from multiple classes.
I found a post too, that's almost what i'm looking for: viewtopic.php?f=18&t=5300
But when i try to implement the code:

Code: Select all
package com.roboter.dev;
import lejos.hardware.sensor.*;
import lejos.hardware.port.*;


public class EV3FirstProgram {
   public static void main(String[] args) throws InterruptedException {

           sampleProvider touch = new EV3TouchSensor(SensorPort.S2);
      float[] sample = new float[touch.sampleSize()];
      while(true) {
        touch.fetchSample(sample, 0);
        if (sample(0) == 1) {
         LCD.clear();
                   LCD.drawString("Test",0,0);
        }
      }
   

   }
}


i got the following errors:

Multiple markers at this line
- Line breakpoint:EV3FirstProgram [line: 34] -
main(String[])
- sampleProvider cannot be resolved to a type

and

The method sample(int) is undefined for the type EV3FirstProgram.

I installed only the class "ev3classes" (and DBusJava, because there was an error whitout including them), because I read that I dont need the other classes, like : EV3SensorMonitor, EV3Splash, kernel and so on. Do I need other classes for the Sensors?

I just want to count how often the Touchsensor at Port 1 is pressed, but I dont get it ...
Maybe there are any "tutorials" or something like this?

I would be very happy if somebody can help me :-)

Greetz from Germany :wink:
leJosNeedHelp
New User
 
Posts: 18
Joined: Tue Sep 24, 2013 7:33 am

Re: EV3TouchSensor - How does it work?

Postby gloomyandy » Mon Jan 27, 2014 12:51 pm

You need SampleProvider not sampleProvider. In general class names start with a capital letter in leJOS.
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3881
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: EV3TouchSensor - How does it work?

Postby leJosNeedHelp » Tue Jan 28, 2014 8:11 am

Problem fixed, Thank you!

My Code:
Code: Select all
import lejos.hardware.sensor.*;
import lejos.hardware.lcd.LCD;
import lejos.hardware.port.*;
import lejos.robotics.SampleProvider;


public class EV3FirstProgram {
   public static void main(String[] args) throws InterruptedException {

      SampleProvider touch = new EV3TouchSensor(SensorPort.S1);
      float[] sample = new float[touch.sampleSize()];
      while(true) {
        touch.fetchSample(sample, 0);
        if (sample[0] == 1) {
           LCD.drawString("Test",0,0);
        }
      }
   }
}


Maybe it'll help somebody:-)
leJosNeedHelp
New User
 
Posts: 18
Joined: Tue Sep 24, 2013 7:33 am


Return to EV3 Software

Who is online

Users browsing this forum: No registered users and 1 guest

more stuff