SDカードとサーボを同時に使用したいのですがsetupが何度も実行されてloopまでいってないようです。
エラーは出てないけどサーボが震えた状態になります。
サーボ単体、SDカード単体のスケッチでは動作OKでした。
下記loop部分を省いたスケッチになります。
原因と解決方法がお分かりの方よろしくお願いします。
arduino
1 2#include <Wire.h> 3#include <Adafruit_PWMServoDriver.h> 4 5#include <SPI.h> 6#include <SD.h> 7 8 9Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(); 10#define ServoCount 12 11#define FrameCount 8 12#define MotionCount 6 13 14int motion0[ServoCount] = {4, -60, -66, 0, 15, -4, 0, -60, -70, -22, 30, 55}; 15 16 17bool IsMove = false; 18int currentMotion = 0; 19 20File myFile; 21 22void setup() 23{ 24 25 26 // Open serial communications and wait for port to open: 27 28 29 Serial.begin(9600); 30while (!Serial) { 31 ; // wait for serial port to connect. Needed for native USB port only 32 } 33Serial.print("Initializing SD card..."); 34 35 if (!SD.begin(4)) { 36 Serial.println("initialization failed!"); 37 return; 38 } 39 Serial.println("initialization done."); 40 41 // open the file. note that only one file can be open at a time, 42 // so you have to close this one before opening another. 43 myFile = SD.open("test.txt", FILE_WRITE); 44 45 // if the file opened okay, write to it: 46 if (myFile) { 47 Serial.print("Writing to test.txt..."); 48 myFile.println("testing 1, 2, 3."); 49 // close the file: 50 myFile.close(); 51 Serial.println("done."); 52 } else { 53 // if the file didn't open, print an error: 54 Serial.println("error opening test.txt"); 55 } 56 57 // re-open the file for reading: 58 myFile = SD.open("test.txt"); 59 if (myFile) { 60 Serial.println("test.txt:"); 61 62 // read from the file until there's nothing else in it: 63 while (myFile.available()) { 64 Serial.write(myFile.read()); 65 } 66 // close the file: 67 myFile.close(); 68 } else { 69 // if the file didn't open, print an error: 70 Serial.println("error opening test.txt"); 71 } 72 73 74 pwm.begin(); 75 pwm.setPWMFreq(60); 76 for (int i = 0; i < 16; i++) { 77 myservo(i, 0); 78 } 79 80 81 //delay(1000); 82} 83
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/05/22 11:45
2018/05/22 11:48