fork download
  1. #define LED 4
  2. #define SEN A0
  3.  
  4. #define tls 5000 //最初の出現時間
  5. #define tlc 5 //5回出現すると時間が短くなる
  6. #define tlr 0.9 //10%短くなる
  7. #define hitv 300 //圧力しきい値
  8.  
  9. int hit=0;
  10. int miss=0;
  11. int adv[4];
  12. int cnt=0;
  13. int tlsv=tls;
  14. int onLed=-1;
  15.  
  16. unsigned long ts;
  17.  
  18.  
  19. void setup(){
  20. pinMode(LED_BUILTIN, OUTPUT);
  21. for(byte i=0;i<4;i++)
  22. pinMode(i+LED,OUTPUT);
  23. Serial.begin(115200);
  24. for(byte i=0;i<3;i++){
  25. allLed(1,250);
  26. allLed(0,250);
  27. }
  28. delay(1000);
  29. randomSeed(analogRead(A5));
  30. Serial.println("-- Game start ---");
  31. ts=millis();
  32. }
  33.  
  34. void loop(){
  35. long wt;
  36.  
  37. onLed=random(4);
  38. setLed(onLed);
  39.  
  40. game1();
  41. if(miss>=3){
  42. endGame();
  43. }
  44. dsp();
  45.  
  46. wt=random(100,tlsv);
  47. delay(wt);
  48.  
  49.  
  50. cnt++;
  51. if(cnt>=tlc && tlsv>500){
  52. tlsv *= tlr;
  53. cnt=0;
  54. }
  55. }
  56.  
  57. void endGame(){
  58. Serial.println("-- Game over ---");
  59. dsp();
  60. while(1){
  61. allLed(1,200);
  62. allLed(0,800);
  63. }
  64. }
  65.  
  66. int game1(){
  67. int a=0;
  68. ts=millis();
  69. while(millis()-ts <tlsv && a==0){
  70. getAd();
  71. for(byte i=0;i<4;i++){
  72. if(onLed==i && adv[i]==1){
  73. hit++;
  74. a++;
  75. break;
  76. }
  77. if(onLed!=i && adv[i]==1){
  78. miss++;
  79. a++;
  80. break;
  81. }
  82. }
  83. }
  84. if(a==0)miss++;
  85. allLed(0,10);
  86. return 0;
  87. }
  88.  
  89. void dsp(){
  90. char buf[32];
  91. sprintf(buf,"score: %d miss: %d\n",hit,miss);
  92. Serial.print(buf);
  93. }
  94.  
  95. void getAd(){
  96. byte i;
  97. int d;
  98. for(i=0;i<4;i++){
  99. d=analogRead(i+SEN);
  100. adv[i]= d>=hitv?1:0;
  101. }
  102. }
  103.  
  104.  
  105. void setLed(int n){
  106. for(byte i=0;i<4;i++)
  107. digitalWrite(i+LED,LOW);
  108. if(n>=0)
  109. digitalWrite(n+LED,HIGH);
  110. }
  111.  
  112. void allLed(byte n,int t){
  113. for(byte i=0;i<4;i++)
  114. digitalWrite(i+LED,n);
  115. if(t>0)delay(t);
  116. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function ‘setup’:
prog.c:20:3: warning: implicit declaration of function ‘pinMode’ [-Wimplicit-function-declaration]
   pinMode(LED_BUILTIN, OUTPUT);
   ^~~~~~~
prog.c:20:11: error: ‘LED_BUILTIN’ undeclared (first use in this function)
   pinMode(LED_BUILTIN, OUTPUT);
           ^~~~~~~~~~~
prog.c:20:11: note: each undeclared identifier is reported only once for each function it appears in
prog.c:20:24: error: ‘OUTPUT’ undeclared (first use in this function)
   pinMode(LED_BUILTIN, OUTPUT);
                        ^~~~~~
prog.c:21:7: error: unknown type name ‘byte’
   for(byte i=0;i<4;i++)
       ^~~~
prog.c:23:3: error: ‘Serial’ undeclared (first use in this function)
   Serial.begin(115200);
   ^~~~~~
prog.c:24:7: error: unknown type name ‘byte’
   for(byte i=0;i<3;i++){
       ^~~~
prog.c:25:5: warning: implicit declaration of function ‘allLed’ [-Wimplicit-function-declaration]
     allLed(1,250);
     ^~~~~~
prog.c:28:3: warning: implicit declaration of function ‘delay’ [-Wimplicit-function-declaration]
   delay(1000);
   ^~~~~
prog.c:29:3: warning: implicit declaration of function ‘randomSeed’ [-Wimplicit-function-declaration]
   randomSeed(analogRead(A5));
   ^~~~~~~~~~
prog.c:29:14: warning: implicit declaration of function ‘analogRead’ [-Wimplicit-function-declaration]
   randomSeed(analogRead(A5));
              ^~~~~~~~~~
prog.c:29:25: error: ‘A5’ undeclared (first use in this function)
   randomSeed(analogRead(A5));
                         ^~
prog.c:31:6: warning: implicit declaration of function ‘millis’ [-Wimplicit-function-declaration]
   ts=millis();
      ^~~~~~
prog.c: In function ‘loop’:
prog.c:37:9: warning: implicit declaration of function ‘random’ [-Wimplicit-function-declaration]
   onLed=random(4);
         ^~~~~~
prog.c:38:3: warning: implicit declaration of function ‘setLed’; did you mean ‘setup’? [-Wimplicit-function-declaration]
   setLed(onLed);
   ^~~~~~
   setup
prog.c:40:3: warning: implicit declaration of function ‘game1’ [-Wimplicit-function-declaration]
   game1();
   ^~~~~
prog.c:42:5: warning: implicit declaration of function ‘endGame’ [-Wimplicit-function-declaration]
     endGame();
     ^~~~~~~
prog.c:44:3: warning: implicit declaration of function ‘dsp’ [-Wimplicit-function-declaration]
   dsp();
   ^~~
prog.c: At top level:
prog.c:57:6: warning: conflicting types for ‘endGame’
 void endGame(){
      ^~~~~~~
prog.c:42:5: note: previous implicit declaration of ‘endGame’ was here
     endGame();
     ^~~~~~~
prog.c: In function ‘endGame’:
prog.c:58:3: error: ‘Serial’ undeclared (first use in this function)
   Serial.println("-- Game over ---");
   ^~~~~~
prog.c: In function ‘game1’:
prog.c:70:5: warning: implicit declaration of function ‘getAd’ [-Wimplicit-function-declaration]
     getAd();
     ^~~~~
prog.c:71:9: error: unknown type name ‘byte’
     for(byte i=0;i<4;i++){
         ^~~~
prog.c: At top level:
prog.c:89:6: warning: conflicting types for ‘dsp’
 void dsp(){
      ^~~
prog.c:44:3: note: previous implicit declaration of ‘dsp’ was here
   dsp();
   ^~~
prog.c: In function ‘dsp’:
prog.c:91:3: warning: implicit declaration of function ‘sprintf’ [-Wimplicit-function-declaration]
   sprintf(buf,"score: %d miss: %d\n",hit,miss);
   ^~~~~~~
prog.c:91:3: warning: incompatible implicit declaration of built-in function ‘sprintf’
prog.c:91:3: note: include ‘<stdio.h>’ or provide a declaration of ‘sprintf’
prog.c:1:1:
+#include <stdio.h>
 #define LED 4
prog.c:91:3:
   sprintf(buf,"score: %d miss: %d\n",hit,miss);
   ^~~~~~~
prog.c:92:3: error: ‘Serial’ undeclared (first use in this function)
   Serial.print(buf);
   ^~~~~~
prog.c: At top level:
prog.c:95:6: warning: conflicting types for ‘getAd’
 void getAd(){
      ^~~~~
prog.c:70:5: note: previous implicit declaration of ‘getAd’ was here
     getAd();
     ^~~~~
prog.c: In function ‘getAd’:
prog.c:96:3: error: unknown type name ‘byte’
   byte i;
   ^~~~
prog.c:2:13: error: ‘A0’ undeclared (first use in this function)
 #define SEN A0
             ^~
prog.c:99:20: note: in expansion of macro ‘SEN’
     d=analogRead(i+SEN);
                    ^~~
prog.c: At top level:
prog.c:105:6: warning: conflicting types for ‘setLed’
 void setLed(int n){
      ^~~~~~
prog.c:38:3: note: previous implicit declaration of ‘setLed’ was here
   setLed(onLed);
   ^~~~~~
prog.c: In function ‘setLed’:
prog.c:106:7: error: unknown type name ‘byte’
   for(byte i=0;i<4;i++)
       ^~~~
prog.c:107:5: warning: implicit declaration of function ‘digitalWrite’ [-Wimplicit-function-declaration]
     digitalWrite(i+LED,LOW);
     ^~~~~~~~~~~~
prog.c:107:24: error: ‘LOW’ undeclared (first use in this function)
     digitalWrite(i+LED,LOW);
                        ^~~
prog.c:109:24: error: ‘HIGH’ undeclared (first use in this function)
     digitalWrite(n+LED,HIGH);
                        ^~~~
prog.c: At top level:
prog.c:112:13: error: unknown type name ‘byte’
 void allLed(byte n,int t){
             ^~~~
stdout
Standard output is empty