跳到主要內容
Old / 物聯網 / 12/11 呼吸燈程式設計

訊三甲 呼吸燈 程式 

1

#define LED D5 

unsigned char get_next( void );

 

void setup() {

  pinMode(LED, OUTPUT);

  Serial.begin( 115200 );

  Serial.print( "\n Hello World \n\n" );

}

 

void loop() {

  static unsigned char val;  //0-255

  val = get_next( );

  Serial.println( val );

  analogWrite(LED , val);

  delay(100); // Wait for 1000 millisecond(s)

}

 

unsigned char get_next( void ) {

  static char i = 0;

  byte table[] = { 1, 2, 3, 5, 6, 7, 10, 12, 15, 20 ,25, 30, 40, 50, 70, 100,150,

  200, 250, 200, 150, 100, 70, 50 ,40, 30, 25, 20, 15, 12, 10,7,6,5,4,3,2,1,0};

  i = i + 1;

  if ( table[i] == 0 ) i = 0;

  return table[i];

}

 

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