1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
| #include <SPI.h>
#include <SD.h>
#include <Servo.h>
#include "LcDef.h"
Servo myservo[166] ;//{myservo0,myservo1,myservo2,myservo3,myservo4,myservo5,myservo6,myservo7,myservo8,myservo9,myservo10,myservo11,myservo12,myservo13,myservo14,myservo15};
File myFile;// myFile=le fichier qu'on va lire sur la carte SD qui contient les angles 020;320;090;
float xfutur[16];
float xavant[16];
float increment[16];
int angle[ 3] [ 6]= {
{0, 90, 0 ,90, 45, 90},
{120, 180, 20 ,90, 45, 180},
{120, 90, 20 ,180, 45, 180}
};
int duree= 1800;// 1000ms=1s entre chaque position
void setup()
{
myservo[0].attach(9);//attachs the servo on pin 9 to servo object
myservo[1].attach(10);
myservo[2].attach(11);
for (int j=0;j<=15;j++)
{
myservo[j].write(0);//back to 0 degrees
}
delay(1000);//wait for a second
Serial.begin(9600);
}
void loop()
{
lecturesd();
for (int j=0;j<=15;j++)
{
myservo[j].write(0);//back to 0 degrees
}
delay(1000);//wait for a second
mouvementsynchrone();
for (int j=0;j<=15;j++)
{
myservo[j].write(0);//back to 0 degrees
}
delay(1000);//wait for a second
mouvementalterne();
}
//****************************************************
void mouvementalterne()
{
int duree= 2000;
for(int no=0;no<=5;no++)//on balaye tout le tableau
{
for (int j=0;j<=15;j++)
{
xfutur[j]=angle[j][no];//l'angle ou on doit aller
increment[j]=(xfutur[j]-xavant[j])/duree ;
}
for (int j=0;j<=15;j++)
{
for(int count=0;count<=duree;count++)//***********************************
{
xavant[j]=xavant[j]+increment[j];
myservo[j].write(xavant[j]);
delayMicroseconds(20);//wait for a second
}
//xavant[j]=angle[1][no];
}
}
}
//***************************************************************************
void mouvementsynchrone()
{
for(int no=0;no<=5;no++)//on balaye tout le tableau
{
for (int j=0;j<=15;j++)
{
xfutur[j]=angle[j][no];//l'angle ou on doit aller
increment[j]=(xfutur[j]-xavant[j])/duree ;
}
for(int count=0;count<=duree;count++)
{
for (int j=0;j<=15;j++)
{
xavant[j]=xavant[j]+increment[j];
myservo[j].write(xavant[j]);
}
delayMicroseconds(20);//wait for a second
}
for (int j=0;j<=15;j++)
{
xavant[j]=angle[j][no];
}
}
}
//***************************************************************************
//The circuit:
// * SD card attached to SPI bus as follows: avec une carte sd neuve de 2Go formaté en Fat
// ** MOSI - pin 51 on Arduino Uno/Duemilanove/Diecimila
// ** MISO - pin 50 on Arduino Uno/Duemilanove/Diecimila
// ** scK - pin 52 clock on Arduino Uno/Duemilanove/Diecimila
// ** CS - pin53
void lecturesd()
{
char c;// variable du carractere lu par READ();
char buffer [3]; //Buffer de reception
byte curseur=0;// curseur de position dans le buffer
// tu remplit le buffer jusqu'a ce que tu trouve un ";"
int X;
Serial.println("debut");
myFile = SD.open("test.txt");
if (myFile) {
Serial.println("encore");
for (long jj = 0; jj< myFile.size(); jj++) // boucle de parcours du fichier
{
char c = myFile.read(); // lecture du carracter suivant
if (c != ';') // comparairon au séparateur de variable
{
buffer[curseur] = c; // mise en buffer du caractere
curseur++;// déplacement du curseur de buffer
}
else { // si un ; a ete trouve
X = atoi(buffer);
curseur=0;
Serial.println("mot");
Serial.println(X);
}
}
myFile.close();
}
} |
Partager