Ressource documentaire: code example: #include //adresses codées sur 7bits //données #define SLAVE_ADDR_8574_A 0x3e //controle #define SLAVE_ADDR_8574_B 0x3f ////////////////////////////////////////// char readPort8574(char addr, char * ptr_value) /*addr, l'adresse du PCF8574 ptr_value, pointeur pour renvoyer la valeur lue sur le port retourne -1 si échec 0 sinon*/ { Wire.requestFrom((byte)addr, (byte)1);// demande la lecture d'1 octet depuis l'adresse du pérpiphérique if (Wire.available()==1) //si l'octet est disponible { (* ptr_value) = Wire.read(); // lire l'octet return 0; } else { (* ptr_value) =0; //valeur par défaut si le composant n'a pas acquité return -1; } } ////////////////////////////////////////// char writePort8574(char addr, char value) /*addr, l'adresse du PCF8574 value, la valeur à écrire sur le port retourne -1 si échec 0 sinon */ { Wire.beginTransmission(addr);//démarre la transmission avec l'adresse du pérpiphérique Wire.write((byte)value); //envoie la donnée if (Wire.endTransmission()==0) //stoppe la transmission return 0; else return -1; } byte imageB; ////////////////////////////////////////// bool sendCar(char c) { char datab; //if busy return false; readPort8574(SLAVE_ADDR_8574_B,&datab); if ((datab & 2) ==2 ) { // Serial.println("occupée"); return false; } writePort8574( SLAVE_ADDR_8574_A , c); writePort8574( SLAVE_ADDR_8574_B , imageB&0xfe); //strobe à 0 writePort8574( SLAVE_ADDR_8574_B , imageB|1); //strobe à 1 return true; } ////////////////////////////////////////// void sendCarBlocking(char c){ while (sendCar(c)==false); } ////////////////////////////////////////// void sendStringBlocking(char * ptrc){ while ((*ptrc) !=0){ while (sendCar(*ptrc)==false); ptrc++; } } char chaine[100]="PU1000,1000;PD1000,2000;PD2000,2000;PD2000,1000;PD1000,1000;"; char coord[10]; ////////////////////////////////////////// void traceCirclePointille(unsigned int cx,unsigned int cy,unsigned int r,unsigned int nbseg) { unsigned int i=0; int x,y; float angle=0; float incangle=2*PI/nbseg; while (i<=nbseg){ x=cx+r*cos(angle); y=cy+r*sin(angle); Serial.print(x); Serial.print(" , "); Serial.println(y); sendCarBlocking('P'); if ((i%2)==0) sendCarBlocking('D'); else sendCarBlocking('U'); itoa(x,coord,10); sendStringBlocking(coord); sendCarBlocking(','); itoa(y,coord,10); sendStringBlocking(coord); sendCarBlocking(';'); i++; angle=angle+incangle; } } ////////////////////////////////////////// void traceCircle(unsigned int cx,unsigned int cy,unsigned int r,unsigned int nbseg) { unsigned int i=0; int x,y; float angle=0; float incangle=2*PI/nbseg; while (i<=nbseg){ x=cx+r*cos(angle); y=cy+r*sin(angle); Serial.print(x); Serial.print(" , "); Serial.println(y); sendCarBlocking('P'); sendCarBlocking('D'); itoa(x,coord,10); sendStringBlocking(coord); sendCarBlocking(','); itoa(y,coord,10); sendStringBlocking(coord); sendCarBlocking(';'); i++; angle=angle+incangle; } sendCarBlocking('P'); sendCarBlocking('U'); sendCarBlocking(','); } ////////////////////////////////////////// bool gotoyx(int16_t x,int16_t y,int16_t b) { /*int16_t xmax=5000; int16_t ymax=5000; if (x<0) return -1; if (y<0) return -1; if (x>xmax) return -1; if (y>ymax) return -1; */ sendCarBlocking('P'); if ((b%2)==0) sendCarBlocking('D'); else sendCarBlocking('U'); itoa(x,coord,10); sendStringBlocking(coord); sendCarBlocking(','); itoa(y,coord,10); sendStringBlocking(coord); sendCarBlocking(';'); return 0; } ////////////////////////////////////////// void loop2() { static int i=10; // Serial.print("JMB"); Serial.println(i,HEX); delay(1000); i=i+1; } ////////////////////////////////////////// class Joystick{ private: int16_t x,y,b; int16_t minX,maxX,minY,maxY; int16_t xFactor,yFactor; int16_t centerX,centerY,dZ; uint8_t pinX,pinY,pinB; public: Joystick(uint8_t pinXinit,uint8_t pinYinit,uint8_t pinBinit,int16_t dZinit) { pinX=pinXinit; pinY=pinYinit; pinB=pinBinit; dZ=dZinit; //dead Zone //par défaut les limites pour x et y sont les valeurs min et max codable minX=-32768; maxX=32767; minY=-32768; maxY=32767; xFactor=1; yFactor=1; } init(){ //analogRead ne fonctionne pas avant appel de setup() pinMode(pinB,INPUT_PULLUP); //pull up pour bouton x=0; y=0; b=!digitalRead(pinB); centerX= analogRead(pinX); centerY= analogRead(pinY); } setLimits(int16_t minXinit,int16_t maxXinit,int16_t minYinit,int16_t maxYinit){ minX=minXinit; maxX=maxXinit; minY=minYinit; maxY=maxYinit; } setPos(int16_t xinit,int16_t yinit){ x=xinit; y=yinit; } setPosCenter(){ x=(maxX+minX)/2; y=(maxY+minY)/2; } setFactorOrientation(int16_t xFactorInit,int16_t yFactorInit){ xFactor=xFactorInit; yFactor=yFactorInit; } update(){ int16_t dX= (analogRead(pinX) - centerX)*xFactor; int16_t dY= (analogRead(pinY) - centerY)*yFactor; /*if (abs(dX)>dZ) x=x+dX; if (abs(dY)>dZ) y=y+dY; */ if (dX>dZ) if (xminX-dX) x=x+dX; else x=minX; if (dY>dZ) if (yminY-dY) y=y+dY; else y=minY; b=!digitalRead(pinB); /* Serial.print("centerX: "); Serial.print(centerX); Serial.print("centerY: "); Serial.println(centerY); Serial.print("dX: "); Serial.print(dX); Serial.print("dY: "); Serial.println(dY); */ } int16_t getX(){return x;} int16_t getY(){return y;} int16_t getB(){return b;} bool isUp(){return (y>centerY+dZ);} bool isDown(){return (ycenterX+dZ);} bool isRight(){return (x