テスト

Dependencies:   C12832 USBHost mbed MMA7660 wave_player

Fork of app-board-Speaker by Ryohei Funakoshi

Revision:
3:b1115b34e95b
Parent:
2:cfd337edff08
Child:
5:04b0c694b5a1
--- a/main.cpp	Thu Oct 25 12:25:00 2012 +0000
+++ b/main.cpp	Wed Dec 07 03:00:13 2016 +0000
@@ -1,17 +1,169 @@
+
+
+#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);
-PwmOut spkr(p26);
+//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 main()
+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) 
 {
-    while (1) {
-        for (float i=2000.0; i<10000.0; i+=100) {
-            spkr.period(1.0/i);
-            spkr=0.5;
-            wait(0.1);
+    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);
         }
-        spkr=0.0;
-        while(!fire) {}
+        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);
     }
-}
\ No newline at end of file
+} 
+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();
+
+    }
+}
+ 
\ No newline at end of file