テスト

Dependencies:   C12832 USBHost mbed MMA7660 wave_player

Fork of app-board-Speaker by Ryohei Funakoshi

Revision:
5:04b0c694b5a1
Parent:
3:b1115b34e95b
Child:
6:82aa8f2c3c47
diff -r dc538515998b -r 04b0c694b5a1 main.cpp
--- a/main.cpp	Sat Dec 10 11:15:42 2016 +0000
+++ b/main.cpp	Sat Dec 10 11:30:44 2016 +0000
@@ -8,6 +8,7 @@
 #define mA 440.000
 #define mB 493.883
 #define THRESH 80
+#define COUNT_MAX 15
 #include "C12832.h"
 #include "mbed.h"
 #include "rtos.h"
@@ -26,12 +27,17 @@
 Timer for_chat;
 
 int i=0;
+int count = 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);
     {
+        if(i<=13){
         i++;
+        count ++;
+        }
         sp1.period(1.0/mm[i]);
         sp1.write(0.5f);
         for_chat.reset();
@@ -42,7 +48,10 @@
 {
     if(for_chat.read_ms()>THRESH);
     {
+        if(i >=1){
         i--;
+        count --;
+        }
         sp1.period(1.0/mm[i]);
         sp1.write(0.5f);
         for_chat.reset();
@@ -59,8 +68,26 @@
         while(r<=1)
         {
             three_slots.wait();
+            switch(count){
+                case 0:r = 0.0;break;
+                case 1:r=0.07;break;
+                case 2:r=0.13;break;
+                case 3:r=0.20;break;
+                case 4:r=0.27;break;
+                case 5:r=0.34;break;
+                case 6:r=0.41;break;
+                case 7:r=0.48;break;
+                case 8:r=0.55;break;
+                case 9:r=0.62;break;
+                case 10:r=0.69;break;
+                case 11:r=0.76;break;
+                case 12:r=0.83;break;
+                case 13:r=0.90;break;
+                case 14:r=0.97;break;
+                }
+            //r = (float)(count%COUNT_MAX)/COUNT_MAX;
             led1 = r;
-            r += 0.01;
+            //r += 0.01;
             lcd.locate(0,16);
             lcd.printf("R: %3.2f",r);
             three_slots.release();
@@ -70,8 +97,26 @@
         while(r>0)
         {
             three_slots.wait();
+            switch(count){
+                case 0:r = 0.0;break;
+                case 1:r=0.07;break;
+                case 2:r=0.13;break;
+                case 3:r=0.20;break;
+                case 4:r=0.27;break;
+                case 5:r=0.34;break;
+                case 6:r=0.41;break;
+                case 7:r=0.48;break;
+                case 8:r=0.55;break;
+                case 9:r=0.62;break;
+                case 10:r=0.69;break;
+                case 11:r=0.76;break;
+                case 12:r=0.83;break;
+                case 13:r=0.90;break;
+                case 14:r=0.97;break;
+                }
+            //r = (float)(count%COUNT_MAX)/COUNT_MAX;
             led1 = r;
-            r -= 0.01;
+            //r -= 0.01;
             lcd.locate(0,16);
             lcd.printf("R: %3.2f",r);
             three_slots.release();
@@ -89,8 +134,25 @@
         while(g<=1)
         {
             three_slots.wait();
+            switch(count){
+                case 0:g = 0.50;break;
+                case 1:g = 0.50;break;
+                case 2:g=0.63;break;
+                case 3:g=0.63;break;
+                case 4:g=0.77;break;
+                case 5:g=0.77;break;
+                case 6:g=0.90;break;
+                case 7:g=0.90;break;
+                case 8:g=0.47;break;
+                case 9:g=0.47;break;
+                case 10:g=0.33;break;
+                case 11:g=0.33;break;
+                case 12:g=0.20;break;
+                case 13:g=0.20;break;
+                case 14:g=0.07;break;
+                }
             led2 = g;
-            g += 0.01;
+            //g += 0.01;
             lcd.locate(40,16);
             lcd.printf("G: %3.2f",g);
             three_slots.release();
@@ -99,8 +161,25 @@
         while(g>0)
         {
             three_slots.wait();
+            switch(count){
+                case 0:g = 0.50;break;
+                case 1:g = 0.50;break;
+                case 2:g=0.63;break;
+                case 3:g=0.63;break;
+                case 4:g=0.77;break;
+                case 5:g=0.77;break;
+                case 6:g=0.90;break;
+                case 7:g=0.90;break;
+                case 8:g=0.47;break;
+                case 9:g=0.47;break;
+                case 10:g=0.33;break;
+                case 11:g=0.33;break;
+                case 12:g=0.20;break;
+                case 13:g=0.20;break;
+                case 14:g=0.07;break;
+                }
             led2 = g;
-            g -= 0.01;
+            //g -= 0.01;
             lcd.locate(40,16);
             lcd.printf("G: %3.2f",g);
             three_slots.release();
@@ -117,8 +196,25 @@
         while(b<=1)
         {
             three_slots.wait();
+            switch(count){
+                case 0:b = 1.00;break;
+                case 1:b = 1.00;break;
+                case 2:b=1.00;break;
+                case 3:b=0.80;break;
+                case 4:b=0.80;break;
+                case 5:b=0.80;break;
+                case 6:b=0.60;break;
+                case 7:b=0.60;break;
+                case 8:b=0.60;break;
+                case 9:b=0.40;break;
+                case 10:b=0.40;break;
+                case 11:b=0.40;break;
+                case 12:b=0.20;break;
+                case 13:b=0.20;break;
+                case 14:b=0.20;break;
+                }
             led3 = b;
-            b += 0.01;
+            //b += 0.01;
             lcd.locate(80,16);
             lcd.printf("B: %3.2f",b);
             three_slots.release();
@@ -127,8 +223,25 @@
         while(b>0)
         {
             three_slots.wait();
+            switch(count){
+                case 0:b = 1.00;break;
+                case 1:b = 1.00;break;
+                case 2:b=1.00;break;
+                case 3:b=0.80;break;
+                case 4:b=0.80;break;
+                case 5:b=0.80;break;
+                case 6:b=0.60;break;
+                case 7:b=0.60;break;
+                case 8:b=0.60;break;
+                case 9:b=0.40;break;
+                case 10:b=0.40;break;
+                case 11:b=0.40;break;
+                case 12:b=0.20;break;
+                case 13:b=0.20;break;
+                case 14:b=0.20;break;
+                }
             led3 = b;
-            b -= 0.01;
+            //b -= 0.01;
             lcd.locate(80,16);
             lcd.printf("B: %3.2f",b);
             three_slots.release();
@@ -142,7 +255,7 @@
     {
         three_slots.wait();
         lcd.locate(0,3);
-        lcd.printf("Counting : %d",i);
+        lcd.printf("Counting : %d   ",i);
         three_slots.release();
         Thread::wait(100);
     }