2016年3月27日 星期日

寫一個 9x9 乘法表 swtch.... case

//4)利用  switch …case  與 Serial.print  Serial.println 指令


void setup()
{
 Serial.begin(9600); 
}
void loop()
{
 for (int i=1 ;i<=9 ;i++)
  {
    switch (i) {
    case 1 :  {
     for (int j=1 ; j<=9;j++)
     {
      int x=1*j; 
      Serial.print ("1") ;
      Serial.print ("\t") ;
      Serial.print ("*") ;
      Serial.print (j) ; 
      Serial.print ("\t") ;
      Serial.print ("=") ;
      Serial.print ("\t") ;
      Serial.println (x) ; 
      delay (500);     
     }  //for
     break;
  } //case
  
    case 2 :  {
     for (int j=1 ; j<=9;j++)
     {
      int x=2*j; 
      Serial.print ("2") ;
      Serial.print ("\t") ;
      Serial.print ("*") ;
      Serial.print (j) ; 
      Serial.print ("\t") ;
      Serial.print ("=") ;
      Serial.print ("\t") ;
      Serial.println (x) ; 
      delay (500);     
     }  //for
     break;
  } //case
  
   case 3 :  {
     for (int j=1 ; j<=9;j++)
     {
      int x=3*j; 
      Serial.print ("3") ;
      Serial.print ("\t") ;
      Serial.print ("*") ;
      Serial.print (j) ; 
      Serial.print ("\t") ;
      Serial.print ("=") ;
      Serial.print ("\t") ;
      Serial.println (x) ; 
      delay (500);     
     }  //for
     break;
  } //case

   case 4 :  {
     for (int j=1 ; j<=9;j++)
     {
      int x=4*j; 
      Serial.print ("4") ;
      Serial.print ("\t") ;
      Serial.print ("*") ;
      Serial.print (j) ; 
      Serial.print ("\t") ;
      Serial.print ("=") ;
      Serial.print ("\t") ;
      Serial.println (x) ; 
      delay (500);     
     }  //for
     break;
  } //case
   
  case 5 :  {
     for (int j=1 ; j<=9;j++)
     {
      int x=5*j; 
      Serial.print ("5") ;
      Serial.print ("\t") ;
      Serial.print ("*") ;
      Serial.print (j) ; 
      Serial.print ("\t") ;
      Serial.print ("=") ;
      Serial.print ("\t") ;
      Serial.println (x) ; 
      delay (500);     
     }  //for
     break;
  } //case

    case 6 :  {
    for (int j=1 ; j<=9;j++)
     {
      int x=6*j; 
      Serial.print ("6") ;
      Serial.print ("\t") ;
      Serial.print ("*") ;
      Serial.print (j) ; 
      Serial.print ("\t") ;
      Serial.print ("=") ;
      Serial.print ("\t") ;
      Serial.println (x) ; 
      delay (500);     
     }  //for
     break;
   } //case


    case 7 :  {
    for (int j=1 ; j<=9;j++)
     {
      int x=7*j; 
      Serial.print ("7") ;
      Serial.print ("\t") ;
      Serial.print ("*") ;
      Serial.print (j) ; 
      Serial.print ("\t") ;
      Serial.print ("=") ;
      Serial.print ("\t") ;
      Serial.println (x) ; 
      delay (500);     
     }  //for
     break;
  } //case

   case 8 :  {
    for (int j=1 ; j<=9;j++)
     {
      int x=8*j; 
      Serial.print ("8") ;
      Serial.print ("\t") ;
      Serial.print ("*") ;
      Serial.print (j) ; 
      Serial.print ("\t") ;
      Serial.print ("=") ;
      Serial.print ("\t") ;
      Serial.println (x) ; 
      delay (500);     
     }  //for
     break;
  } //case

    default :  {
    for (int j=1 ; j<=9;j++)
     {
      int x=9*j; 
      Serial.print ("9") ;
      Serial.print ("\t") ;
      Serial.print ("*") ;
      Serial.print (j) ; 
      Serial.print ("\t") ;
      Serial.print ("=") ;
      Serial.print ("\t") ;
      Serial.println (x) ; 
      delay (500);     
     }  //for 
     
    } //case
     
 //============================
  }  //switch
  
  }   //for
  
}  //loop

寫一個 9x9 乘法表 do while

// 3)利用 do    while 與  Serial.print  Serial.println 指令

// 設定引用函數庫

// 參數設定


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


//Loop
void loop()
{
  int x=1;  
   do  {
    int y=1;
    do {
       int  i=x*y;
      Serial.print (x) ;
      Serial.print ("\t") ;
      Serial.print ("*") ;
      Serial.print (y) ;
      Serial.print ("\t") ;
      Serial.print ("=") ;
      Serial.print ("\t") ;
      Serial.println (i) ;
      delay (500);  
      y++;
     }  while (y<10);    //do  while
     x++;


  }  while  (x<10) ; //do while
 
}

寫一個 9x9 乘法表 while

//2)利用  while 與  Serial.print  Serial.println 指令

// 設定引用函數庫

// 參數設定


//Setup 

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


//Loop

void loop()
{
  int x=1;   
  while (x<=9) { 
    int y=1; 

    while (y<=9) { 
        int  i=x*y; 
      Serial.print (x) ;
      Serial.print ("\t") ;
      Serial.print ("*") ;
      Serial.print (y) ; 
      Serial.print ("\t") ;
      Serial.print ("=") ;
      Serial.print ("\t") ;
      Serial.println (i) ; 
      delay (500);    
      y++; 
     }   //while
     x++;
  } //while
  
}  

寫一個 9x9 乘法表 for

// 1)利用  for 與 Serial.print  Serial.println指令

int x=0;
void setup()
{
 Serial.begin(9600); 
}
void loop()
{
 for (int i=1 ;i<=9 ;i++)
  {
    for (int j=1 ; j<=9;j++)
     {
      x=i*j; 
      Serial.print (i) ;
      Serial.print ("\t") ;
      Serial.print ("*") ;
      Serial.print (j) ; 
      Serial.print ("\t") ;
      Serial.print ("=") ;
      Serial.print ("\t") ;
      Serial.println (x) ; 
      delay (500);     
     }
  }
}  

Hello world! for Arduino.


/*
  *Hello World! *
  * This is the Hello World! for Arduino.
   * It shows how to send data to the computer
*/
void setup()   // run once, when the sketch starts
{
Serial.begin(9600);
}  // set up Serial library at 9600 bps
void  loop()  // run over and over again
{
Serial.println("Hello world! for Arduino.  ");
// prints hello with ending line break }
Delay (500);    //delay 500ms

 }

  清除項目編譯快取 執行 flutter clean 重新取得套件依賴 執行 flutter pub get 完整重新編譯並執行 flutter run 1. 新增專案套件 (pubspec.yaml) 在 Flutter 專案根目錄下的 pubspec.yaml 中,新增 ...