Package com.grt192.sensor

Source Code of com.grt192.sensor.GRTSingleChannelEncoder

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package com.grt192.sensor;

import com.grt192.core.Sensor;
import com.grt192.event.component.EncoderEvent;
import com.grt192.event.component.EncoderListener;
import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.Encoder;
import java.util.Vector;

/**
*
* @author grtstudent, code for an Encoder with one channel.
*/
public class GRTSingleChannelEncoder extends Sensor{
    private DigitalInput rotaryEncoder;
    private Vector encoderListeners;
    public static final double DIST_PER_PULSE = Math.PI * 16/(360 * 4 *12);
    private boolean previousValue;
    private int count = 0;
        public GRTSingleChannelEncoder(int channela, int pollTime, String id){
        rotaryEncoder = new DigitalInput(channela);
        setSleepTime(pollTime);
        encoderListeners = new Vector();
        this.id = id;
    }

    public void poll() {
        boolean currentValue = rotaryEncoder.get();
        System.out.println("Switch: " + currentValue);
        if (currentValue != previousValue){
            count++;
            System.out.println("Added count");
        }
        setState("Count", count);
        previousValue = currentValue;
    }


}
TOP

Related Classes of com.grt192.sensor.GRTSingleChannelEncoder

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.