Flowing lights based on STONE HMI and Arduino.

Flowing lights based on STONE HMI and Arduino. - C - Programmation

Marsh Posté le 04-06-2021 à 10:22:00    

J'essaie de faire briller les feux de circulation et je ne sais pas s'il y a un problème avec le code, j'ai écrit cinq modes de luminosité différents mais les résultats semblent similaires.
Ne me blâmez pas, je suis un débutant.
 
J'utilise Arduino UNO (https://www.arduino.cc/)
et PIERRE STVI050WT-03 (https://www.stoneitech.com/product/ [...] wt-03.html)
 

Code :
  1. int t = 40;
  2. int rnd =5;
  3. int pat1t =75;
  4. void setup()
  5. {
  6.    for(int i=3; i<=12; i++)
  7.    pinMode(i,OUTPUT);
  8. }
  9. void loop(){
  10.    for(int i=0; i<=rnd; i++) {
  11.    pat1();}
  12.    for(int i=0; i<=rnd; i++){
  13.    pat2();}
  14.    for(int i=0; i<=rnd; i++) {
  15.    pat3();}
  16.    for(int i=0; i<=rnd; i++) {
  17.    pat4();}
  18.    for(int i=0; i<=rnd; i++){
  19.    pat5();}
  20.    for(int i=0; i<=rnd; i++) {
  21.    pat6();}
  22.    for(int i=0; i<=rnd; i++) {
  23.    pat7();}
  24.    for(int i=0; i<=rnd; i++) {
  25.    pat8();}
  26.    for(int i=0; i<=rnd; i++) {
  27.    pat9();}
  28.  
  29.  
  30. }
  31.  
  32. void pat1(){
  33.     for(int i=3; i<=12; i++) {
  34.       digitalWrite(i,HIGH);
  35.       delay(pat1t);
  36.       digitalWrite(i,LOW);
  37.     }
  38.    
  39.     for(int i=11; i>=4; i--) {
  40.       digitalWrite(i,HIGH);
  41.       delay(pat1t);
  42.       digitalWrite(i,LOW);
  43.     }
  44. void pat2(){
  45.      for(int i=3; i<=12; i++) {
  46.       digitalWrite(i,HIGH);
  47.       digitalWrite(i-1,HIGH);
  48.       digitalWrite(i+1,HIGH);
  49.       delay(100);
  50.       digitalWrite(i,LOW);
  51.       digitalWrite(i-1,LOW);
  52.       digitalWrite(i+1,LOW);
  53.     }
  54.    
  55.     for(int i=11; i>=4; i--) {
  56.       digitalWrite(i,HIGH);
  57.       digitalWrite(i-1,HIGH);
  58.       digitalWrite(i+1,HIGH);
  59.       delay(100);
  60.       digitalWrite(i,LOW);
  61.       digitalWrite(i-1,LOW);
  62.       digitalWrite(i+1,LOW);
  63.     }
  64. }
  65. void pat3(){
  66.   for(int i=3; i<=12; i=i+2) {
  67.       digitalWrite(i,HIGH);
  68.       delay(100);
  69.       digitalWrite(i,LOW);
  70.     }
  71.    
  72.     for(int i=12; i>=3; i=i-2) {
  73.       digitalWrite(i,HIGH);
  74.       delay(100);
  75.       digitalWrite(i,LOW);
  76.     }     
  77. }
  78. void pat4(){ 
  79.       for(int i=3; i<=12; i++) {
  80.       digitalWrite(i,HIGH);
  81.       delay(100);
  82.     }
  83.    
  84.     for(int i=12; i>=2; i--) {
  85.       digitalWrite(i,HIGH);
  86.       delay(100);
  87.       digitalWrite(i,LOW);
  88.     }
  89. }
  90. void pat5(){
  91.      for(int i=3; i<=12; i++) {
  92.       digitalWrite(i,HIGH);
  93.       }
  94.     delay(100);
  95.     for(int i=3; i<=12; i++) {
  96.       digitalWrite(i,LOW);
  97.       }
  98.     delay(100); 
  99. }
  100. void pat6(){
  101.        for(int i=3; i<=8; i++) {
  102.       digitalWrite(i,HIGH);
  103.       }
  104.     for(int i=8; i<=12; i++) {
  105.       digitalWrite(i,LOW);
  106.       }
  107.     delay(200);
  108.     for(int i=3; i<=8; i++) {
  109.       digitalWrite(i,LOW);
  110.       }
  111.     for(int i=8; i<=12; i++) {
  112.       digitalWrite(i,HIGH);
  113.       }
  114.     delay(200);
  115. }
  116. void pat7(){
  117.        for(int i=3; i<=12; i=i+2) {
  118.       digitalWrite(i,HIGH);
  119.       }
  120.     for(int i=4; i<=12; i=i+2) {
  121.       digitalWrite(i,LOW);
  122.       }
  123.     delay(200);
  124.      for(int i=3; i<=12; i=i+2) {
  125.       digitalWrite(i,LOW);
  126.       }
  127.     for(int i=4; i<=12; i=i+2) {
  128.       digitalWrite(i,HIGH);
  129.       }
  130.     delay(200);
  131. }
  132. void pat8(){
  133.     digitalWrite(7,HIGH);
  134.     digitalWrite(8,HIGH);
  135.     delay(t);
  136.     digitalWrite(7,LOW);
  137.     digitalWrite(8,LOW);
  138.     delay(t);
  139.     digitalWrite(6,HIGH);
  140.     digitalWrite(9,HIGH);
  141.     delay(t);
  142.     digitalWrite(6,LOW);
  143.     digitalWrite(9,LOW);
  144.     delay(t);
  145.     digitalWrite(5,HIGH);
  146.     digitalWrite(10,HIGH);
  147.     delay(t);
  148.     digitalWrite(5,LOW);
  149.     digitalWrite(10,LOW);
  150.     delay(t);
  151.     digitalWrite(4,HIGH);
  152.     digitalWrite(11,HIGH);
  153.     delay(t);
  154.     digitalWrite(4,LOW);
  155.     digitalWrite(11,LOW);
  156.     delay(t);
  157.     digitalWrite(3,HIGH);
  158.     digitalWrite(12,HIGH);
  159.     delay(t);
  160.     digitalWrite(3,LOW);
  161.     digitalWrite(12,LOW);
  162.     delay(t);
  163.      digitalWrite(4,HIGH);
  164.     digitalWrite(11,HIGH);
  165.     delay(t);
  166.     digitalWrite(4,LOW);
  167.     digitalWrite(11,LOW);
  168.     delay(t);
  169.     digitalWrite(5,HIGH);
  170.     digitalWrite(10,HIGH);
  171.     delay(t);
  172.     digitalWrite(5,LOW);
  173.     digitalWrite(10,LOW);
  174.     delay(t);
  175.     digitalWrite(6,HIGH);
  176.     digitalWrite(9,HIGH);
  177.     delay(t);
  178.     digitalWrite(6,LOW);
  179.     digitalWrite(9,LOW);
  180.     delay(t);     
  181. }   
  182. void pat9(){
  183.     for(int i=3; i<=12; i++) {
  184.       digitalWrite(i,HIGH);
  185.     }
  186.      for(int i=3; i<=12; i++) {
  187.       digitalWrite(i,LOW);
  188.       delay(100);
  189.       digitalWrite(i,HIGH);
  190.     }
  191.     for(int i=11; i>=4; i--) {
  192.       digitalWrite(i,LOW);
  193.       delay(100);
  194.       digitalWrite(i,HIGH);
  195.     }
  196.  
  197. }


Message édité par ellis13 le 07-06-2021 à 07:47:12
Reply

Marsh Posté le 04-06-2021 à 10:22:00   

Reply

Marsh Posté le 04-06-2021 à 19:39:21    

As we already told you this is a french forum, so please post in FRENCH. If you only speak english you should look for an alternative forum.

Reply

Marsh Posté le 07-06-2021 à 07:48:42    

rat de combat a écrit :

As we already told you this is a french forum, so please post in FRENCH. If you only speak english you should look for an alternative forum.


I am very sorry, I have corrected it to French, and I will take care of this afterward.

Reply

Marsh Posté le 07-06-2021 à 17:24:42    

C'est pas compréhensible ton problème. Tu parles de "feux de circulation" mais tu mets un lien vers un afficheur avec un ARM (plutôt costaud à priori).

 

Montre ton schéma, qu'est-ce qui est connecté sur l'Arduino et comment?

 

Sinon le code est affreux, mais bon, pour un débutant ça passera. Perso je mettrais les modes dans un tableau (PROGMEM pour bien faire) et une fonction qui prend le mode souhaité comme paramètre. Enfin bref.

 

La fonction delay() c'est des millisecondes, à ta place j'augmenterais nettement les valeurs pour tester. Et tu as pensé à activer les Warnings dans ton IDE? Il y a quelque chose qui sort?

 

PS @modo: A déplacer dans Élec/Domotique/DIY (?) :jap:

 

PPS: Le titre est toujours en Shakespeare. :o

Message cité 1 fois
Message édité par rat de combat le 07-06-2021 à 17:34:39
Reply

Marsh Posté le 09-06-2021 à 03:36:08    

rat de combat a écrit :

C'est pas compréhensible ton problème. Tu parles de "feux de circulation" mais tu mets un lien vers un afficheur avec un ARM (plutôt costaud à priori).
 
Montre ton schéma, qu'est-ce qui est connecté sur l'Arduino et comment?
 
Sinon le code est affreux, mais bon, pour un débutant ça passera. Perso je mettrais les modes dans un tableau (PROGMEM pour bien faire) et une fonction qui prend le mode souhaité comme paramètre. Enfin bref.
 
La fonction delay() c'est des millisecondes, à ta place j'augmenterais nettement les valeurs pour tester. Et tu as pensé à activer les Warnings dans ton IDE? Il y a quelque chose qui sort?
 
PS @modo: A déplacer dans Élec/Domotique/DIY (?) :jap:  
 
PPS: Le titre est toujours en Shakespeare. :o


J'ai un arduino connecté à un LCD ainsi qu'à un feu de circulation.
Je sais peut-être d'où vient le problème, j'ai lu attentivement le manuel d'instruction de cet écran tactile et j'ai trouvé que la communication se fait par la lecture et l'écriture des adresses variables du contrôle, je devrais mettre un tampon dans mon code pour mémoriser ces adresses variables.


Message édité par ellis13 le 09-06-2021 à 03:36:25
Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed