This is a part of the Kinetiszer project.

Dependencies:   FastPWM SoundEngine board mbed-src

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "FastPWM.h"
00003 #include "atmegatron.h"
00004 
00005 
00006 uint32_t sample_rate = 64000;
00007 FastPWM audio1(PTD1,1);
00008 FastPWM audio2(PTD3,1);
00009 
00010 Ticker tick;
00011 
00012 DigitalOut led_green(PTE24);
00013 DigitalOut led_red(PTB20);
00014 
00015 DigitalIn encoder1_a(PTA0); // phase A
00016 DigitalIn encoder1_b(PTE27); // phase B
00017 DigitalIn encoder1_k(PTD2); // integrated pushbutton
00018 
00019 DigitalIn encoder2_a(PTC4); // phase A
00020 DigitalIn encoder2_b(PTE25); // phase B
00021 DigitalIn encoder2_k(PTD0); // integrated pushbutton
00022 
00023 AnalogIn pot2(A5);
00024 AnalogIn pot3(A4);
00025 AnalogIn pot4(A3);
00026 AnalogIn pot5(A2);
00027 AnalogIn pot6(A1);
00028 AnalogIn pot7(A0);
00029 
00030 
00031 int main(void)
00032 {
00033     // Systick at 1 kHz.
00034     tick.attach_us(&SysTick_Handler,1000); 
00035 
00036     // Setup PWM.
00037     audio1.period_us(1000000.0/sample_rate);
00038     audio1.pulsewidth_us(0.5*1000000.0/sample_rate); // 50%
00039     audio2.period_us(1000000.0/sample_rate);
00040     audio2.pulsewidth_us(0.5*1000000.0/sample_rate); // 50%
00041     
00042     // Setup rotary encoders.
00043     encoder1_a.mode(PullUp);
00044     encoder1_b.mode(PullUp);
00045     encoder1_k.mode(PullUp);
00046     encoder2_a.mode(PullUp);
00047     encoder2_b.mode(PullUp);
00048     encoder2_k.mode(PullUp);
00049     
00050     // Initialize random number generator.
00051     randomSeed(0); // TODO: find a better seed.
00052 
00053     // Sound engin setup.
00054     setup();
00055     
00056     while (true) 
00057     {
00058         loop_priority_low();
00059         // The idea is to call loop_priority_high from the systick ISR to
00060         // fix the sample calculation rate at a known value (1 kHz).
00061         //loop_priority_high();
00062     }
00063 }