How can u use 4*4 Keypad to set fan working temperature
What have you tried ?
Can you read single values from the keypad and print them as they are read ?
yes i can read single values from the keypad and print them as they are read
but the problem The temperature consists of two numbers
and i need to set the temperature value with the keypad
Set a variable to zero in preparation for reading the input
Read a numeric character from the keypad. If you have the keypad set up to return characters rather than numerical values then subtract '0' from the returned value to turn it into a real digit and add the result to the total. Read a second character, subtract '0', multiply the total by 10 and add the new digit. Carry on until you have read the required number of digits in the total
Try this out with pencil and paper to see the principle in action and post your code here that reads and prints the keypad input
i try it but it doesn't work
000000000.ino (1.68 KB)
You have not done as I suggested
For instance, I said
If you have the keypad set up to return characters rather than numerical values then subtract '0' from the returned value to turn it into a real digit
, but you did
n = pressedKey - 0 ; which is not the same thing at all
Please read what I suggested carefully. Did you work through it with pencil and paper ?
Read a character and if it is a numeric character ( >= '0' and <= '9') subtract '0' from it
Suppose that you press '3' then subtracting '0' will give you 3 (write a small sketch to prove that and read up on ASCII values)
The total will be 0 at this point so adding 3 gives a total of 3
Suppose that the next entry is '5'. Subtracting '0' gives 5
Multiply the current total by 10 to give 30 and add the 5 to get 35 which is what was entered
Keep going until the required number of digits has been entered
We specify two special keys:
- A key to start/re-start the input. For example, key "*"
- A key to terminate the input. For example, key "#"
And then:
- When the start/re-start character is pressed, reset String to empty.
- Read the pressed number characters in between start/re-start character and terminate character into a String.
- When the terminate character is pressed, convert String to INT using this function
You can refer to the Arduino - Keypad Password code
Good luck!