Advertisement
DrAungWinHtut

Untitled

Feb 12th, 2023
1,063
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // C++ code
  2. //
  3. int status = 0;
  4.  
  5. void setup()
  6. {
  7.   pinMode(2, INPUT);
  8.   pinMode(3, INPUT);
  9.   pinMode(4, INPUT);
  10.   pinMode(5, OUTPUT);
  11.   pinMode(6, OUTPUT);
  12.   pinMode(7, OUTPUT);
  13.   Serial.begin(9600);
  14. }
  15.  
  16. void loop()
  17. {
  18.   int pattern =0; //1,2,3
  19.  
  20.   int input1 = digitalRead(2);
  21.   int input2 = digitalRead(3);
  22.   int input3 = digitalRead(4);
  23.   Serial.print("Input1 = ");
  24.   Serial.println(input1);
  25.   Serial.print("Input2 = ");
  26.   Serial.println(input2);
  27.   Serial.print("Input3 = ");
  28.   Serial.println(input3);
  29.  
  30.  
  31.   if(input1==HIGH)
  32.   {
  33.     pattern = 1;
  34.   }
  35.   else if(input2==HIGH)
  36.   {
  37.     pattern = 2;
  38.   }
  39.   else if(input3==HIGH)
  40.   {
  41.     pattern = 3;
  42.   }
  43.  
  44.   if(pattern!=0)
  45.   {
  46.     status=pattern;
  47.   }
  48.  
  49.  
  50.   Serial.print("pattern = ");
  51.   Serial.println(pattern);
  52.   Serial.print("status = ");
  53.   Serial.println(status);
  54.  
  55.   ledDance(status);
  56.  
  57. }
  58.  
  59.  
  60.  
  61. void ledDance(int p)
  62. {
  63.   switch(p)
  64.   {
  65.     case 1: seqOne(); break;
  66.     case 2: seqTwo(); break;
  67.     case 3: seqThree(); break;
  68.   }
  69. }
  70.  
  71.  
  72.  
  73. void seqOne()
  74. {
  75.   digitalWrite(5,HIGH);
  76.   delay(1000);
  77.   digitalWrite(5,LOW);
  78.   delay(1000);
  79.  
  80.   digitalWrite(6,HIGH);
  81.   delay(1000);
  82.   digitalWrite(6,LOW);
  83.   delay(1000);
  84.  
  85.   digitalWrite(7,HIGH);
  86.   delay(1000);
  87.   digitalWrite(7,LOW);
  88.   delay(1000);
  89. }
  90.  
  91. void seqTwo()
  92. {
  93.   digitalWrite(7,HIGH);
  94.   delay(1000);
  95.   digitalWrite(7,LOW);
  96.   delay(1000);
  97.  
  98.   digitalWrite(6,HIGH);
  99.   delay(1000);
  100.   digitalWrite(6,LOW);
  101.   delay(1000);
  102.  
  103.   digitalWrite(5,HIGH);
  104.   delay(1000);
  105.   digitalWrite(5,LOW);
  106.   delay(1000);
  107. }
  108.  
  109.  
  110.  
  111. void seqThree()
  112. {
  113.   seqOne();
  114.   seqTwo();
  115. }
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement