Advertisement
Cardwell

Arduinodrit

Apr 11th, 2018
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1.  
  2. int bitbut1 = 2;
  3. int bitbut2 = 3;
  4. int bitbut3 = 4;
  5. int led1 = 5; //Forteller hvilken enhet som er på hvilken port
  6. int led2 = 6;
  7. int led3 = 7;
  8. int led4 = 8;
  9. int led5 = 9;
  10. int led6 = 10;
  11. int led7 = 11;
  12. int but1 = 12;
  13. int nummer;
  14. int a;
  15. int b;
  16. int c;
  17.  
  18. void setup() {
  19.  
  20. pinMode(led1, OUTPUT); //Definerer LED-pins som outputs
  21. pinMode(led2, OUTPUT);
  22. pinMode(led3, OUTPUT);
  23. pinMode(led4, OUTPUT);
  24. pinMode(led5, OUTPUT);
  25. pinMode(led6, OUTPUT);
  26. pinMode(led7, OUTPUT);
  27. pinMode(but1, INPUT_PULLUP);
  28. pinMode(bitbut1, INPUT_PULLUP);
  29. pinMode(bitbut2, INPUT_PULLUP);
  30. pinMode(bitbut3, INPUT_PULLUP);
  31. }
  32.  
  33. void loop() {
  34. if(digitalRead(but1) == LOW) //Sjekk om knappen er trykket inn
  35. {
  36.  
  37. a = digitalRead(bitbut1);
  38. b = digitalRead(bitbut2);
  39. c = digitalRead(bitbut3);
  40.  
  41. nummer = (a*1)+(b*2)+(c*4);
  42.  
  43. //loops();
  44. if (nummer == 7){
  45. terning7(); }
  46.  
  47. if (nummer == 6){
  48. terning6(); }
  49.  
  50. if (nummer == 5){
  51. terning5(); }
  52.  
  53. if (nummer == 4){
  54. terning4(); }
  55.  
  56. if (nummer == 3){
  57. terning3(); }
  58.  
  59. if (nummer == 2){
  60. terning2(); }
  61.  
  62. if (nummer == 1){
  63. terning1(); }
  64. }
  65. }
  66.  
  67.  
  68.  
  69. void alloff() {
  70. delay(1000);
  71. digitalWrite(led1, LOW);
  72. digitalWrite(led2, LOW);
  73. digitalWrite(led3, LOW);
  74. digitalWrite(led4, LOW);
  75. digitalWrite(led5, LOW);
  76. digitalWrite(led6, LOW);
  77. digitalWrite(led7, LOW);
  78. }
  79.  
  80.  
  81. void terning1() {
  82. digitalWrite(led4, HIGH);
  83. delay(250);
  84. alloff();
  85. }
  86.  
  87. void terning2() {
  88. digitalWrite(led1, HIGH);
  89. digitalWrite(led2, HIGH);
  90. delay(250);
  91. alloff();
  92. }
  93.  
  94. void terning3() {
  95. digitalWrite(led1, HIGH);
  96. digitalWrite(led4, HIGH);
  97. digitalWrite(led7, HIGH);
  98. delay(250);
  99. alloff();
  100. }
  101.  
  102. void terning4(){
  103. digitalWrite(led1, HIGH);
  104. digitalWrite(led2, HIGH);
  105. digitalWrite(led6, HIGH);
  106. digitalWrite(led7, HIGH);
  107. delay(250);
  108. alloff();
  109. }
  110.  
  111. void terning5() {
  112. digitalWrite(led1, HIGH);
  113. digitalWrite(led2, HIGH);
  114. digitalWrite(led6, HIGH);
  115. digitalWrite(led7, HIGH);
  116. digitalWrite(led4, HIGH);
  117. delay(250);
  118. alloff();
  119. }
  120.  
  121. void terning6() {
  122. digitalWrite(led1, HIGH);
  123. digitalWrite(led2, HIGH);
  124. digitalWrite(led3, HIGH);
  125. digitalWrite(led5, HIGH);
  126. digitalWrite(led6, HIGH);
  127. digitalWrite(led7, HIGH);
  128. delay(250);
  129. alloff();
  130. }
  131.  
  132. void terning7() {
  133. digitalWrite(led1, HIGH);
  134. digitalWrite(led2, HIGH);
  135. digitalWrite(led3, HIGH);
  136. digitalWrite(led4, HIGH);
  137. digitalWrite(led5, HIGH);
  138. digitalWrite(led6, HIGH);
  139. digitalWrite(led7, HIGH);
  140. delay(250);
  141. alloff();
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement