i hve code about intergrated keypad and arduino, i put random tone in one key with infinite loop, but i cannot stop that tone ,, please help me
this is my code
#include <toneAC.h>
#include <Keypad.h>
int acak;
int vol=10;
char key1;
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {2,3,4,5}; //connect to row pinouts
byte colPins[COLS] = {6,7,8,12}; //connect to columnpinouts
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
//Serial.begin(9600);
}
void loop()
{
//int vol=10;
char key = keypad.getKey();
if(key) // Check for a valid key.
{
switch (key)
{
//this is what i want to stop
case 'D':
while(key!='0'){
//key1 = keypad.getKey();
acak=random(10000,19000);
toneAC(acak,vol);
delay(5000);
}
break;
case '*':
noToneAC() ;
if(vol>1){
vol=vol-1;
}
break;
case '#':
noToneAC() ;
if(vol<10){
vol=vol+1;
}
break;
default:
noToneAC() ;
Serial.println(key);
}
}
}