void loop() { float vol_value = analogRead(VOLPIN); char str[5]; int val; if(isDebug == 0 && isServoDone == 0){ //for button buttonState = digitalRead(buttonPin); if (buttonState == HIGH) { //ボタンが押されたらサーボ起動、移動後にFlahsAirの初期化 (TODO 先に初期化するとサーボが動かないバグのため暫定) Serial.println("Btn High!!!!yeah"); //時計周りに 0 度の方向へ、そして戻した後に、FAを起動 moveServoShaft(0, 1); moveServoShaft(90, 1); delay(1000); isDebug = 1; // Initialize SD card. Serial.print(F("\nInitializing SD card...")); if (card.init(SPI_HALF_SPEED, chipSelectPin)) { Serial.print(F("OK")); } else { Serial.print(F("NG")); abort(); } memset(buffer, 0, 0x200); }else { //nothing } int d = Serial.read(); if( d == 'a' ){ sv.attach(SERVO_PIN); } else if( d == 'd' ){ sv.detach(); } else if( d == 'r' ){ Serial.println(sv.read()); Serial.println(sv.readMicroseconds()); } else if( '0' <= d && d <= '9' ){ //時計周りに 0 度の方向へそして戻してFA移動 moveServoShaft(0, 10); moveServoShaft(90, 10); delay(1000); //サーボ終了 isServoDone = 1; // Initialize SD card. Serial.print(F("\nInitializing SD card...")); if (card.init(SPI_HALF_SPEED, chipSelectPin)) { Serial.print(F("OK")); } else { Serial.print(F("NG")); abort(); } memset(buffer, 0, 0x200); } //} }else{ if (card.readExtMemory(1, 1, 0x1000, 0x200, buffer)) { str[0] = buffer[0]; str[1] = buffer[1]; str[2] = buffer[2]; str[3] = buffer[3]; str[4] = 0; val = atoi(str); //0バイトの場合初期化 if(currentByte != 0 && val == 0){ strip.clear(); strip.show(); Serial.println("back to start"); currentByte = 0; } if(val == 0 || val == currentByte){ //do nothing... //Serial.println("get 1..."); }else{ if (vol_value < 800){ //Serial.println("byte changed..."); currentByte = val; showLed3AndHelloServo(val); Serial.println(val); }else{ strip.clear(); strip.show(); } } } } delay(450); }
void showLed3AndHelloServo(int val){ Serial.println("led array was...."); Serial.println(val); Serial.println("ooooooooooooooooooo"); //strip.clear(); switch(val){ case 123://how colorWipe(strip.Color(255, 255, 255), 100); // white colorWipe(strip.Color(0, 0, 0), 100); // black colorWipe(strip.Color(255, 255, 255), 100); // white colorWipe(strip.Color(0, 0, 0), 100); // black colorWipe(strip.Color(255, 255, 255), 100); // white colorWipe(strip.Color(0, 0, 0), 100); // black //TODO Arduinoをリセット wdt_enable(WDTO_15MS); // turn on the WatchDog and don't stroke it. for(;;) { // do nothing and wait for the eventual... } break; case 1://サーボ準備 sv.attach(SERVO_PIN); Serial.println("servo attached...");//サーボの位置確認 break; case 2://サーボ回転 Serial.println(sv.read());//サーボの位置確認 moveServoShaft(0, 10); //delay(100);//TODO 不要 delay(1000); break; case 3://サーボ戻す Serial.println(sv.read());//サーボの位置確認 moveServoShaft(90, 10); //delay(100);//TODO 不要 delay(1000); break; case 4://サーボ終了 sv.detach(); break; case 0://クリア strip.clear(); break; case 555://白 case 5://白 colorWipe(strip.Color(255, 255, 255), 80); // white delay(3000); colorWipe(strip.Color(0, 0, 0), 100); // black break; case 666://紫 case 6://紫 colorWipe(strip.Color(105, 14, 102), 80); // purple delay(3000); colorWipe(strip.Color(0, 0, 0), 100); // black break; case 777://ピンク case 7://ピンク colorWipe(strip.Color(252, 18, 245), 80); // pink delay(3000); colorWipe(strip.Color(0, 0, 0), 100); // black break; case 888://レインボー? case 8://レインボー? rainbow(20); //rainbowCycle(80); break; case 999://黒 = 消す case 9://黒 = 消す colorWipe(strip.Color(0, 0, 0), 10); // black strip.clear(); break; case 100://予備 break; default: Serial.println("this is for servo"); colorWipe(strip.Color(0, 0, 0), 10); // black strip.clear(); break; } }