string to int (pwm)


i've posted question in software interfacing part, think problem more on arduino hardware/software side.

i try convert string 000 255 value pwm output.
i use method below, other pwm outputs react on changes on output.

maybe code isn't efficient enough.

is there way convert string or hexicadecimal values ( 00-ff ) output value standard arduino library ?
from string int or someting.

code: [select]

if (serinstring[0]==73)  // i
{ (int i=1; <= digseq; i++)
 { if (serinstring[i]==',')
   { p++;
     i++;
     }    
   char valchar=serinstring[i];
     if(p==8 || p==12 || p==13)                        // digital outputs
     { // other code      
     }
     else                                           // pwm outputs
     { valpwm = 0;
       valpwm = (serinstring[i]-48)*100;
       valpwm = valpwm + (serinstring[i+1]-48)*10;
       valpwm = valpwm + (serinstring[i+2]-48);
     
       i=i+2;                                    
       analogwrite(p,valpwm);                   
     }
 }  
}

you can use standard c library function atoi(). takes string in decimal , returns integer. checked , adds 120 bytes sketch.


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > string to int (pwm)


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums