a
Dependents: 3servotest 1stcomp 3rdcompfixstart 2ndcomp ... more
Fork of button by
button.cpp
00001 00002 #include "button.h" 00003 00004 DigitalIn start_button(USER_BUTTON); 00005 DigitalIn makihara_button(PD_2); 00006 DigitalOut beep(PB_10); 00007 00008 DigitalIn phase1(PA_5); 00009 DigitalIn phase2(PA_6); 00010 DigitalIn phase4(PA_7); 00011 DigitalIn phase8(PB_12); 00012 00013 DigitalIn teamSW(PC_11); 00014 DigitalOut teamledblue(PC_10); 00015 DigitalOut teamledred(PC_12); 00016 00017 00018 00019 int phaseSW(void){ 00020 phase1.mode(PullUp); 00021 phase2.mode(PullUp); 00022 phase4.mode(PullUp); 00023 phase8.mode(PullUp); 00024 00025 int SW=phase1+2*phase2+4*phase4+8*phase8; 00026 00027 return SW; 00028 } 00029 00030 00031 int teamLED() 00032 { 00033 teamSW.mode(PullUp); 00034 if(teamSW) { 00035 teamledblue=1; 00036 teamledred=0; 00037 return -1; 00038 } else { 00039 teamledblue=0; 00040 teamledred=1; 00041 return 1; 00042 } 00043 } 00044 00045 void buzzer(bool on) 00046 { 00047 if(on) 00048 beep = 1; 00049 else 00050 beep = 0; 00051 } 00052 00053 bool start() 00054 { 00055 if(start_button) 00056 return true; 00057 else 00058 return false; 00059 } 00060 00061 void commandIn(int command[3]) 00062 { 00063 00064 makihara_button.mode(PullUp); 00065 while(!makihara_button); 00066 for(int i=0; i < 3; ++i) { 00067 while(makihara_button); 00068 wait_ms(10); 00069 buzzer(1); 00070 while(!makihara_button); 00071 wait_ms(10); 00072 buzzer(0); 00073 command[i] = get_phase(); 00074 // (*colors[i])(1); 00075 } 00076 } 00077 00078 void initbutton() 00079 { 00080 makihara_button.mode(PullUp); 00081 phase1.mode(PullUp); 00082 phase2.mode(PullUp); 00083 phase4.mode(PullUp); 00084 phase8.mode(PullUp); 00085 } 00086 00087 00088 int get_phase() 00089 { 00090 return phase1 + phase2*2 + phase4*4 + phase8*8; 00091 }
Generated on Thu Jul 14 2022 14:52:30 by
1.7.2
