Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int beepPin = 9;
- int toneValue = 50;
- int rotaryPinA = 1;
- int rotaryPinB = 2;
- int rotaryReadA;
- int rotaryReadB;
- int rotaryReadAPrev = 0;
- unsigned long currentTime;
- unsigned long loopTime;
- void setup()
- {
- Serial.begin(9600);
- pinMode(beepPin, OUTPUT);
- pinMode(rotaryPinA, INPUT);
- pinMode(rotaryPinB, INPUT);
- currentTime = millis();
- loopTime = currentTime;
- }
- void loop()
- {
- currentTime = millis();
- if (currentTime >= (loopTime + 5))
- {
- rotaryReadA = digitalRead(rotaryPinA);
- rotaryReadB = digitalRead(rotaryPinB);
- Serial.print("A");
- Serial.println(rotaryReadA);
- Serial.print("B");
- Serial.println(rotaryReadB);
- if ((!rotaryReadA) && (rotaryReadAPrev))
- {
- if (rotaryReadB)
- {
- toneValue += 50;
- Serial.println("+");
- }
- else
- {
- toneValue -= 50;
- Serial.println("-");
- }
- }
- rotaryReadAPrev = rotaryReadA;
- beep(toneValue, 100);
- loopTime = currentTime;
- }
- }
- void beep(int toneValue, int delayTime)
- {
- analogWrite(beepPin, toneValue);
- delay(delayTime);
- analogWrite(beepPin, 0);
- delay(delayTime * 15);
- }
Add Comment
Please, Sign In to add comment