新部内対抗A班 / Mbed 2 deprecated circle_war_ver_A_NUCLEO__

Dependencies:   mbed

Fork of circle_war_ver_A_NUCLEO_ by 新部内対抗A班

encoder.cpp

Committer:
username16248
Date:
2016-04-01
Revision:
5:df89be97e11a

File content as of revision 5:df89be97e11a:

#include "mbed.h"
#include <pin_file.h>
#include <encoder.h>
InterruptIn b(EC1_b);//前部
InterruptIn a(EC1_a);
InterruptIn d(EC2_b);//右部
InterruptIn c(EC2_a);
InterruptIn e(EC3_a);//左部
InterruptIn f(EC3_b);

int count_f=0,count_r=0,count_l=0;
int pa,pb,pC,pd,pe,pf;
//int s=0;

//interrupt
void risea()
{
    pa=1;
    if(pb==0) {
        count_f++;
    } else {
        count_f--;
    }
}
void falla()
{
    pa=0;
    if(pb==0) {
        count_f--;
    } else {
        count_f++;
    }
}
void riseb()
{
    pb=1;
    if(pa==0) {
        count_f--;
    } else {
        count_f++;
    }
}
void fallb()
{
    pb=0;
    if(pa==0) {
        count_f++;
    } else {
        count_f--;
    }
}


void risec()
{
    pC=1;
    if(pd==0) {
        count_r++;
    } else {
        count_r--;
    }
}
void fallc()
{
    pC=0;
    if(pd==0) {
        count_r--;
    } else {
        count_r++;
    }
}
void rised()
{
    pd=1;
    if(pC==0) {
        count_r--;
    } else {
        count_r++;
    }
}
void falld()
{
    pd=0;
    if(pC==0) {
        count_r++;
    } else {
        count_r--;
    }
}


void risee()
{
    pe=1;
    if(pf==0) {
        count_l++;
    } else {
        count_l--;
    }
}
void falle()
{
    pe=0;
    if(pf==0) {
        count_l--;
    } else {
        count_l++;
    }
}
void risef()
{
    pf=1;
    if(pe==0) {
        count_l--;
    } else {
        count_l++;
    }
}
void fallf()
{
    pf=0;
    if(pe==0) {
        count_l++;
    } else {
        count_l--;
    }
}

void encoder_setting(){
    //interrupt
    a.rise(&risea);
    a.fall(&falla);
    b.rise(&riseb);
    b.fall(&fallb);
    c.rise(&risec);
    c.fall(&fallc);
    d.rise(&rised);
    d.fall(&falld);
    e.rise(&risee);
    e.fall(&falle);
    f.rise(&risef);
    f.fall(&fallf);
    //s++;
    }