Advertisement
neilguest

8 led chaser

Oct 9th, 2014
215
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 8 led chaser one direction with speed control via pot.
  2.  
  3.  
  4. int sensorValue = 0; //make a variable where you can store incoming
  5. //analog values
  6.  
  7. void setup(){
  8. pinMode(13, OUTPUT);
  9. pinMode(12, OUTPUT); //tell arduino what you'll be using these pins
  10. pinMode(11, OUTPUT); // for (output).
  11. pinMode(10, OUTPUT);
  12. pinMode(9, OUTPUT);
  13. pinMode(8, OUTPUT);
  14. pinMode(7, OUTPUT);
  15. pinMode(6, OUTPUT);
  16.  
  17. Serial.begin(9600); //initialize serial
  18. }
  19.  
  20. void loop(){ //we put the code we want executed in a loop
  21.  
  22. Serial.print("sensor = " ); //sends what's in quotes via serial
  23. Serial.println(sensorValue); //sends our variable (sensorValue)
  24. //via serial
  25.  
  26. digitalWrite(13,HIGH); // lights the led
  27. sensorValue = analogRead(0); // reads pin 0
  28. delay(sensorValue + 25); // sensorValue used for delay
  29. digitalWrite(13,LOW); //turns off the led
  30. delay(15); //delay before moving to next output pin
  31. //the + 25 keeps delay from reaching zero
  32. //code below is for remaining 4 LEDs
  33. digitalWrite(12,HIGH);
  34. sensorValue = analogRead(0);
  35. delay(sensorValue + 25);
  36. digitalWrite(12, LOW);
  37. delay(15);
  38.  
  39. digitalWrite(11,HIGH);
  40. sensorValue = analogRead(0);
  41. delay(sensorValue + 25);
  42. digitalWrite(11,LOW);
  43. delay(15);
  44.  
  45. digitalWrite(10,HIGH);
  46. sensorValue = analogRead(0);
  47. delay(sensorValue + 25);
  48. digitalWrite(10,LOW);
  49. delay(15);
  50.  
  51. digitalWrite(9,HIGH);
  52. sensorValue = analogRead(0);
  53. delay(sensorValue + 25);
  54. digitalWrite(9,LOW);
  55. delay(15);
  56.  
  57. digitalWrite(8, HIGH);
  58. sensorValue = analogRead(0);
  59. delay(sensorValue + 25);
  60. digitalWrite(8, LOW);
  61. delay(15);
  62.  
  63.  
  64.  
  65. digitalWrite(7,HIGH);
  66. sensorValue = analogRead(0);
  67. delay(sensorValue + 25);
  68. digitalWrite(7,LOW);
  69. delay(15);
  70.  
  71. digitalWrite(6,HIGH);
  72. sensorValue = analogRead(0);
  73. delay(sensorValue + 25);
  74. digitalWrite(6,LOW);
  75. delay(15);
  76.  
  77.  
  78.  
  79. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement