La Vidéo:

Le Schémat:

Le code arduino de test des valeurs de boutons:

  1. void setup(){
  2. Serial.begin(9600);
  3. }
  4. void loop(){
  5. Serial.println(analogRead(A0));
  6. delay(200);
  7. }

Le code arduino complet:

  1. //------------------------GammaTroniques-----------------------------
  2. //| Code clavier Arduino Nano |
  3. //| By Xmow |
  4. //| 05/2019 |
  5. //-------------------------------------------------------------------
  6.  
  7. bool eA=0;
  8. bool eB=0;
  9. bool eC=0;
  10. bool eD=0;
  11. bool eOK=0;
  12.  
  13. const int ledA = 6;
  14. const int ledB = 4;
  15. const int ledC = 5;
  16. const int ledD = 3;
  17. const int ledOK = 2;
  18.  
  19. void setup() {
  20.  
  21. Serial.begin(9600);
  22. pinMode(ledA,OUTPUT);
  23. pinMode(ledB,OUTPUT);
  24. pinMode(ledC,OUTPUT);
  25. pinMode(ledD,OUTPUT);
  26. pinMode(ledOK,OUTPUT);
  27. startAnimation();
  28. }
  29.  
  30. void loop() {
  31. if(analogRead(A0) >= 0 && analogRead(A0) <= 99){//A
  32. while(analogRead(A0) >= 0 && analogRead(A0) <= 99){}
  33. if(eA==0){
  34. eA=1;
  35. digitalWrite(ledA,HIGH);
  36. Serial.println("a");
  37. }else if(eA==1){
  38. eA=0;
  39. digitalWrite(ledA,LOW);
  40. Serial.println("a");
  41. }
  42. }
  43.  
  44.  
  45. else if(analogRead(A0) >= 500 && analogRead(A0) <= 599){//B
  46. while(analogRead(A0) >= 500 && analogRead(A0) <= 599){}
  47. if(eB==0){
  48. eB=1;
  49. digitalWrite(ledB,HIGH);
  50. Serial.println("b");
  51. }else if(eB==1){
  52. eB=0;
  53. digitalWrite(ledB,LOW);
  54. Serial.println("b");
  55. }
  56. }
  57.  
  58.  
  59.  
  60.  
  61. else if(analogRead(A0) >= 600 && analogRead(A0) <= 750){//C
  62. while(analogRead(A0) >= 600 && analogRead(A0) <= 750){}
  63. if(eC==0){
  64. eC=1;
  65. digitalWrite(ledC,HIGH);
  66. Serial.println("c");
  67. }else if(eC==1){
  68. eC=0;
  69. digitalWrite(ledC,LOW);
  70. Serial.println("c");
  71.  
  72. }
  73. }
  74.  
  75. else if(analogRead(A0) >= 751 && analogRead(A0) <= 799){//D
  76. while(analogRead(A0) >= 751 && analogRead(A0) <= 799){}
  77. if(eD==0){
  78. eD=1;
  79. digitalWrite(ledD,HIGH);
  80. Serial.println("d");
  81. }else if(eD==1){
  82. eD=0;
  83. digitalWrite(ledD,LOW);
  84. Serial.println("d");
  85.  
  86. }
  87. }
  88.  
  89. else if(analogRead(A0) >= 800 && analogRead(A0) <= 899){//ok
  90. while(analogRead(A0) >= 800 && analogRead(A0) <= 899){}
  91. eA=0;
  92. eB=0;
  93. eC=0;
  94. eD=0;
  95. eOK=0;
  96. digitalWrite(ledA,LOW);
  97. digitalWrite(ledB,LOW);
  98. digitalWrite(ledC,LOW);
  99. digitalWrite(ledD,LOW);
  100. Serial.println("ok");
  101. digitalWrite(ledOK,HIGH);
  102. delay(1000);
  103. digitalWrite(ledOK,LOW);
  104.  
  105.  
  106. }
  107.  
  108.  
  109. delay(50);
  110. }
  111.  
  112. void startAnimation(){
  113. digitalWrite(ledA,HIGH);
  114. delay(200);
  115. digitalWrite(ledA,LOW);
  116. digitalWrite(ledB,HIGH);
  117. delay(200);
  118. digitalWrite(ledB,LOW);
  119. digitalWrite(ledC,HIGH);
  120. delay(200);
  121. digitalWrite(ledC,LOW);
  122. digitalWrite(ledD,HIGH);
  123. delay(200);
  124. digitalWrite(ledD,LOW);
  125. digitalWrite(ledOK,HIGH);
  126. delay(200);
  127. digitalWrite(ledOK,LOW);
  128. delay(200);
  129. digitalWrite(ledA,HIGH);
  130. digitalWrite(ledB,HIGH);
  131. digitalWrite(ledC,HIGH);
  132. digitalWrite(ledD,HIGH);
  133. digitalWrite(ledOK,HIGH);
  134. delay(500);
  135. digitalWrite(ledA,LOW);
  136. digitalWrite(ledB,LOW);
  137. digitalWrite(ledC,LOW);
  138. digitalWrite(ledD,LOW);
  139. digitalWrite(ledOK,LOW);
  140. }
Le petit logiciel (avec le code source):
Code ClavierTélécharger

0 commentaire

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *

YouTube