Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. kconst int buttonPin1 = 2;
  2. const int buttonPin2 = 3;
  3. const int buttonPin3 = 4;
  4. const int buttonPin4 = 5;
  5. const int buttonPin5 = 6; // the pin that the pushbutton is attached to
  6. const int buttonPin6 = 7;
  7. const int buttonPin7 = 8;
  8. int sensorPin = A0;
  9.  
  10.  
  11. byte buttonsPin[5] = {2,3,4,5,6};
  12. const int ledPin = 13; // the pin that the LED is attached to
  13.  
  14. // Variables will change:
  15. int buttonPushCounter = 0; // counter for the number of button presses
  16. int buttonState1 = 0;
  17. int buttonState2 = 0;
  18. int buttonState3 = 0;
  19. int buttonState4 = 0;
  20. int buttonState5 = 0;
  21. int buttonState6 = 0;
  22. int buttonState7 = 0;
  23. // current state of the button
  24. int lastButtonState = 0; // previous state of the button
  25.  
  26. int speakerPin = 9;
  27. int timer = 100;
  28.  
  29. int firsttime = 1;
  30. unsigned long startTime;
  31. unsigned long pressTime;
  32.  
  33. void setup() {
  34. // initialize the button pin as a input:
  35. pinMode(buttonPin1, INPUT);
  36. pinMode(buttonPin2, INPUT);
  37. pinMode(buttonPin3, INPUT);
  38. pinMode(buttonPin4, INPUT);
  39. pinMode(buttonPin5, INPUT);
  40. pinMode(buttonPin6, INPUT);
  41. pinMode(buttonPin7, INPUT);
  42. // initialize the LED as an output:
  43. pinMode(ledPin, OUTPUT);
  44. // initialize serial communication:
  45. Serial.begin(9600);
  46. }
  47.  
  48.  
  49. void loop() {
  50. // read the state of the pushbutton value:
  51. buttonState1 = digitalRead(buttonPin1);
  52. buttonState2 = digitalRead(buttonPin2);
  53. buttonState3 = digitalRead(buttonPin3);
  54. buttonState4 = digitalRead(buttonPin4);
  55. buttonState5 = digitalRead(buttonPin5);
  56. buttonState6 = digitalRead(buttonPin6);
  57. buttonState7 = digitalRead(buttonPin7);
  58.  
  59. int sensorValue;
  60. int sensorValueMap;
  61.  
  62.  
  63. sensorValue = analogRead(sensorPin);
  64. sensorValueMap = map(sensorValue, 0, 1023, 1,20);
  65.  
  66. Serial.println(sensorValueMap);
  67.  
  68. if (buttonState1 == HIGH) {
  69. // turn LED on:
  70. tone(speakerPin, 1047 * sensorValueMap / 10, 50);
  71. }
  72.  
  73. if (buttonState2 == HIGH) {
  74. // turn LED on:
  75. tone(speakerPin, 1175 * sensorValueMap / 10, 50);
  76. }
  77.  
  78. if (buttonState3 == HIGH) {
  79. // turn LED on:
  80. tone(speakerPin, 1319 * sensorValueMap / 10, 50);
  81. }
  82.  
  83. if (buttonState4 == HIGH) {
  84. // turn LED on:
  85. tone(speakerPin, 1397 * sensorValueMap / 10, 50);
  86. }
  87.  
  88. if (buttonState5 == HIGH) {
  89. // turn LED on:
  90. tone(speakerPin, 1568 * sensorValueMap / 10, 50);
  91. }
  92.  
  93.  
  94.  
  95. if (buttonState6 == HIGH) {
  96. // turn LED on:
  97. tone(speakerPin, 1760 * sensorValueMap / 10, 50);
  98. }
  99.  
  100.  
  101. if (buttonState7 == HIGH) {
  102. // turn LED on:
  103. tone(speakerPin, 1976 * sensorValueMap / 10, 50);
  104. }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement