Librairie contenant les fonctions nécessaires pour pouvoir contrôler les différents composants de la carte d'extension MyLab
Dependencies: MMA7660FC LCD_lib
MyLab_Lib.cpp
- Committer:
- lucas_favre
- Date:
- 2016-03-29
- Revision:
- 1:4659469cc20d
- Child:
- 2:c3fedebb6c7e
File content as of revision 1:4659469cc20d:
/* * MyLab.cpp * Librairie réalisé pour l'utilisation des composants de la carte d'extension MyLab * * * Author: Favre Lucas */ #include "MyLab_Lib.h" #include "mbed.h" #include "lpc1769.h" MyLab::MyLab(PinName Joy_c,PinName Joy_e,PinName Joy_n,PinName Joy_w,PinName Joy_s,PinName mic,PinName speaker,PinName capt_r,PinName capt_g,PinName capt_b) : _joystick (Joy_c,Joy_e,Joy_n,Joy_w,Joy_s), _micro(mic),_speaker(speaker),_r(capt_r),_g(capt_g),_b(capt_b) { for(int k=0; k<32; k++) { Analog_out_data[k] = int (65536.0 * ((1.0 + sin((float(k)/32.0*6.28318530717959)))/2.0)); } Acc.init(); } // Lecture de la position du joystick // sous forme de chaîne caractère void MyLab::JoyStick_Position(char pos[]){ result = ~_joystick.read() + 31 ; switch (result) { case 0: sprintf(pos,"North"); break; case 1: sprintf(pos,"Center"); break; case 7: sprintf(pos,"West"); break; case 3: sprintf(pos,"South"); break; case 15: sprintf(pos,"East"); break; default: sprintf(pos,""); break; } return pos; } // Enregistrement de son sur le microphone SPU0414HR5H short * MyLab::Sound_Record(short * dat){ wait(1); micCB=0; for(int i=0;i<100;i++){ micCB+=_micro; } micCB/=100; // Enregistrement sur le microphone for(int i=0;i<NUMDAT; i++){ dat[i]=(int)((_micro-micCB)*32768); wait_us(DLY); } return dat; } // Lecture d'un son enregistré par le microphone sur // la sortie audio (port jack) void MyLab::Sound_Play(short * buffer){ for(int i=0;i<NUMDAT; i++){ _speaker=((float)buffer[i])/32768*10+0.5; wait_us(DLY); } } // Génération d'une note vers la sortie audio void MyLab::PlayNote(float frequency, float duration, float volume) { // scale samples using current volume level arg for(int k=0; k<32; k++) { Analog_scaled_data[k] = Analog_out_data[k] * volume; } // reset to start of sample array s = 0; // turn on timer interrupts to start sine wave output Sample_Period.attach(this,&MyLab::Sample_timer_interrupt, 1.0/(frequency*32.0)); // play note for specified time wait(duration); // turns off timer interrupts Sample_Period.detach(); // sets output to mid range - analog zero _speaker.write_u16(32768); } float MyLab::Luminosity_Mesure(){ r = _r; g = _g; b = _b; return r+g+b; } float MyLab::Acc_X_Mesure(){ return Acc.read_x(); } float MyLab::Acc_Y_Mesure(){ return Acc.read_y(); } float MyLab::Acc_Z_Mesure(){ return Acc.read_z(); }