Created
April 22, 2018 21:03
-
-
Save vilaca/0df3628692c43959d5add6a060b4c309 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Volume3.h" | |
#define speakerPin 9 | |
void setup() { | |
pinMode(2, OUTPUT); | |
pinMode(3, OUTPUT); | |
pinMode(4, OUTPUT); | |
pinMode(5, OUTPUT); | |
} | |
int n = -1, last = 0; | |
void loop() { | |
uint16_t volume = 1023; | |
int zz = ++n % 4 + 2; | |
digitalWrite(zz, HIGH); | |
uint16_t frequency = analogRead(zz) & (B11111 << 5); | |
uint16_t st = (1023 - analogRead(1)) / 8 + 1; | |
uint16_t pwm = (analogRead(0)& (B111111 << 4))+1; | |
int freq = frequency > last ? last : frequency; | |
int inc = (freq - last) / 8 / ((pwm * st) / 16); | |
for ( int i = 0; i < (pwm * st) / 16 ; i++) | |
{ | |
vol.tone(speakerPin, freq / 2 , volume); | |
delay(1); | |
if ( freq < frequency ) | |
{ | |
freq += inc + 2; | |
if ( freq > frequency ) freq = frequency; | |
} | |
} | |
vol.noTone(); | |
delay(((1023 - pwm)*st) / 16); | |
digitalWrite(zz, LOW); | |
last = frequency; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment