Pikir dan Rasa

cogito ergo sum

Tinkering #03 dengan printing array pada Arduino

leave a comment »

Lanjutan ketiga tinkering dengan Arduino, array & serial printing:

CODE:

 

const int BAUDRATE = 9600;

const int BESARBUFF = 7;

//char buff1[5] = {10,20,3,40,5};
char buff1[BESARBUFF];

char buff2[] = {10,20,'g',3,'N',40,'ab','ba',5};

void setup(){
  Serial.begin(BAUDRATE);
  
  isibuff1();
  
  const byte ukuran_buff1 = ( sizeof(buff1)/sizeof(char) );
  Serial.print("Besar ukuran buff1: ");
  Serial.print(ukuran_buff1,DEC);
  Serial.print(" atau ");
  Serial.println((int)ukuran_buff1);
  Serial.println();
  
  
  Serial.print("Isi dari buff1: ");
  printBuff(buff1, ukuran_buff1);
  
  Serial.println();
  
    
  Serial.print("Print dengan printbuff: ");
  printBuff(buff1, ( sizeof(buff1)/sizeof(char) ));

  Serial.print("Print dengan Serial.println: ");
  Serial.println((long)(buff1));      

  char *ptr;
  ptr = (buff1);
  Serial.print("Print dengan Serial.println ptr: ");
  Serial.println(ptr);
     
           
  Serial.print("Print dengan printbuffptr: ");
  printbuffptr(buff1);
      
  Serial.println();
      
  
}

void loop(){
}

void printBuff(char *alamatarray, const byte buffsize){
  for(byte i=0; i < buffsize; i++){
    Serial.print(alamatarray[i],DEC);
    if((buffsize-i)>1){
      Serial.print(",");
    }
  }
  Serial.println();
}

void clearBuff(char *alamatarrayclr, const byte buffsizeclr){
  for(byte i=0; i < buffsizeclr; i++){
    (alamatarrayclr[i]='\0'); // isi dengan "null character"
   }
}

void printbuffptr(char *data){
  //Serial.println();
  Serial.println(data);
  //Serial.println();
}

void isibuff1(){
  for (int i=0; i < BESARBUFF; i++){
    buff1[i] = (i * 10);
  }
}

 

 

Referensi:

http://www.arduino.cc/en/Reference/Array

http://arduino.cc/en/Serial/Println

http://arduino.cc/en/Reference/ASCIIchart


Written by sunupradana

January 1, 2012 at 11:52 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: