Sound : LED = 1:1 param "1" never go upper 15, under 0

Dependencies:   C12832 mbed-rtos mbed

Fork of app-board-Speaker by Ryohei Funakoshi

Committer:
funa0825
Date:
Wed Dec 07 03:00:13 2016 +0000
Revision:
3:b1115b34e95b
Parent:
2:cfd337edff08
Child:
4:91da6632d547
?;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
funa0825 3:b1115b34e95b 1
funa0825 3:b1115b34e95b 2
funa0825 3:b1115b34e95b 3 #define mC 261.626
funa0825 3:b1115b34e95b 4 #define mD 293.665
funa0825 3:b1115b34e95b 5 #define mE 329.628
funa0825 3:b1115b34e95b 6 #define mF 349.228
funa0825 3:b1115b34e95b 7 #define mG 391.995
funa0825 3:b1115b34e95b 8 #define mA 440.000
funa0825 3:b1115b34e95b 9 #define mB 493.883
funa0825 3:b1115b34e95b 10 #define THRESH 80
funa0825 3:b1115b34e95b 11 #include "C12832.h"
chris 0:f86c572491c3 12 #include "mbed.h"
funa0825 3:b1115b34e95b 13 #include "rtos.h"
chris 0:f86c572491c3 14
funa0825 3:b1115b34e95b 15 C12832 lcd(p5, p7, p6, p8, p11);
chris 1:0a08d26b011a 16 DigitalIn fire(p14);
funa0825 3:b1115b34e95b 17 //DigitalIn up(p15);
funa0825 3:b1115b34e95b 18 //DigitalIn down(p12);
funa0825 3:b1115b34e95b 19 PwmOut sp1(p26);
funa0825 3:b1115b34e95b 20 InterruptIn myup(p15);
funa0825 3:b1115b34e95b 21 InterruptIn mydown(p12);
funa0825 3:b1115b34e95b 22 PwmOut led1(p23);
funa0825 3:b1115b34e95b 23 PwmOut led2(p24);
funa0825 3:b1115b34e95b 24 PwmOut led3(p25);
funa0825 3:b1115b34e95b 25 Semaphore three_slots(1);
funa0825 3:b1115b34e95b 26 Timer for_chat;
chris 0:f86c572491c3 27
funa0825 3:b1115b34e95b 28 int i=0;
funa0825 3:b1115b34e95b 29 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};
funa0825 3:b1115b34e95b 30 void intRise(void)
funa0825 3:b1115b34e95b 31 {
funa0825 3:b1115b34e95b 32 if(for_chat.read_ms()>THRESH);
funa0825 3:b1115b34e95b 33 {
funa0825 3:b1115b34e95b 34 i++;
funa0825 3:b1115b34e95b 35 sp1.period(1.0/mm[i]);
funa0825 3:b1115b34e95b 36 sp1.write(0.5f);
funa0825 3:b1115b34e95b 37 for_chat.reset();
funa0825 3:b1115b34e95b 38 }
funa0825 3:b1115b34e95b 39 }
funa0825 3:b1115b34e95b 40
funa0825 3:b1115b34e95b 41 void intFall(void)
funa0825 3:b1115b34e95b 42 {
funa0825 3:b1115b34e95b 43 if(for_chat.read_ms()>THRESH);
funa0825 3:b1115b34e95b 44 {
funa0825 3:b1115b34e95b 45 i--;
funa0825 3:b1115b34e95b 46 sp1.period(1.0/mm[i]);
funa0825 3:b1115b34e95b 47 sp1.write(0.5f);
funa0825 3:b1115b34e95b 48 for_chat.reset();
funa0825 3:b1115b34e95b 49 }
funa0825 3:b1115b34e95b 50 }
funa0825 3:b1115b34e95b 51
funa0825 3:b1115b34e95b 52
funa0825 3:b1115b34e95b 53 void r_thread(void const *argument)
funa0825 3:b1115b34e95b 54 {
funa0825 3:b1115b34e95b 55 float r = 0;
funa0825 3:b1115b34e95b 56 while (true)
funa0825 3:b1115b34e95b 57 {
funa0825 3:b1115b34e95b 58 r=0;
funa0825 3:b1115b34e95b 59 while(r<=1)
funa0825 3:b1115b34e95b 60 {
funa0825 3:b1115b34e95b 61 three_slots.wait();
funa0825 3:b1115b34e95b 62 led1 = r;
funa0825 3:b1115b34e95b 63 r += 0.01;
funa0825 3:b1115b34e95b 64 lcd.locate(0,16);
funa0825 3:b1115b34e95b 65 lcd.printf("R: %3.2f",r);
funa0825 3:b1115b34e95b 66 three_slots.release();
funa0825 3:b1115b34e95b 67 Thread::wait(100);
funa0825 3:b1115b34e95b 68
funa0825 3:b1115b34e95b 69 }
funa0825 3:b1115b34e95b 70 while(r>0)
funa0825 3:b1115b34e95b 71 {
funa0825 3:b1115b34e95b 72 three_slots.wait();
funa0825 3:b1115b34e95b 73 led1 = r;
funa0825 3:b1115b34e95b 74 r -= 0.01;
funa0825 3:b1115b34e95b 75 lcd.locate(0,16);
funa0825 3:b1115b34e95b 76 lcd.printf("R: %3.2f",r);
funa0825 3:b1115b34e95b 77 three_slots.release();
funa0825 3:b1115b34e95b 78 Thread::wait(100);
funa0825 3:b1115b34e95b 79
funa0825 3:b1115b34e95b 80 }
funa0825 3:b1115b34e95b 81 }
funa0825 3:b1115b34e95b 82 }
funa0825 3:b1115b34e95b 83 void g_thread(void const *argument)
chris 0:f86c572491c3 84 {
funa0825 3:b1115b34e95b 85 float g = 0;
funa0825 3:b1115b34e95b 86 while (true)
funa0825 3:b1115b34e95b 87 {
funa0825 3:b1115b34e95b 88 g=0;
funa0825 3:b1115b34e95b 89 while(g<=1)
funa0825 3:b1115b34e95b 90 {
funa0825 3:b1115b34e95b 91 three_slots.wait();
funa0825 3:b1115b34e95b 92 led2 = g;
funa0825 3:b1115b34e95b 93 g += 0.01;
funa0825 3:b1115b34e95b 94 lcd.locate(40,16);
funa0825 3:b1115b34e95b 95 lcd.printf("G: %3.2f",g);
funa0825 3:b1115b34e95b 96 three_slots.release();
funa0825 3:b1115b34e95b 97 Thread::wait(200);
funa0825 3:b1115b34e95b 98 }
funa0825 3:b1115b34e95b 99 while(g>0)
funa0825 3:b1115b34e95b 100 {
funa0825 3:b1115b34e95b 101 three_slots.wait();
funa0825 3:b1115b34e95b 102 led2 = g;
funa0825 3:b1115b34e95b 103 g -= 0.01;
funa0825 3:b1115b34e95b 104 lcd.locate(40,16);
funa0825 3:b1115b34e95b 105 lcd.printf("G: %3.2f",g);
funa0825 3:b1115b34e95b 106 three_slots.release();
funa0825 3:b1115b34e95b 107 Thread::wait(200);
funa0825 3:b1115b34e95b 108 }
funa0825 3:b1115b34e95b 109 }
funa0825 3:b1115b34e95b 110 }
funa0825 3:b1115b34e95b 111 void b_thread(void const *argument)
funa0825 3:b1115b34e95b 112 {
funa0825 3:b1115b34e95b 113 float b = 0;
funa0825 3:b1115b34e95b 114 while (true)
funa0825 3:b1115b34e95b 115 {
funa0825 3:b1115b34e95b 116 b=0;
funa0825 3:b1115b34e95b 117 while(b<=1)
funa0825 3:b1115b34e95b 118 {
funa0825 3:b1115b34e95b 119 three_slots.wait();
funa0825 3:b1115b34e95b 120 led3 = b;
funa0825 3:b1115b34e95b 121 b += 0.01;
funa0825 3:b1115b34e95b 122 lcd.locate(80,16);
funa0825 3:b1115b34e95b 123 lcd.printf("B: %3.2f",b);
funa0825 3:b1115b34e95b 124 three_slots.release();
funa0825 3:b1115b34e95b 125 Thread::wait(300);
chris 2:cfd337edff08 126 }
funa0825 3:b1115b34e95b 127 while(b>0)
funa0825 3:b1115b34e95b 128 {
funa0825 3:b1115b34e95b 129 three_slots.wait();
funa0825 3:b1115b34e95b 130 led3 = b;
funa0825 3:b1115b34e95b 131 b -= 0.01;
funa0825 3:b1115b34e95b 132 lcd.locate(80,16);
funa0825 3:b1115b34e95b 133 lcd.printf("B: %3.2f",b);
funa0825 3:b1115b34e95b 134 three_slots.release();
funa0825 3:b1115b34e95b 135 Thread::wait(300);
funa0825 3:b1115b34e95b 136 }
funa0825 3:b1115b34e95b 137 }
funa0825 3:b1115b34e95b 138 }
funa0825 3:b1115b34e95b 139 void count_thread(void const *argument)
funa0825 3:b1115b34e95b 140 {
funa0825 3:b1115b34e95b 141 while (true)
funa0825 3:b1115b34e95b 142 {
funa0825 3:b1115b34e95b 143 three_slots.wait();
funa0825 3:b1115b34e95b 144 lcd.locate(0,3);
funa0825 3:b1115b34e95b 145 lcd.printf("Counting : %d",i);
funa0825 3:b1115b34e95b 146 three_slots.release();
funa0825 3:b1115b34e95b 147 Thread::wait(100);
chris 0:f86c572491c3 148 }
funa0825 3:b1115b34e95b 149 }
funa0825 3:b1115b34e95b 150 int main()
funa0825 3:b1115b34e95b 151 {
funa0825 3:b1115b34e95b 152 wait(0.01);
funa0825 3:b1115b34e95b 153 for_chat.start();
funa0825 3:b1115b34e95b 154 myup.fall(&intRise);
funa0825 3:b1115b34e95b 155 mydown.fall(&intFall);
funa0825 3:b1115b34e95b 156 Thread thread1(r_thread,(void *)"Th 1");
funa0825 3:b1115b34e95b 157 Thread thread2(g_thread,(void *)"Th 2");
funa0825 3:b1115b34e95b 158 Thread thread3(b_thread,(void *)"Th 3");
funa0825 3:b1115b34e95b 159 Thread thread4(count_thread,(void *)"Th 4");
funa0825 3:b1115b34e95b 160
funa0825 3:b1115b34e95b 161 lcd.cls();
funa0825 3:b1115b34e95b 162 wait(0.01);
funa0825 3:b1115b34e95b 163 while(1)
funa0825 3:b1115b34e95b 164 {
funa0825 3:b1115b34e95b 165 //lcd.cls();
funa0825 3:b1115b34e95b 166
funa0825 3:b1115b34e95b 167 }
funa0825 3:b1115b34e95b 168 }
funa0825 3:b1115b34e95b 169