Advertisement
Guest User

Arduino Play Code by Acey

a guest
Nov 25th, 2014
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. /*
  2. Blink
  3. Turns on an LED on for one second, then off for one second, repeatedly.
  4.  
  5. Most Arduinos have an on-board LED you can control. On the Uno and
  6. Leonardo, it is attached to digital pin 13. If you're unsure what
  7. pin the on-board LED is connected to on your Arduino model, check
  8. the documentation at http://arduino.cc
  9.  
  10. This example code is in the public domain.
  11.  
  12. modified 8 May 2014
  13. by Scott Fitzgerald
  14. */
  15.  
  16. int led1 = 13;
  17. int led2 = 12;
  18. int led3 = 11;
  19. int led4 = 10;
  20. int led5 = 9;
  21. int led6 = 8;
  22.  
  23. int buzzer = 3;
  24.  
  25.  
  26. // the setup function runs once when you press reset or power the board
  27. void setup() {
  28. // initialize digital pin 13 as an output.
  29. pinMode(led1, OUTPUT);
  30. pinMode(led2, OUTPUT);
  31. pinMode(led3, OUTPUT);
  32. pinMode(led4, OUTPUT);
  33. pinMode(led5, OUTPUT);
  34. pinMode(led6, OUTPUT);
  35. pinMode(buzzer, OUTPUT);
  36. }
  37.  
  38. // the loop function runs over and over again forever
  39. void loop() {
  40. int lightSensor = digitalRead(7);
  41. digitalWrite(led4, !lightSensor);
  42. analogPitch();
  43. analogBrightness();
  44. }
  45.  
  46. void singleLightBlink(int light) {
  47. digitalWrite(light, HIGH); // turn the LED on (HIGH is the voltage level)
  48. delay(1000); // wait for a second
  49. digitalWrite(light, LOW); // turn the LED off by making the voltage LOW
  50. delay(1000);
  51. }
  52.  
  53. void lightSequence(int light, int delayTimer) {
  54. flash(light, 50);
  55. delay(500);
  56. flash(light, 50);
  57. delay(500);
  58. flash(light, 50);
  59. delay(100);
  60. flash(light, 50);
  61. delay(500);
  62. flash(light, 50);
  63. }
  64.  
  65. void lightSequence2(int delayTimer) {
  66. flash(led1);
  67. delay(delayTimer);
  68. flash(led2);
  69. delay(delayTimer);
  70. flash(led3);
  71. delay(delayTimer);
  72. flash(led4);
  73. delay(delayTimer);
  74. flash(led5);
  75. delay(delayTimer);
  76. flash(led6);
  77. delay(delayTimer);
  78. }
  79.  
  80. void analogPitch() {
  81. digitalWrite(led2, HIGH);
  82. int pitch = analogRead(A5);
  83. tone(buzzer, pitch, 20);
  84. delay(10);
  85. }
  86.  
  87. void analogBrightness() {
  88. int lightSensor = analogRead(A5);
  89. analogWrite(led6, lightSensor);
  90. }
  91.  
  92. void flash (int light) {
  93. digitalWrite(light, HIGH);
  94. delay(50);
  95. digitalWrite(light, LOW);
  96. }
  97.  
  98. void flash(int light, int liveTime) {
  99. digitalWrite(light, HIGH);
  100. delay(liveTime);
  101. digitalWrite(light, LOW);
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement