Arduino – BUZZER
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
int val=0; int sw1=2; int count=0; int tones[8]={523, 587, 659, 699, 784, 880, 988, 1047}; void setup() { Serial.begin(9600); pinMode(sw1, INPUT); } void loop() { val=analogRead(A4); count=map(val, 0, 1023, 0, 7); Serial.print("Volume : "); Serial.print(val); Serial.print(", Count : "); Serial.println(count); if (digitalRead(sw1)) { tone(6, tones[count]); } else { noTone(6); } } |