- Код: Выделить всё
int val=0;// A variable to store the value calculated based on the binary inputs q1 to q4.Переменная для сохранения значения, рассчитанного на основе двоичных входов q1 - q4
const int set_pass[]={1,2,3,4}; // The DTMF Value for 4 Digits of Password [Remember in DTMF Values 0 => 10, * =>11 & #=> 12]
int recvd_pass[4]; // a variable to store the password received. Переменная для хранения полученного пароля.
boolean login_flag = 0; // a flag variable to store the log in status of the user
int count = 0; // a variable to count the number of digits entered. Переменная для подсчета числа введенных цифр.
long int first_press_time = 0; // переменная,для хранения времени, оставшегося после нажатия первой кнопки
void setup()
{
pinMode(2,INPUT); // Steered delay Pin (INT 0)
pinMode(3,INPUT); // q1
pinMode(4,INPUT); // q2
pinMode(5,INPUT); // q3
pinMode(6,INPUT); // q4
attachInterrupt(0,dtmf,RISING); // Включение пина прерывания, связь его с функцией ISR dtmf и настройка его для запуска по прерыванию RISING
//Serial.begin(9600); // Включить монитор порта для отладки
pinMode(11,OUTPUT); // LED for login indication
pinMode(12,OUTPUT); // LED for Reset indication
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
}
void loop()
{
// Если новое значение получено, распечатать его в последовательный монитор для отладки
if(val>0)
{
Serial.println(val);
}
// Проверка условий сброса. Либо время прошедшее от первого нажатия более 10 секунд, либо пользователь нажал клавишу «#» в режиме выхода из системы
if((count>0 && (millis()-first_press_time)>6000)||(login_flag==0 && val==12))
{
count = 0; // reset count
Serial.println("RESET"); // print reset message
val = 0; // reset val to '0' as so that we can distinguish when a new value is received. Сброс val до '0', чтобы мы могли отличить, когда получено новое значение.
digitalWrite(12,HIGH); // led indication for reset
delay(1000);
digitalWrite(12,LOW);
}
//Get four digit input to check for login, ensure that the user is not already logged in and that 4 digits have not been input already.
//Получение четырехзначного кода для проверки входа в систему, убеждаемся, что пользователь еще не зарегистрирован и что 4 цифры уже не введены.
if(login_flag==0 && count< 4 && val>0)
{
recvd_pass[count] = val; // store the value into an array for comparing once all the 4 digits are received. Сохраняем значение в массиве для сравнения после получения всех четырех цифр
val = 0; // reset val to '0' as so that we can distinguish when a new value is received. Сброс val до '0', чтобы мы могли отличить, когда получено новое значение.
if(count==0) // if this is the first key press then store the time for calculating time out. Если это первое нажатие клавиши, тогда сохраняем время для расчета тайм-аута
{
first_press_time = millis();
}
count++; // increment count
Serial.print("Count : ");Serial.println(count); // print count value for debug
if(count==4) // if count is 4, then we need to match the password received to the passwors stored
{
if(recvd_pass[0]==set_pass[0] && recvd_pass[1]==set_pass[1] && recvd_pass[2]==set_pass[2] && recvd_pass[3]==set_pass[3]) // check if passwords match
{
login_flag = 1; // if matched set the login flag
digitalWrite(11,HIGH); // and turn on the indication led
}
else
{
digitalWrite(12,HIGH); // if passwords dont match, show the reset indication
delay(1000);
digitalWrite(12,LOW);
}
count = 0;// on reaching 4, count has to be reset to 0. При достижении 4, счет должен быть сброшен до 0
}
}
// logged in activities
if(login_flag==1) // if the user is logged in then the keys pressed are treated differently
{
switch(val) // check which key is pressed
{
case 1: digitalWrite(8,HIGH); break; // turn on the 13th pin led when '1' is pressed
case 2: digitalWrite(8,LOW); break;// turn off the 13th pin led when '0' is pressed
case 4: digitalWrite(9,HIGH); break; // turn on the 13th pin led when '1' is pressed
case 8: digitalWrite(9,LOW); break;// turn off the 13th pin led when '0' is pressed
case 12: digitalWrite(11,LOW); login_flag=0; break; // Log out the user, set the login flag to false and turn off the login status led
}
val = 0; // reset val to '0'
}
}
void dtmf() // the ISR - this function is called everytime a RISING interrupt occurs on PIN 2 (INT 0)
{
for(int i=0;i<4;i++) // Once we receive an Interrupt, we need to read each of q1 to q4, with q1 being the LSB and q4 the MSB
{
if(digitalRead(i+3)==1)// check if the pin is 1 or 0, if 1 then we need to process for binary to decimal conversion
{
val = val + (1<<i); // Binary to decimal conversion
}
}
}
Здравствуйте! Есть такой код. Соединяю плату про мини 168 и дтмф декодер mt8870. Питание 5в через усб-ком переходник. При вводе цифр на клавиатуре телефона частые пропуски по декодированию сигнала платой про мини. Сам модуль мт8870 тоже иногда не понимает дтмф сигнал на входе. На пинах q1-q4, при наличии единицы, на них-3,7в. На пине stq импульс максимум-2,7в.
Куда смотреть? Уменьшать сопротивление на входе мт8870? Ставить транзисторные ключи с выводов q1-q4 и stq? По другому распознавать двоичный код в про мини?