This is probably pretty basic for most of you guys, but I haven’t figured it out yet.
Let’s say I got a number above 10, and I want to split said number, for example:
and I want to split it to:
Number 1: 1
Number 2: 3
number 3: 3
number 4: 7
I want to be able to select a specific number, got it?
Any ideas? BTW I’m programming for an Arduino.
I'd like to know how to do both. But first of all I need to seperate numeral values.
Most sensors gives me numeral inputs.
If I want to "write back" to the Arduino, lets say a numeric value, I'd like it to be able to assign different values to different places.
I got this 4 digit 7-segment display hooked up, directly to my Arduino.
Soon I'm going to use a shift register to drive it, (as I recently learned how to use a shift register).
Point is, I'm testing it out, and if I write numerals on the Serial Monitor, I want it to be able to display it.
Like if I write 1337, I want the Arduino to display this.
That would go ok, but I can only assign 1 value per digit on the display. I can't tell the display to write "1337" on one digit.
So I need it to split it up and assign it to different digits.
By the way, someone might know why, but for some odd reason, every time I write the "Serial.begin(9600)" into the Arduino code, my first 2 digits on the display becomes blurry. Why is this?
101 = 10
102 = 100
103 = 1000
I don't follow. How's this helping my problem? (Ok, I'm a bit fresh to this, call me a n00b or whatnot, but do you have any example code?)
Btw, I figured out why my 2 digits became blurry, and the problem has been taken care of.
1337 % 10 = 7
1337 / 10 % 10 = 3
1337 / 100 % 10 = 3
1337 / 1000 % 10 = 1
Then comes my next question:
Except writing a program in say.. processing, what is the shortest way to get the Arduino to understand a 1 (Byte) as a 1 (text) ?
If I use the Serial Monitor, I will be sending 1337 as BYTE.
I need to be receiving it like plain text.
Either that, or I'm going to need to start using processing again, to test this out.
when you receive 1 as byte add the value 0 as char
byte c = Serial.read();
c = c + '0';
Please spend some time in the reference section and the tutorial section of arduino.cc as there is an amazing about of knowledge, samples etc to learn from. Time spend there is no waste of time...
Not sure on the specifics of the arduino c/c++ derivative, but I'd start with type casting from int to char or string.
I was needing something similar the other day, but never investigated.
Is type casting an option?
So you want to make a string into a complete number?
char yourstring =('1', '2', '3', '4'];
and have the output be = 1234?
but I'd start with type casting from int to char or string.
That might be useful for splitting into pairs of hex digits, but unless the number was expressed in BCD, not much use for decimal.