Advertisement
DrAungWinHtut

VoidFunctionwithMultipleLEDs.ino

Aug 24th, 2022
2,022
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // C++ code
  2. //
  3. void setup()
  4. {
  5.   pinMode(2, OUTPUT); //red
  6.   pinMode(3, OUTPUT); //yellow
  7.   pinMode(4, OUTPUT); //orange
  8.   pinMode(5, OUTPUT); //blue
  9.   pinMode(6, OUTPUT); //green
  10.   pinMode(7, OUTPUT); //white
  11. }
  12.  
  13. void loop()
  14. {
  15.   //Red LED ON and OFF once
  16.   funRedLedOnOff();  
  17.   //Yellow LED ON and OFF once
  18.   funYellowLedOnOff();  
  19.   //Orange LED ON and OFF once
  20.   funOrangeLedOnOff();  
  21.   //Blue LED ON and OFF once
  22.   funBlueLedOnOff();  
  23.   //Green LED ON and OFF once
  24.   funGreenLedOnOff();  
  25.   //White LED ON and OFF once
  26.   funWhiteLedOnOff();
  27.  
  28.  
  29.   funGreenLedOnOff();
  30.   funYellowLedOnOff();  
  31.   funRedLedOnOff();  
  32.   funWhiteLedOnOff();
  33.   funBlueLedOnOff();
  34.   funOrangeLedOnOff();
  35.  
  36.   funRedLedOn();
  37.   delay(1000);
  38.   funGreenLedOn();
  39.   delay(1000);
  40.   funAllLedOff();
  41.   delay(1000);
  42.  
  43.  
  44. }
  45.  
  46.  
  47.  
  48. void funRedLedOnOff()
  49. {
  50.   //Red LED ON and OFF once
  51.   digitalWrite(2, HIGH);
  52.   delay(500);           //wait 0.5 sec
  53.   digitalWrite(2, LOW);
  54.   delay(500);
  55. }
  56.  
  57. void funYellowLedOnOff()
  58. {
  59.   digitalWrite(3, HIGH);
  60.   delay(500);
  61.   digitalWrite(3, LOW);
  62.   delay(500);
  63. }
  64.  
  65. void funOrangeLedOnOff()
  66. {
  67.   digitalWrite(4, HIGH);
  68.   delay(500);
  69.   digitalWrite(4, LOW);
  70.   delay(500);
  71. }
  72.  
  73. void funBlueLedOnOff()
  74. {
  75.   digitalWrite(5, HIGH);
  76.   delay(500);
  77.   digitalWrite(5, LOW);
  78.   delay(500);
  79. }
  80.  
  81. void funGreenLedOnOff()
  82. {
  83.   digitalWrite(6, HIGH);
  84.   delay(500);
  85.   digitalWrite(6, LOW);
  86.   delay(500);
  87. }
  88.  
  89. void funWhiteLedOnOff()
  90. {
  91.   digitalWrite(7, HIGH);
  92.   delay(500);
  93.   digitalWrite(7, LOW);
  94.   delay(500);
  95. }
  96.  
  97. void funRedLedOn()
  98. {
  99.   digitalWrite(2,HIGH);
  100. }
  101.  
  102. void funRedLedOff()
  103. {
  104.   digitalWrite(2,LOW);
  105. }
  106.  
  107. void funGreenLedOn()
  108. {
  109.   digitalWrite(6,HIGH);
  110. }
  111.  
  112. void funGreenLedOff()
  113. {
  114.   digitalWrite(6,LOW);
  115. }
  116.  
  117. void funAllLedOff()
  118. {
  119.   digitalWrite(2,LOW);
  120.   digitalWrite(3,LOW);
  121.   digitalWrite(4,LOW);
  122.   digitalWrite(5,LOW);
  123.   digitalWrite(6,LOW);
  124.   digitalWrite(7,LOW);
  125. }
  126.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement