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.
Fork of hapticFeedback by
hapticFeedback.cpp
00001 //11/13/12 MM Made fix to haptic error where exo would freak out when it was in the sitting position and you commanded it to stand up 00002 #include "mbed.h" 00003 #include "HipControl.h" 00004 #include "hapticFeedback.h" 00005 00006 // arpeggio down (A E C# A) = f(880 659 554 440) = T(.0011363 .00151745 .00180505 .0022727) 00007 // doogie howser MD theme (A(high) A(high) A(Low) A(low) A(high) D#) = f(880 880 440 440 880 622) = T(.0011363 .0011363 .0022727 .0022727 .0011363 .0016077) 00008 00009 const float arpeggio[] = {.0011363, .00151745, .00180505, .0022727}; 00010 const float arpeggio_t[] = {.1, .1, .1, .1}; 00011 const float DH[] = {.0011363, .00005, .0011363, .00005, .0022727, .00005, .0022727, .00005, .0011363, .00005, .0016077}; // doogie howser periods 00012 const float DH_t[] = {.1, .05, .1, .05, .1, .05, .1, .05, .1, .05, .1}; 00013 const float IronMan[] = {0.0010124,0.0008513,0.00005,0.0008513,0.00005,0.0007584,0.00005,0.0007584,0.0006378,0.0006757,0.0006378,0.0006757,0.0006378,0.0006757,0.0008513,0.000050,0.0008513,0.000050,.0007584,0.00005,0.0007584}; 00014 const float IronMan_t[] = {.8,.5,.3,.3,.1,.3,.1,.4,.2,.2,.2,.2,.2,.2,.3,.1,.3,.1,.3,.1,.3}; 00015 const float lockSound[] = {.0011363,.0022727}; 00016 const float lockSound_t[] = {.3, .3}; 00017 const float unlockSound[] = {.0022727,.0011363}; 00018 const float unlockSound_t[] = {.2, .2}; 00019 const float LowBatterySound[] = {.00151745,.00151745}; 00020 const float LowBatterySound_t[] = {.1,.1}; 00021 const short unsigned int IronMan_count=(sizeof(IronMan)/sizeof(IronMan[0]))-1; 00022 const short unsigned int arpeggio_count=(sizeof(arpeggio)/sizeof(arpeggio[0]))-1; 00023 const short unsigned int DH_count=(sizeof(DH)/sizeof(DH[0]))-1; 00024 const short unsigned int lockSound_count=(sizeof(lockSound)/sizeof(lockSound[0]))-1; 00025 const short unsigned int unlockSound_count=(sizeof(unlockSound)/sizeof(unlockSound[0]))-1; 00026 00027 00028 bool hapticOn = false; 00029 int buzzMode; 00030 00031 MotorMusic::MotorMusic(HipControl& left, HipControl& right):pwmDefault(0.00005),count(0),count_max(0),_left(left),_right(right) 00032 { 00033 time.start(); 00034 } 00035 void MotorMusic::setDefault(float a) 00036 { 00037 pwmDefault=a; 00038 } 00039 void MotorMusic::check() 00040 { 00041 if (musicFlag==1) { 00042 song(); 00043 } 00044 } 00045 void MotorMusic::init() 00046 { 00047 _left.pwmPeriod(ptrNotes[count]); //play first note 00048 _right.pwmPeriod(ptrNotes[count]); //play first note 00049 } 00050 void MotorMusic::song() 00051 { 00052 if(time.read()>=ptrTimes[count]) { //change note if the time to play the previous note is over 00053 count++; //change note counter 00054 time.reset(); //reset and start timer 00055 _left.pwmPeriod(ptrNotes[count]); //increment note 00056 _right.pwmPeriod(ptrNotes[count]); //increment note 00057 } 00058 if(count>count_max) { 00059 _left.pwmPeriod(pwmDefault); //increment note 00060 _right.pwmPeriod(pwmDefault); //increment note 00061 count=0; //counter to change notes 00062 musicFlag=0; //flag to signal playing music 00063 } 00064 } 00065 00066 00067 void MotorMusic::playIronMan() 00068 { 00069 ptrNotes=IronMan; //point to the Iron Man notes array 00070 ptrTimes=IronMan_t;//point to the Iron Man times array 00071 time.reset();//reset timer for music 00072 musicFlag=1;//flag to play music 00073 count_max=IronMan_count; 00074 init(); 00075 } 00076 void MotorMusic::playArpeggio() 00077 { 00078 ptrNotes=arpeggio; //point to the Iron Man notes array 00079 ptrTimes=arpeggio_t;//point to the Iron Man times array 00080 time.reset();//reset timer for music 00081 musicFlag=1;//flag to play music 00082 count_max=arpeggio_count; 00083 init(); 00084 } 00085 void MotorMusic::playDH() 00086 { 00087 ptrNotes=DH; //point to the Iron Man notes array 00088 ptrTimes=DH_t;//point to the Iron Man times array 00089 time.reset();//reset timer for music 00090 musicFlag=1;//flag to play music 00091 count_max=DH_count; 00092 init(); 00093 } 00094 void MotorMusic::playLock() 00095 { 00096 ptrNotes=lockSound; //point to the Iron Man notes array 00097 ptrTimes=lockSound_t;//point to the Iron Man times array 00098 time.reset();//reset timer for music 00099 musicFlag=1;//flag to play music 00100 count_max=lockSound_count; 00101 init(); 00102 } 00103 void MotorMusic::playUnlock() 00104 { 00105 ptrNotes=unlockSound; //point to the Iron Man notes array 00106 ptrTimes=unlockSound_t;//point to the Iron Man times array 00107 time.reset();//reset timer for music 00108 musicFlag=1;//flag to play music 00109 count_max=unlockSound_count; 00110 init(); 00111 } 00112 //WTF is this? MM 00113 00114
Generated on Mon Jul 18 2022 01:12:15 by
1.7.2
