I like to know how count the received values from. Im using an 4x4 keypad, and AVR studio as compiler
for example if I press button "1" I receive a "1" but if I press button "1" again it should be an "11" and not a "2",
int inputcounter;
if (button = 00x1)
{ // what should i do instead of
inputcounter++ to get "11" and not "2"
}
Thank you.
Based on the comment instead of inputcounter++, it sounds like you are trying to use a numeric value.
So you need to do:
inputcounter = (inputcounter * 10) + newvalue;
I'm assuming you are trying to read in a key sequence and compare it to a sequence stored in the microcontroller's memory (a secret code, for example). You have two easy ways of doing this.
Use an array. Each time a new input arrives, place it in the next array slot until you have read in your max number of input button presses.
Pack the keystrokes into a single number. Assuming your keypad returns 1 when 1 is pressed, 2 when 2 is pressed, etc, you can use an integer to track input. Initialize the variable to zero. Whenever an input comes in, multiply the variable's current value by 16 and add the incoming digit. Since you have a 4x4 keypad, you will have to treat incoming keystrokes as hexidecimal digits, not decimal digits (the other suggestions that multiply by 10 will limit you to only using 10 out of your 16 available buttons).
The number of keys you can track at a time will depend on how many long you declare your array (for option #1) or what size variable you use (for option #2).
Related
I am implementing an input, where the user should type number in the following format: 12/34/56. I have found that react-input-mask allows to do so. But my question now is how to make the mask either require the user to fully enter the number (to remove such cases 1_/3_/_5) or add zeros where the number wasn't entered.
Also, another thing I think of is to allow either one or two digits, but I haven't seen documentation on this in react-input-mask
I am willing to choose another mask library, if you know it can be done so.
I figured it out. There is a property called maskChar, if you set it to null, e.g <InputMask maskChar={null} mask="99/99/99" /> won't allow user to proceed to second number, without filling both digits.
I am receiving 128 byte data continuously every second from serial,
I just want to know how can I replace this data to the starting index for each iteration in my byte array?
how can I do it?
-Thanks
I created an byte array and feed my serial string output to it via string to byte array converter
You could implement circular buffer in this way:
If I understand correctly you want to see the current iteration in the Array Indicator
If so, just place the Array Indicator inside the loop
Note that the Array indicator and the wire connected to it is not the same data type, there is a convert, you can see that it's different colors (orange and blue) and there is red dot where it's connected.
But if you want to collect all the data you received you should right click on your loop output and select Indexing
You would also need to change your indicator, just delete the current one and than right click on the wire -> create -> Indicator.
Or Hirshfeld
Control SW Engineer
Im creating a simple program that will compare user input to a predetermined string (for memorization help). So far, after the user pushes space a code will run to break the user input text into individual characters (in an array) to test it against the original.
When the user pushes space and one of the letters is wrong, I want that letter to turn a different color. Is there any way to store htmlText in an array, or can anyone think of a way to make that letter turn the color?
Is there any way to write the program at all? Am I able to keep the text in a string and compare it (the spaces and punctuation need to be ignored)?
You can change color without htmlText.
Use setTextFormat.
example:
var format:TextFormat = textField.getTextFormat(wrongLetterBeginIndex, wrongLetterEndIndex);
format.color = 0xFF0000;
textField.setTextFormat(format, wrongLetterBeginIndex, wrongLetterEndIndex);
I want to develop a custom user control in WPF which has some sort of mask. this functionality is very like the one provided in many online applications where u enter your credit card number and next time whenever u sign in to your account u see only last for digits of the card number (something like ***4587) but while I display data in this way I want to keep real value unchanged so inside binding I will access full data.
You could try something like this:
string originalNumber = textBoxOriginalNumber.Text;
int numberOfDigits = textBoxOriginalNumber.Text.Length;
string hidden = new String('*', numberOfDigits-4);
textBoxModifiedNumber.Text = hidden + originalNumber.Remove(0, numberOfDigits-4);
It's is not an elegant solution but will help you if anybody else give you a better solution. Basically, it takes the original credit card number, counts how many digits it has, removes the "n-4" first digits, then show the * symbol "n-4" times plus the four last digits. This will work no matter how many digits the original number has.
Additionally, I'm not sure if a mask (or the Regex suggested by the other user bellow) would work because (if I understood it well) it would replace the whole number, instead of show the last 4 digits.
OK here is the way I resolved that issue. after working with Card numbers I wanted to work with ID and SN numbers as well so what I did was just wrote little method which takes in string and returns masked value here it is in case someone needs this in feature.
public static string GetMaskedNumber(string unsecuredNumber, char maskChar)
{
return unsecuredNumber.Substring(unsecuredNumber.Length - 4)
.PadLeft(unsecuredNumber.Length - 6, ' ')
.PadLeft(unsecuredNumber.Length, maskChar);
}
You could use Regex.Replace with \d to indicate a digit
i.e.
var digits = new Regex(#"\d");
modifiedNumber = digits.Replace(originalNumber, "*");
Or if you want to update the whole set of numbers except for the last group
#"\d{4}-"
I have a small WIN32 C-Application in which i work with the KBDLLHOOKSTRUCT structure. This structure contains the VK-Code for a pressed key.
I try to convert this to an ASCII-Character. For this i use the Function MapVirtualKey, which works well.
The only problem is, that one VK-Code can stay for multiple chars.
Example:
On my keyboard (Swiss-German) exists the key-char .. If i press Shift+. then it creates a :. The VK-Code is the same. Thats no problem, and i can also check if Shift is pressed or Caps Lock is activated.
My only problem is: How can i get the char ':'?
I need a function like this:
GetKeyChar(vkCode, shift)
I need this to get the "normal" and the "shifted" value of the keyboard. Of course i could hardcode this, but i don't like to do it on this way.
The problem is that the KBDLLHOOKSTRUCT doesn't have all the information you need in order to do the translation. You get a message every time a key is pressed. So for Shift+X, you'll get an input message saying that the Shift key was pressed, and another message saying that the "X" key was pressed.
You need to call GetKeyboardState in order to get the state of the Shift, Alt, Ctrl, (and perhaps other) keys. Then call ToAsciiEx or ToUnicodeEx.
You're looking for ToUnicode, which returns the unicode character generated by that keypress.
The functions you are looking for are: ToAscii, ToAsciiEx, ToUnicode, ToUnicodeEx.
short VkKeyScan(char ch) API has contained the shift information. It translate char to virtual-key code and shift state.
See this: Convert character to the corresponding virtual-key code