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 TrapezoidControl QEI
Switch.cpp
00001 #include "Switch.h" 00002 00003 #include <stdint.h> 00004 #include "mbed.h" 00005 00006 namespace SWITCH { 00007 DigitalIn dipSw[] = { 00008 DigitalIn(DIP0_PIN), 00009 DigitalIn(DIP1_PIN), 00010 DigitalIn(DIP2_PIN), 00011 DigitalIn(DIP3_PIN), 00012 }; 00013 00014 DigitalIn limitSw(LS_PIN); 00015 00016 DigitalOut selectPin[] = { 00017 DigitalOut(SELECT0_PIN), 00018 DigitalOut(SELECT1_PIN), 00019 DigitalOut(SELECT2_PIN), 00020 DigitalOut(SELECT3_PIN), 00021 }; 00022 00023 void DipSw::Initialize() { 00024 for(uint8_t i=0; i < sizeof(dipSw)/sizeof(dipSw[0]); i++) { 00025 dipSw[i].mode(PullUp); 00026 } 00027 } 00028 00029 uint8_t DipSw::GetStatus() { 00030 if(DIP0 == SW_ON) return 0; 00031 else if(DIP1 == SW_ON) return 1; 00032 else if(DIP2 == SW_ON) return 2; 00033 else if(DIP3 == SW_ON) return 3; 00034 00035 return 0; 00036 } 00037 00038 void LimitSw::Initialize() { 00039 for(uint8_t i=0; i<4; i++) selectPin[i] = 0; 00040 limitSw.mode(PullUp); 00041 } 00042 00043 bool LimitSw::IsPressed(int index) { 00044 00045 MP_Channel ch; 00046 00047 switch(index){ 00048 case 0: 00049 ch.all = 8; 00050 break; 00051 case 1: 00052 ch.all = 9; 00053 break; 00054 case 2: 00055 ch.all = 10; 00056 break; 00057 case 3: 00058 ch.all = 11; 00059 break; 00060 case 4: 00061 ch.all = 7; 00062 break; 00063 case 5: 00064 ch.all = 4; 00065 break; 00066 case 6: 00067 ch.all = 2; 00068 break; 00069 case 7: 00070 ch.all = 0; 00071 break; 00072 case 8: 00073 ch.all = 6; 00074 break; 00075 case 9: 00076 ch.all = 5; 00077 break; 00078 case 10: 00079 ch.all = 3; 00080 break; 00081 case 11: 00082 ch.all = 1; 00083 break; 00084 case 12: 00085 ch.all = 12; 00086 break; 00087 case 13: 00088 ch.all = 13; 00089 break; 00090 case 14: 00091 ch.all = 14; 00092 break; 00093 case 15: 00094 ch.all = 15; 00095 break; 00096 } 00097 00098 00099 selectPin[0] = ch.s0; 00100 selectPin[1] = ch.s1; 00101 selectPin[2] = ch.s2; 00102 selectPin[3] = ch.s3; 00103 00104 wait_us(1); 00105 00106 return limitSw ? false : true; 00107 } 00108 }
Generated on Thu Aug 11 2022 13:16:31 by
