String to Int(MPR121 breakout board)

12 Aug 2011

I am using the example written by Anthony Buckton with the mpr121 breakout board. I have heavily modified the example and have setup the mbed to only recognize buttons zero through four. I am using button zero to cancel and return to a main menu screen, button one decrements a value displayed on a screen, button two increments a value displayed on a screen, and button three confirms the value that is chosen by a user.

I set up a variable lets call it, int pumpspeed=0;. When I increment(press and release button two) the value of "pumpspeed" the variable will increase by one and the sequence of numbers looks normal until I reach anything past nine; after that every value displayed is represented as A-F until reaching 10. The same behavior is exhibited after values 19, 29,39,... as well.

I recognize that the #include <string> directive is there, so, I am wondering what is the best way to convert these strings to ints or rather how to eliminate the A-F values from showing up before reaching the next sequential number? I have picked the three files apart and I have no idea why the int variables contain hex values.

13 Aug 2011

Since you haven't shared out any of your code, I am going to guess at what might be happening here. Is is possible that you are using a printf() to display this pumpseed variable and if so, does the format string contain a %x which will display the value in hexadecimal? Using %d in place of the %x would switch the output to decimal.

15 Aug 2011

That would be it! Thank you very much, sir. Parsing and Outputting the variable to a putc() for a serial controlled seven segment display.