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.
triwave.cpp
00001 /** triwave class 00002 * Copyright (c) 2014, 2015 Motoo Tanaka @ Design Methodology Lab 00003 * 00004 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00005 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00006 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00007 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00008 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00009 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00010 * THE SOFTWARE. 00011 */ 00012 #include "triwave.h" 00013 00014 triwave::triwave(float v, int f, int d, int p) : sqrwave(v, f, d, p) 00015 { 00016 _name = "tri" ; 00017 } 00018 00019 triwave::~triwave(void) { } 00020 00021 int triwave::value(void) 00022 { 00023 int result = 0 ; 00024 if (_cycle == 0) { 00025 if (_duty == 100) { 00026 result = _amp ; 00027 } else { 00028 result = 0 ; 00029 } 00030 } else if (_duty == 100) { // saw wave 00031 result = _amp * _pos / _cycle ; 00032 } else if (_duty == 0) { // reversed saw wave 00033 result = _amp * (_cycle - _pos) / _cycle ; 00034 } else { // tri wave 00035 if (_pos < (int)((_duty * _cycle)/100)) { 00036 result = _amp * _pos / ((_duty * _cycle) / 100) ; 00037 } else { 00038 result = _amp - _amp * (_pos - (_duty * _cycle)/100) / ((_cycle * (100 - _duty))/100) ; 00039 } 00040 } 00041 return( result ) ; 00042 }
Generated on Wed Jul 13 2022 01:58:56 by
1.7.2