Arduino LED test プログラム
以下、Arduino nanoの動作チェックに使ったプログラムです。
元記事はこちら
int inByte = 0; int LEDstat = 0; // 動作 int LED = 0; // LED点灯/消灯 int LEDtime = 0; // custom用 float x = 0; void setup() { Serial.begin(9600); while (!Serial) //シリアル差さないと先に進まないらしい pinMode(13, OUTPUT); //操作入力キー Serial.println("LED control"); Serial.println("0 : OFF"); Serial.println("1 : ON"); Serial.println("2 : 50us/1s low Light"); Serial.println("3 : 300ms blink"); Serial.println("4 : 250ms blink"); Serial.println("5 : 180ms blink"); Serial.println("6 : custom1"); Serial.println("7 : custom2"); Serial.println("8 : custom3"); Serial.println("9 : custom4"); } void loop() { //シリアル受信処理 if (Serial.available() > 0) { inByte = Serial.read(); LEDstat = inByte - '0'; Serial.print("Mode key= "); Serial.println(LEDstat); LED = 0; LEDtime = 0; x = 0; } // 1~9以外消灯 if((LEDstat <= 0) || (LEDstat >= 10)){ digitalWrite(13, LOW); }else // 1. 点灯 if(LEDstat == 1){ digitalWrite(13, HIGH); }else // 2. 50us 点灯 if(LEDstat == 2){ digitalWrite(13, LOW); delayMicroseconds(950); digitalWrite(13, HIGH); delayMicroseconds(50); }else // 6. custom6 if(LEDstat == 6){ digitalWrite(13, LED); x = x + 0.01; if(x >= 1){x = 0;} LEDtime = sin(PI*x)*100; delay(LEDtime); LED = ~LED; }else // 7. custom7 if(LEDstat == 7){ digitalWrite(13, LED); x = x + 0.02; if(x >= 1){x = 0;} LEDtime = pow((sin(PI*x)),4)*100; delay(LEDtime); LED = ~LED; }else // 8. custom8 if(LEDstat == 8){ digitalWrite(13, LED); x = x + 0.01; if(x >= 0.49){x = 0;} LEDtime = tan(PI*x)*100; delay(LEDtime); LED = ~LED; }else // 9. custom9 if(LEDstat == 9){ digitalWrite(13, LED); x = x + 0.01; if(x >= 0.49){x = 0;} LEDtime = cos(PI*x)*100; delay(LEDtime); LED = ~LED; }else // 3. 300ms // 4. 250ms // 5. 180ms if(LEDstat >= 3){ digitalWrite(13, LED); delay(900/LEDstat); LED = ~LED; } }