跳到主要內容
選修分組-專題 / 選手訓練 / 0926- scanf ( ) an integer number

1

 

int scanf_int( char *str1 ); //函數原型宣告
//----------------------------------------------------------------
void setup ()
{
  Serial.begin( 115200 );
  while ( !Serial );  //wait for UART ready
  Serial.println("Hello World!\n");
}
char buf[128]; //for sprinf() function
void loop()
{  
  int a = scanf_int ( "Input a number:" );
  sprintf( buf, "\n value= %d", a );
  Serial.println( buf );
}

 
int scanf_int( char *str1 ) {
  String str = "";
  int a = 0;
  Serial.println( str1 );
  while ( !Serial.available() );
  if ( Serial.available() ) {
      str = Serial.readString();
      a = str.toInt();
  }
  return a;
}

 

時間類別單位標題發佈點閱
跳至網頁頂部