Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- kconst int buttonPin1 = 2;
- const int buttonPin2 = 3;
- const int buttonPin3 = 4;
- const int buttonPin4 = 5;
- const int buttonPin5 = 6; // the pin that the pushbutton is attached to
- const int buttonPin6 = 7;
- const int buttonPin7 = 8;
- int sensorPin = A0;
- byte buttonsPin[5] = {2,3,4,5,6};
- const int ledPin = 13; // the pin that the LED is attached to
- // Variables will change:
- int buttonPushCounter = 0; // counter for the number of button presses
- int buttonState1 = 0;
- int buttonState2 = 0;
- int buttonState3 = 0;
- int buttonState4 = 0;
- int buttonState5 = 0;
- int buttonState6 = 0;
- int buttonState7 = 0;
- // current state of the button
- int lastButtonState = 0; // previous state of the button
- int speakerPin = 9;
- int timer = 100;
- int firsttime = 1;
- unsigned long startTime;
- unsigned long pressTime;
- void setup() {
- // initialize the button pin as a input:
- pinMode(buttonPin1, INPUT);
- pinMode(buttonPin2, INPUT);
- pinMode(buttonPin3, INPUT);
- pinMode(buttonPin4, INPUT);
- pinMode(buttonPin5, INPUT);
- pinMode(buttonPin6, INPUT);
- pinMode(buttonPin7, INPUT);
- // initialize the LED as an output:
- pinMode(ledPin, OUTPUT);
- // initialize serial communication:
- Serial.begin(9600);
- }
- void loop() {
- // read the state of the pushbutton value:
- buttonState1 = digitalRead(buttonPin1);
- buttonState2 = digitalRead(buttonPin2);
- buttonState3 = digitalRead(buttonPin3);
- buttonState4 = digitalRead(buttonPin4);
- buttonState5 = digitalRead(buttonPin5);
- buttonState6 = digitalRead(buttonPin6);
- buttonState7 = digitalRead(buttonPin7);
- int sensorValue;
- int sensorValueMap;
- sensorValue = analogRead(sensorPin);
- sensorValueMap = map(sensorValue, 0, 1023, 1,20);
- Serial.println(sensorValueMap);
- if (buttonState1 == HIGH) {
- // turn LED on:
- tone(speakerPin, 1047 * sensorValueMap / 10, 50);
- }
- if (buttonState2 == HIGH) {
- // turn LED on:
- tone(speakerPin, 1175 * sensorValueMap / 10, 50);
- }
- if (buttonState3 == HIGH) {
- // turn LED on:
- tone(speakerPin, 1319 * sensorValueMap / 10, 50);
- }
- if (buttonState4 == HIGH) {
- // turn LED on:
- tone(speakerPin, 1397 * sensorValueMap / 10, 50);
- }
- if (buttonState5 == HIGH) {
- // turn LED on:
- tone(speakerPin, 1568 * sensorValueMap / 10, 50);
- }
- if (buttonState6 == HIGH) {
- // turn LED on:
- tone(speakerPin, 1760 * sensorValueMap / 10, 50);
- }
- if (buttonState7 == HIGH) {
- // turn LED on:
- tone(speakerPin, 1976 * sensorValueMap / 10, 50);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement