Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of circle_war_ver_A_NUCLEO_ by
Diff: encoder.cpp
- Revision:
- 5:df89be97e11a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/encoder.cpp Fri Apr 01 05:52:10 2016 +0000
@@ -0,0 +1,144 @@
+#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++;
+ }
