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.
Pulse.cpp
00001 00002 #include "Pulse.h" 00003 #include "mbed.h" 00004 00005 Pulse::Pulse(PinName pin) : output_pin(pin) { 00006 output_pin = 0; 00007 switch_state = false; 00008 oscilation = 38400; //Set default oscilation to 38.4KHz 00009 } 00010 00011 void Pulse::send_pulse(int* sequence){ 00012 int num_switches = (sizeof(sequence)/sizeof(int)); 00013 int tick = 1000000/oscilation; 00014 for(int i = 0; i < num_switches; i++){ 00015 if(i % 2 == 0){ 00016 change_state(); 00017 output_pin = 1; 00018 flipper.attach_us(this, &Pulse::flip_pin, tick); 00019 wait_us(sequence[i]); 00020 flipper.detach(); 00021 change_state(); 00022 output_pin = 0; 00023 }else{ 00024 wait_us(sequence[i]); 00025 } 00026 } 00027 } 00028 00029 void Pulse::set_osc(int khz){ 00030 if(khz > 0 && khz <= 250000) //Make sure that the new oscilation is positive and also less than 250KHz 00031 oscilation = khz; 00032 } 00033 00034 void Pulse::set_pin(PinName pin){ 00035 output_pin = pin; 00036 } 00037 00038 void Pulse::flip_pin(){ 00039 if(switch_state) //Stop the output from switching unless it is meant to be transmitting 00040 output_pin = !output_pin; 00041 else 00042 output_pin = 0; 00043 } 00044 00045 void Pulse::change_state(){ 00046 switch_state = !switch_state; 00047 } 00048 00049 00050
Generated on Wed Jul 20 2022 16:50:00 by
1.7.2