電子ルーレットです

Dependencies:   mbed

Revision:
0:c39163aed6b3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Jan 23 03:46:54 2016 +0000
@@ -0,0 +1,227 @@
+#include "mbed.h"
+#define yukkuri 0.1     //回転が遅くなる具合
+#define startwait 0.01  //最初の回転の速さ
+
+DigitalOut sp(dp1);
+DigitalOut l1(dp6);
+DigitalOut l2(dp9);
+DigitalOut l3(dp10);
+DigitalOut l4(dp11);
+DigitalOut l5(dp13);
+DigitalOut l6(dp14);
+DigitalIn sw(dp15);
+
+//回転中の音
+void beep()
+{
+        for( int i=0 ; i<50 ; i++ )
+        {
+        sp = 1;
+        wait(1.0/659.26/4);
+        sp = 0;
+        wait(1.0/659.26/4);
+        }
+        for( int i=0 ; i<50 ; i++ )
+        {
+        sp = 1;
+        wait(1.0/783.99/4);
+        sp = 0;
+        wait(1.0/783.99/4);
+        }
+} 
+
+int main() {
+        
+        //起動音
+        beep();
+        for( int i=0 ; i<50 ; i++ )
+        {
+        sp = 1;
+        wait(1.0/659.26/2);
+        sp = 0;
+        wait(1.0/659.26/2);
+        }
+        for( int i=0 ; i<50 ; i++ )
+        {
+        sp = 1;
+        wait(1.0/783.99/2);
+        sp = 0;
+        wait(1.0/783.99/2);
+        }
+        
+        //LEDを全て光らせる
+        for( int i=0 ; i<100 ; i++ )
+        {
+        l1 = 1;
+        l2 = 0;
+        l3 = 0;
+        l4 = 0;
+        l5 = 0;
+        l6 = 0;
+        wait(0.001);
+        l1 = 0;
+        l2 = 1;
+        l3 = 0;
+        l4 = 0;
+        l5 = 0;
+        l6 = 0;
+        wait(0.001);
+        l1 = 0;
+        l2 = 0;
+        l3 = 1;
+        l4 = 0;
+        l5 = 0;
+        l6 = 0;
+        wait(0.001);
+        l1 = 0;
+        l2 = 0;
+        l3 = 0;
+        l4 = 1;
+        l5 = 0;
+        l6 = 0;
+        wait(0.001);
+        l1 = 0;
+        l2 = 0;
+        l3 = 0;
+        l4 = 0;
+        l5 = 1;
+        l6 = 0;
+        wait(0.001);
+        l1 = 0;
+        l2 = 0;
+        l3 = 0;
+        l4 = 0;
+        l5 = 0;
+        l6 = 1;
+        wait(0.001);
+        }
+        l1 = 1;
+        l2 = 0;
+        l3 = 0;
+        l4 = 0;
+        l5 = 0;
+        l6 = 0;
+        
+    float memo;    
+    while(1)
+    {
+        //スイッチが押されるまで待つ
+        while( sw == 0 )
+        {
+            memo = startwait;
+        }   
+      
+        //LEDが回転する
+        while(1) {
+            
+            if( sw == 1 )
+            {
+                memo = startwait;   //スイッチが押されていたら最初の回転速度にする
+             }       
+            l1 = 1;
+            l2 = 0;
+            l3 = 0;
+            l4 = 0;
+            l5 = 0;
+            l6 = 0;
+            beep();
+            wait(memo);
+            memo = memo + yukkuri;
+            if( memo > 1.0 )    //速度が1.0以上になったら回転終了
+                break;
+    
+            if( sw == 1 )
+            {
+                memo = startwait;
+             }       
+            l1 = 0;
+            l2 = 1;
+            l3 = 0;
+            l4 = 0;
+            l5 = 0;
+            l6 = 0;
+            beep();
+            wait(memo);
+            memo = memo + yukkuri;
+            if( memo > 1.0 )
+                break;
+    
+            if( sw == 1 )
+            {
+                memo = startwait;
+             }       
+    
+            l1 = 0;
+            l2 = 0;
+            l3 = 1;
+            l4 = 0;
+            l5 = 0;
+            l6 = 0;
+            beep();
+            wait(memo);
+            memo = memo + yukkuri;
+            if( memo > 1.0 )
+                break;
+    
+            if( sw == 1 )
+            {
+                memo = startwait;
+             }       
+    
+            l1 = 0;
+            l2 = 0;
+            l3 = 0;
+            l4 = 1;
+            l5 = 0;
+            l6 = 0;
+            beep();
+            wait(memo);
+            memo = memo + yukkuri;
+            if( memo > 1.0 )
+                break;
+    
+            if( sw == 1 )
+            {
+                memo = startwait;
+             }       
+    
+            l1 = 0;
+            l2 = 0;
+            l3 = 0;
+            l4 = 0;
+            l5 = 1;
+            l6 = 0;
+            beep();
+            wait(memo);
+            memo = memo + yukkuri;
+            if( memo > 1.0 )
+                break;
+    
+            if( sw == 1 )
+            {
+                memo = startwait;
+             }       
+    
+            l1 = 0;
+            l2 = 0;
+            l3 = 0;
+            l4 = 0;
+            l5 = 0;
+            l6 = 1;
+            beep();
+            wait(memo);
+            memo = memo + yukkuri;
+            if( memo > 1.0 )
+                break;
+    
+            if( sw == 1 )
+            {
+                memo = startwait;
+             }       
+    
+    
+        }
+
+    }
+}
+