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: C12832 USBHost mbed MMA7660 wave_player
Fork of app-board-Speaker by
main.cpp
- Committer:
- funa0825
- Date:
- 2016-12-07
- Revision:
- 3:b1115b34e95b
- Parent:
- 2:cfd337edff08
- Child:
- 5:04b0c694b5a1
File content as of revision 3:b1115b34e95b:
#define mC 261.626
#define mD 293.665
#define mE 329.628
#define mF 349.228
#define mG 391.995
#define mA 440.000
#define mB 493.883
#define THRESH 80
#include "C12832.h"
#include "mbed.h"
#include "rtos.h"
C12832 lcd(p5, p7, p6, p8, p11);
DigitalIn fire(p14);
//DigitalIn up(p15);
//DigitalIn down(p12);
PwmOut sp1(p26);
InterruptIn myup(p15);
InterruptIn mydown(p12);
PwmOut led1(p23);
PwmOut led2(p24);
PwmOut led3(p25);
Semaphore three_slots(1);
Timer for_chat;
int i=0;
float mm[]={mC,mD,mE,mF,mG,mA,mB,mC*2,mD*2,mE*2,mF*2,mG*2,mA*2,mB*2,mC*4};
void intRise(void)
{
if(for_chat.read_ms()>THRESH);
{
i++;
sp1.period(1.0/mm[i]);
sp1.write(0.5f);
for_chat.reset();
}
}
void intFall(void)
{
if(for_chat.read_ms()>THRESH);
{
i--;
sp1.period(1.0/mm[i]);
sp1.write(0.5f);
for_chat.reset();
}
}
void r_thread(void const *argument)
{
float r = 0;
while (true)
{
r=0;
while(r<=1)
{
three_slots.wait();
led1 = r;
r += 0.01;
lcd.locate(0,16);
lcd.printf("R: %3.2f",r);
three_slots.release();
Thread::wait(100);
}
while(r>0)
{
three_slots.wait();
led1 = r;
r -= 0.01;
lcd.locate(0,16);
lcd.printf("R: %3.2f",r);
three_slots.release();
Thread::wait(100);
}
}
}
void g_thread(void const *argument)
{
float g = 0;
while (true)
{
g=0;
while(g<=1)
{
three_slots.wait();
led2 = g;
g += 0.01;
lcd.locate(40,16);
lcd.printf("G: %3.2f",g);
three_slots.release();
Thread::wait(200);
}
while(g>0)
{
three_slots.wait();
led2 = g;
g -= 0.01;
lcd.locate(40,16);
lcd.printf("G: %3.2f",g);
three_slots.release();
Thread::wait(200);
}
}
}
void b_thread(void const *argument)
{
float b = 0;
while (true)
{
b=0;
while(b<=1)
{
three_slots.wait();
led3 = b;
b += 0.01;
lcd.locate(80,16);
lcd.printf("B: %3.2f",b);
three_slots.release();
Thread::wait(300);
}
while(b>0)
{
three_slots.wait();
led3 = b;
b -= 0.01;
lcd.locate(80,16);
lcd.printf("B: %3.2f",b);
three_slots.release();
Thread::wait(300);
}
}
}
void count_thread(void const *argument)
{
while (true)
{
three_slots.wait();
lcd.locate(0,3);
lcd.printf("Counting : %d",i);
three_slots.release();
Thread::wait(100);
}
}
int main()
{
wait(0.01);
for_chat.start();
myup.fall(&intRise);
mydown.fall(&intFall);
Thread thread1(r_thread,(void *)"Th 1");
Thread thread2(g_thread,(void *)"Th 2");
Thread thread3(b_thread,(void *)"Th 3");
Thread thread4(count_thread,(void *)"Th 4");
lcd.cls();
wait(0.01);
while(1)
{
//lcd.cls();
}
}
