...

View Full Version : How to explode integer?



sonic656
01-14-2012, 11:45 AM
Hello. I'm programming Arduino in C and I want to know how to explode integer.... In PHP I just need to write:

$substring = explode($string, "");
please help me.

I tried to use:

charAt();


void setup() {
Serial.begin(9600);
}

void loop() {
int sensorValue = analogRead(A1);
analogWrite(A0, sensorValue);
int a = analogRead(A1);
String aa=(String)a;
int a1 = aa.charAt(1);
int a2 = aa.charAt(2);
int a3 = aa.charAt(3);
int a4 = aa.charAt(4);
Serial.println("char at 1:" + a1);
Serial.println("char at 2:" + a2);
Serial.println("char at 3:" + a3);
Serial.println("char at 4:" + a4);
Serial.println("");
Serial.println("sensor:" + sensorValue);
Serial.println("");
delay(1000);
}

but there was an error...it displays some crazy thigs in serial monitor :(



ş˝†:lŚ–}ľo/uk/gľpa/ď–^fž’ő){ńđC‡˝Ś˙.
b/s.ň mn\ŚŤđ]5�ăo
đD/k}Ł—ťžŢt˙ĺăśďqňmź\ułdĚwĎ7Őkţ>ɦUdŽľěV_Ć˝˙ďţĺr]ű}^Fw˘]oŁOő]źa=]Zňű8[ć\*lľ9Z$ń˙ťşřčńzű˙lŽL-űŹĘăH•qż‡ż&i—˛~0ť˝qżţ?>űu{ţ3ăźfsż~{‘ˇŹ�ĂŻQŐă*1ĺňďŁ~inŰżţ‡~o(gm^.:˝Ş7NłŮ}l›ć/űkź–tőcDͷvň NŞą”NkmW`˙_ŚwEĽĄĆs{eűŠĽűőěăľ6Ůę]2ŹőĚŐňXz[=ăŽň�Š.�U˙6FţĘC֮?N…ł*gMj9wm�f‰lăyK›VS/ďŁţ{˙— 5Ż_�?n†cW…
ő‡ľżc\oş˝?Ő*Ű`/~-Ď˙ęž/9}Dőm "KŰn|şGŻŇş—)ůůďociĄć}Űgg›Mk]ŽKŤgﯿEn߻n‡Ł›ş/›ćŻzűߵJń*B/t‚˙Ů7˙]~˙9n?›rĹžo~űłić3ůľkď[\}f`Ţ?‹˙˘Ě=>uĹůž5|Ă?uź~Ń|ŻzMs~u_ŽšnŤwŐŃ.?s›˘˙Ľ6sGľ;ŮGjGu&}Ok
ű™3<PeŢŕӷEwűhwĹwŇz;ďoŐű˙•ŕi>?Ĺfeł9űŮ…ďĎ*tŽ?Xľvnő”>tk*…hęĎę/ňh“~ˇűoĚĎż…P6ůXmo^


please is there any other way to explode integer?

Thank you in advance.

sonic656
01-14-2012, 01:00 PM
Ohh. I found the bug, but it is not working :( It is displaying some crazy numbers:


char at 1:54
char at 2:48
char at 3:0
char at 4:0

sensor:659


this is new code:


void setup() {
Serial.begin(9600);
}

void loop() {
int sensorValue = analogRead(A1);
analogWrite(A0, sensorValue);
int a = analogRead(A1);
String aa=(String)a;
int a1 = aa.charAt(1);
int a2 = aa.charAt(2);
int a3 = aa.charAt(3);
int a4 = aa.charAt(4);
Serial.print("char at 1:"); Serial.println(a1);
Serial.print("char at 2:"); Serial.println(a2);
Serial.print("char at 3:"); Serial.println(a3);
Serial.print("char at 4:"); Serial.println(a4);
Serial.println("");
Serial.print("sensor:"); Serial.println(sensorValue);
Serial.println("");
delay(100);
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum