Bonjour, je suis en train d'essayer de coder un cube 3d qui tournerais sur mon ecran lcd graphique.
Pour le moment je galére un peu, j'essai pour le moment d'afficher un carré a l'ecran et de le faire tourner par son centre.
J'utilise une arduino uno et un afficheur ST7565.
Je souhaiterais avoir un avis sur les methodes pour arriver au résultat.
J'ai essayé de coder en m'inspirant de cette page:
Voici mon code pour le moment, Non fonctionnel:
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <ST7565_LCD.h>
// ST7565 LCD connection with Arduino board using software SPI
#define LCD_DIN 9
#define LCD_SCLK 8
#define LCD_A0 7
#define LCD_RESET 6
#define LCD_CS 5
ST7565_LCD display = ST7565_LCD(LCD_DIN, LCD_SCLK, LCD_A0, LCD_RESET, LCD_CS);
/*/ Comment out above, uncomment this block to use hardware SPI
// connect LCD 'DIN' & 'SCLK' to board's hardware SPI pins
#define LCD_A0 7
#define LCD_RESET 6
#define LCD_CS 5
ST7565 display = ST7565(LCD_A0, LCD_RESET, LCD_CS);
*/
void setup() {
Serial.begin(9600);
// initialize the ST7565 LCD display with contrast = 13 (0 <= coontrast <= 63)
display.begin(13);
}
//coordonnées du carré
double tab_coor_xy[4][2]={
{-20,20},
{20,20},
{20,-20},
{-20,-20}
};
//coordonées du carré apres decalage
double tab2_coor_xy[4][2]={
{0,0},
{0,0},
{0,0},
{0,0}
};
void loop() {
draw();
delay(1000);
int i=0;
for (int i=0; i<360; i++){
rotation(i);
draw();
delay(100);
}
}
void rotation(int degres){
double sinTheta = sin(degres);
double cosTheta = cos(degres);
tab_coor_xy[0][0] = (tab_coor_xy[0][0] * cosTheta) - (tab_coor_xy[0][1] * sinTheta) ; Serial.print(" x:");Serial.println( tab_coor_xy[0][0]);
tab_coor_xy[0][1] = (tab_coor_xy[0][1] * cosTheta) + (tab_coor_xy[0][0] * sinTheta) ; Serial.print(" y:");Serial.println( tab_coor_xy[0][1]);
tab_coor_xy[1][0] = (tab_coor_xy[1][0] * cosTheta) - (tab_coor_xy[1][1] * sinTheta) ;
tab_coor_xy[1][1] = (tab_coor_xy[1][1] * cosTheta) + (tab_coor_xy[1][0] * sinTheta) ;
tab_coor_xy[2][0] = (tab_coor_xy[2][0] * cosTheta) - (tab_coor_xy[2][1] * sinTheta) ;
tab_coor_xy[2][1] = (tab_coor_xy[2][1] * cosTheta) + (tab_coor_xy[2][0] * sinTheta) ;
tab_coor_xy[3][0] = (tab_coor_xy[3][0] * cosTheta) - (tab_coor_xy[3][1] * sinTheta) ;
tab_coor_xy[3][1] = (tab_coor_xy[3][1] * cosTheta) + (tab_coor_xy[3][0] * sinTheta) ;
}
void draw(){
//decalage des abscises et ordonées au centre de l'ecran
tab2_coor_xy[0][0] = tab_coor_xy[0][0] + 64;
tab2_coor_xy[0][1] = tab_coor_xy[0][1] + 32; //Serial.println( tab_coor_xy[0][1]);
tab2_coor_xy[1][0] = tab_coor_xy[1][0] + 64;
tab2_coor_xy[1][1] = tab_coor_xy[1][1] + 32;
tab2_coor_xy[2][0] = tab_coor_xy[2][0] + 64;
tab2_coor_xy[2][1] = tab_coor_xy[2][1] + 32;
tab2_coor_xy[3][0] = tab_coor_xy[3][0] + 64;
tab2_coor_xy[3][1] = tab_coor_xy[3][1] + 32;
display.clearDisplay();
display.drawLine(0, 0,0 ,0 , ST7565_ON); //affiche un point
display.drawLine(tab2_coor_xy[0][0], tab2_coor_xy[0][1],tab2_coor_xy[1][0] ,tab2_coor_xy[1][1] , ST7565_ON);
display.display(); // Update screen with each newly-drawn line
display.drawLine(tab2_coor_xy[1][0], tab2_coor_xy[1][1],tab2_coor_xy[2][0] ,tab2_coor_xy[2][1] , ST7565_ON);
display.display(); // Update screen with each newly-drawn line
display.drawLine(tab2_coor_xy[2][0], tab2_coor_xy[2][1],tab2_coor_xy[3][0] ,tab2_coor_xy[3][1] , ST7565_ON);
display.display(); // Update screen with each newly-drawn line
display.drawLine(tab2_coor_xy[3][0], tab2_coor_xy[3][1],tab2_coor_xy[0][0] ,tab2_coor_xy[0][1] , ST7565_ON);
display.display(); // Update screen with each newly-drawn line
}