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.
Dependencies: UIT_ACM1602NI UIT_ADDA mbed
main.cpp
00001 //-------------------------------------------------------------- 00002 // 入力の切り替え(ラインとマイク),LCD 表示 ---- 割り込み利用 00003 // Analog Input : A0 00004 // Analog Output: MCP4922 using SPI 00005 // 2014/12/26, Copyright (c) 2014 MIKAMI, Naoki 00006 //-------------------------------------------------------------- 00007 00008 #include "ADC_Interrupt.hpp" // for ADC using interrupt 00009 #include "DAC_MCP4922.hpp" // for DAC MCP4922 00010 #include "ACM1602NI.hpp" // for LCD 00011 00012 using namespace Mikami; 00013 00014 const int FS_ = 10000; // Sampling frequency: 10 kHz 00015 ADC_Intr adc_(A0, FS_, A1); // CH1: Line, CH2: Mic 00016 DAC_MCP4922 myDac_; // for DA 00017 DigitalIn sw_(D2, PullDown); // for SW 00018 Acm1602Ni lcd_; // for LCD 00019 00020 // Interrupt service routine for ADC 00021 void AdcIsr() 00022 { 00023 float xn = adc_.Read(); // Read from A0 00024 myDac_.Write(xn); // to DAC 00025 } 00026 00027 int main() 00028 { 00029 lcd_.Clear(); 00030 myDac_.ScfClockTim3(420000); // cutoff frequency: 4.2 kHz 00031 adc_.SetIntrVec(AdcIsr); // Assign ISR for ADC interrupt 00032 00033 int swBefore = 0; 00034 00035 while (true) 00036 { 00037 int swNow = sw_.read(); 00038 if (swNow != swBefore) 00039 { 00040 if (swNow == 0) adc_.Select1stChannel(); // line input 00041 else adc_.Select2ndChannel(); // mic. input 00042 swBefore = swNow; 00043 } 00044 00045 if (swNow == 0) lcd_.WriteStringXY("Input: Line", 0, 0); 00046 else lcd_.WriteStringXY("Input: Mic ", 0, 0); 00047 wait(0.1f); 00048 } 00049 }
Generated on Wed Jul 13 2022 01:49:13 by
1.7.2