Caroline AlonsoVodhelMichaël BaudeurVouauxHugo
Created May 9, 2023 © GPL3+

How to recycle a 3D printer into a laser engraver ?

Within our studies, this project was proposed and we chose it, the title is rather explicit: we made recycling

IntermediateFull instructions provided2 days54
How to recycle a 3D printer into a laser engraver ?

Things used in this project

Hardware components

Printer - 3D Start
×1
Motherboard - 3D Printer
×1
SD extension cable
×1
Fan for aeration
×1
Charcoal filter
×1
Protective glasses
×1
Kit de résistances
×1
Transistor BS170
×1
Plaque de prototypage
×1
Film de protection
This film is only a temporary solution, it doesn't represent a genuine laser filter (as it doesn't meet any safety standards), we just wanted to filter a little more, but it isn't really doing anything.
×1
Plaque pour le support
×1
Peinture pour le support
×1
Laser de gravure
×1
Driver Diode Laser
×1
Ventilateur laser
×1
Capteur de nivellement
×1
Carte Arduino Uno Rev3
×1
Shield écran
×1
Carte SD
×1
Abaisseur de tension
×1
Kit de condensateurs
×1
Kit connecteurs plastiques
×1

Software apps and online services

Arduino IDE
Arduino IDE
VS Code
Microsoft VS Code
FreeCAD
Inkscape
LaserWeb
Marlin Firmware

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free
3D Printer (generic)
3D Printer (generic)
To print the new laser head

Story

Read more

Custom parts and enclosures

Rack_motherboard

Head_engraver_mobile_part

Head_engraver_fixed_part

Rack_Arduino_and_shield

Gcode files

Files linked to the user manual

User manual

Written in french

Code

Interface

Arduino
Code of the interface
/* Realiser dans le cadre d'un projet industriel, 2022-2023, par Caroline Alonso, Michael Baudeur, Hugo Vouaux et Alexandre Vaudelle*/

/*-------------------------------------------------------------------------------------------------
                                              Define
  ---------------------------------------------------------------------------------------------------*/
  
//#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library for ST7735
//#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
//#include <SPI.h>

// For the breakout board, you can use any 2 or 3 pins.
// These pins will also work for the 1.8" TFT shield.
#define TFT_CS        10
#define TFT_RST        9 // Or set to -1 and connect to Arduino RESET pin
#define TFT_DC         8

// For 1.44" and 1.8" TFT with ST7735 use:
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);

// Define pour position du joystick
#define Neutral 0
#define Press 1
#define Up 2
#define Down 3
#define Right 4
#define Left 5

#define NB_FILE_MAX 8//nombre de fichiers maximum sur la carte SD (limite en raison des capacites de la carte Arduino) pour tre sr que des problmes ne surviennent pas

const int PIN_DOOR = 2; //bouton lie  la porte de la graveuse

typedef enum {WARNING_DOOR = 0, WARNING_GLASSES = 1, INIT_SCREEN = 2, INFO_SCREEN = 3, SELECT_SCREEN = 4, CONTROL_SCREEN = 5, AXIS_SCREEN = 6, LASER_SCREEN = 7, FILE_SCREEN = 8, ADVANCEMENT_SCREEN = 9, PAUSED_SCREEN = 10, QUIT_SCREEN = 11, FINAL_SCREEN = 12, DEVELOPMENT_SCREEN = 13} t_state;

int CheckJoystick();
void warning_glasses() ;
void warning_door() ;
void initialize();
void info() ;
void choice() ;
void control() ;
void axis() ;
void laser() ;
void engraving() ;
void advancement();
void paused();
void quit();
void finish();
void developing();
void writeString(String string);

int autohomepressed = 0;
int levelingpressed = 0;
int joy = CheckJoystick();
int prevjoy = CheckJoystick();
float percentage_laser = 0;
float percentage_engraving = 50;
int position_cursor = 0; //position du curseur sur l'cran 1 (li  l'cran de contrle)
int state = INIT_SCREEN;
int tab[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int positionx = 0, positiony = 0, positionz = 0;
int laser_selected = 0;
String chaine_positionx;
String chaine_positiony;
String chaine_positionz;
String chaine_percentage_laser;
boolean state_bouton;
int init_file_done = 0; //de base les fichiers sont non chargs
int position_file = 4; //par dfaut le premier (commence  4) (li  l'cran de slection de fichier)
int index_filename = 0;
int nb_file = NB_FILE_MAX; //par dfaut au maximum mais en ralit pas forcment le meme nombre
int file_nb = 0;
char buf_test[40];
char filenames_engraver[8][20]; //tableau de fichiers tel que reconnu par la graveuse
char filenames[8][20]; //tableau de fichiers tel que reconnu par l'utilisateur 


//-------------------------------------------------------------------------------------------------
//                                              Setup
//-------------------------------------------------------------------------------------------------

//Certains lments sont inspirs de l'exemple graphicstest (lie  la librairie utilise)
 
void setup(void) {
 
  // initialize serial communication at 9600 bits per second:
  Serial.begin(115200);
  //Serial.setTimeout(10000);

 
  // Use this initializer if using a 1.8" TFT screen:
  tft.initR(INITR_BLACKTAB);      // Init ST7735S chip, black tab

  // SPI speed defaults to SPI_DEFAULT_FREQ defined in the library, you can override it here
  // Note that speed allowable depends on chip and quality of wiring, if you go too fast, you
  // may end up with a black screen some times, or all the time.
  tft.setSPISpeed(80000000);

  pinMode(PIN_DOOR, INPUT_PULLUP); //1 relache, 0 maintenu
  state_bouton = digitalRead(PIN_DOOR) ; 
 
  uint16_t time = millis();
  tft.fillScreen(ST77XX_BLACK);
  time = millis() - time;

  delay(500);

  //change the rotation of the screen
  tft.setRotation(-1);
  // large block of text
  tft.fillScreen(ST77XX_BLACK);

}

//-------------------------------------------------------------------------------------------------
//                                              Loop
//-------------------------------------------------------------------------------------------------

void loop() {

  joy = CheckJoystick();

  switch (state){

    case WARNING_DOOR : //ecran glasses
      joy = CheckJoystick();
      delay(50);
      if (joy != prevjoy && (joy != Neutral || prevjoy == Press))
      {
        switch (joy)
        {
          case Press :  
            state_bouton = digitalRead(PIN_DOOR) ; //maj etat de la porte li au bouton
            if (state_bouton == 0){
              if (laser_selected == 0){
                Serial.write("M24\n"); //dmarrage
                state = ADVANCEMENT_SCREEN;
                position_cursor = 0; //rinitialise
                prevjoy = 0;
              }
            }
            break;
        }
        warning_door();
      }
      prevjoy = joy;
      break;
    
    case WARNING_GLASSES : //ecran glasses
      joy = CheckJoystick();
      delay(50);
      if (joy != prevjoy && (joy != Neutral || prevjoy == Press))
      {
        switch (joy)
        {
          case Press :
            if (laser_selected == 0){
              position_cursor = 0; //rinitialise
              state = WARNING_DOOR;
            }
            else if (laser_selected == 1){
              position_cursor = 0; //rinitialise
              state = LASER_SCREEN;
            }
            break;
        }
        warning_glasses();
      }
      prevjoy = joy;
      break;

    case INIT_SCREEN : //ecran de demarrage
      initialize();
      delay(5000);
      state = INFO_SCREEN;
      break;
    
    case INFO_SCREEN : //ecran informations
      info();
      joy = CheckJoystick();
      while (joy != 1) {
        joy = CheckJoystick();
        prevjoy = joy;
      }
      state = SELECT_SCREEN;
      break;

    case SELECT_SCREEN : //ecran de slection
      joy = CheckJoystick();
      delay(50);
      if (joy != prevjoy && (joy != Neutral || prevjoy == Press))
      {
        switch (joy)
        {
          case Up:
            if (position_cursor >= 1) {
              position_cursor = position_cursor - 1;
            }
            else if (position_cursor == 0) {
              position_cursor = 3;
            }
            break;
          case Down:
            if (position_cursor < 3) {
              position_cursor = position_cursor + 1;
            }
            else if (position_cursor == 3) {
              position_cursor = 0;
            }
            break;
          case Press:
            if (position_cursor == 0) {
              break;
            }
            if (position_cursor == 1) { //Control
              state = CONTROL_SCREEN;
              position_cursor = 0; //rinitialise
              prevjoy = 0;
              break;
            }
            if (position_cursor == 2) { //Engraving
              position_cursor = 0; //rinitialise
              prevjoy = 0;
              init_file_done = 0; 
              state = FILE_SCREEN;
              break;
            }
            if (position_cursor == 3) { //Back
              state = INFO_SCREEN;
              break;
            }
            break;
          default:
            state = SELECT_SCREEN;
            break;
        }
        choice();
      }
      prevjoy = joy;
      break;

    case CONTROL_SCREEN : //ecran de controle
      joy = CheckJoystick();
      delay(50);
      if (joy != prevjoy && (joy != Neutral || prevjoy == Press))
      {
        switch (joy)
        {
          case Up:
            if (position_cursor >= 1) {
              position_cursor = position_cursor - 1;
            }
            else if (position_cursor == 0) {
              position_cursor = 5;
            }
            break;
          case Down:
            if (position_cursor < 5) {
              position_cursor = position_cursor + 1;
            }
            else if (position_cursor == 5) {
              position_cursor = 0;
            }
            break;
          case Press:
            if (position_cursor == 0) { //Control
              break;
              position_cursor = 0; //rinitialise
              prevjoy = 0;
            }
            else if (position_cursor == 1) { //Axes
              state =AXIS_SCREEN;
              position_cursor = 0; //rinitialise
              prevjoy = 0;
              break;
            }
            else if (position_cursor == 2) { //Autohome
              autohomepressed = 1;
              Serial.write("G28\n");
              delay(500);
              state = CONTROL_SCREEN;
              prevjoy = 0;
              break;
            }
            else if (position_cursor == 3) { //Warnings puis laser
              laser_selected = 1;
              state = WARNING_GLASSES;
              position_cursor = 0; //rinitialise
              prevjoy = 0;
              break;
            }
            else if (position_cursor == 4) { //Leveling
              levelingpressed = 1;
              Serial.write("G29\n");
              delay(500);
              state = CONTROL_SCREEN;
              prevjoy = 0;
              break;
            }
            else if (position_cursor == 5) { //Back
              state = SELECT_SCREEN; 
              position_cursor = 0; //rinitialise
              prevjoy = 0;
              break;
            }
            break;
          default:
            state =CONTROL_SCREEN;
            break;
        }
        control();
      }
      prevjoy = joy;
      break;

    case AXIS_SCREEN : //ecran avec axes
      joy = CheckJoystick();
      delay(50);
      if (joy != prevjoy && (joy != Neutral || prevjoy == Press))
      {
        switch (joy)
        {
          case Up:
            if (position_cursor == 4 || position_cursor == 8 || position_cursor == 12 || position_cursor == 16) {
              position_cursor = position_cursor - 4;
            }
            else if (position_cursor == 0) {
              position_cursor = 16;
            }
            else {
              if (tab[position_cursor] >= 0 && tab[position_cursor] <= 9) {
                if (tab[position_cursor] == 9){
                  tab[position_cursor]=0;
                }
                else {
                  tab[position_cursor]++;
                }
                positionx = 100*tab[5]+10*tab[6]+1*tab[7];
                positiony = 100*tab[9]+10*tab[10]+1*tab[11];
                positionz = 100*tab[13]+10*tab[14]+1*tab[15];
                if (positionx >= 171){
                  tab[5] = 1; tab[6] = 7; tab[7] = 0;
                }
                else if (positiony >= 161){
                  tab[9] = 1; tab[10] = 6; tab[11] = 0;
                }
                else if (positionz >= 121){
                  tab[13] = 1; tab[14] = 2; tab[15] = 0;
                }
              }
            }
            break;
          case Down:
            if (position_cursor == 0 || position_cursor == 4 || position_cursor == 8 || position_cursor == 12) {
              position_cursor = position_cursor + 4;
            }
            else if (position_cursor == 16) {
              position_cursor = 0;
            }
            else {
              if (tab[position_cursor] >= 0 && tab[position_cursor] <= 9) {
                if (tab[position_cursor] == 0){
                  tab[position_cursor]=9;
                }
                else {
                  tab[position_cursor]--;
                }
                positionx = 100*tab[5]+10*tab[6]+1*tab[7];
                positiony = 100*tab[9]+10*tab[10]+1*tab[11];
                positionz = 100*tab[13]+10*tab[14]+1*tab[15];
                if (positionx >= 171){
                  tab[5] = 1; tab[6] = 7; tab[7] = 0;
                }
                else if (positiony >= 161){
                  tab[9] = 1; tab[10] = 6; tab[11] = 0;
                }
                else if (positionz >= 121){
                  tab[13] = 1; tab[14] = 2; tab[15] = 0;
                }
              }
            }
            break;
          case Right:
            if ((position_cursor >= 4 && position_cursor < 7) || (position_cursor >= 8 && position_cursor < 11) || (position_cursor >= 12 && position_cursor < 15)) {
              position_cursor = position_cursor + 1;
            }
            break;
          case Left:
            if ((position_cursor > 4 && position_cursor <= 7) || (position_cursor > 8 && position_cursor <= 11) || (position_cursor > 12 && position_cursor <= 157)) {
              position_cursor = position_cursor - 1;
            }
            break;
          case Press:
            switch (position_cursor){
              case 4:  //X
                //G0 X... F2500
                positionx = 100*tab[5]+10*tab[6]+1*tab[7];
                chaine_positionx = "";
                chaine_positionx = chaine_positionx + "G0 X" + positionx + " F2500\n";
                writeString(chaine_positionx); 
                break;
              case 8 :  //Y
                //G0 Y... F2500
                positiony = 100*tab[9]+10*tab[10]+1*tab[11];
                chaine_positiony = "";
                chaine_positiony = chaine_positiony + "G0 Y" + positiony + " F2500\n";
                writeString(chaine_positiony); 
                break;
              case 12 :  //Z
                //G0 Z... F2500
                positionz = 100*tab[13]+10*tab[14]+1*tab[15];
                chaine_positionz = "";
                chaine_positionz = chaine_positionz + "G0 Z" + positionz + " F2500\n";
                writeString(chaine_positionz); 
                break;
              case 16 : //Back
                state =CONTROL_SCREEN;
                position_cursor = 0;
                break;
              default:
                break;
            }
            break;
          default:
            state =AXIS_SCREEN;
            break;
        }
        axis();
      }
      prevjoy = joy;
      break;

    case LASER_SCREEN : //ecran warning glasses puis ecran laser
      joy = CheckJoystick();
      delay(50);
      if (joy != prevjoy && (joy != Neutral || prevjoy == Press))
      {
        switch (joy)
        {
          case Up:
            if (position_cursor >= 1 && position_cursor < 5) {
              position_cursor = position_cursor - 1;
            }
            else if (position_cursor == 0) {
              position_cursor = 4;
            }
            else if (percentage_laser == 100){
              percentage_laser = 0;
            }
            else if (position_cursor == 5 && percentage_laser<=99){
              percentage_laser++;
            }
            break;
          case Down:
            if (position_cursor <= 3) {
              position_cursor = position_cursor + 1;
            }
            else if (position_cursor == 4) {
              position_cursor = 0;
            }
            else if (percentage_laser == 0){
              percentage_laser = 100;
            }
            else if (position_cursor == 5 && percentage_laser>=1){
              percentage_laser--;
            }
            break;
          case Right : 
            if (position_cursor == 3){
              position_cursor = 5;
            }
            break;
          case Left : 
            if (position_cursor == 5){
              position_cursor = 3;
            }
            break;
          case Press:
            if (position_cursor == 1) { //Turn off
              Serial.write("M5\n");
            }
            else if (position_cursor == 2) { //Focus
              Serial.write("G0 Z30\n");
              Serial.write("M3 S0\n");
            }
            else if (position_cursor == 3) { //Power
              //M3 S...
              chaine_percentage_laser = "";
              chaine_percentage_laser = chaine_percentage_laser + "M3 S" + (percentage_laser*2.55) + "\n";
              writeString(chaine_percentage_laser); 
            }
            else if (position_cursor == 4) { //Back
              laser_selected = 0;
              state =CONTROL_SCREEN;
              position_cursor = 0; //rinitialise
              break;
            }
            break;
          default:
            state = LASER_SCREEN;
            break;
        }
        laser();
      }
      prevjoy = joy;
      break;

    case FILE_SCREEN:  //ecran engraving - choisir fichier  graver
      if (init_file_done == 0){
        for(int i = 0; i < 8; i++)
        {
          filenames[i][0] = ' ';
          filenames[i][1] = '\0';
        }
        Serial.write("M22\n");
        Serial.write("M21\n");
        delay(500);
        Serial.flush();
        Serial.write("M20 L\n");              
        //L il y a la liste 
        bool sdcard = true;
        memset(buf_test, 0, sizeof(buf_test));
        int ite = 0;
        while(strstr(buf_test, "Begin") == NULL && strstr(buf_test, "No media") == NULL) 
        {
          ite = ite + 1;
          if(Serial.available())
          {
            memset(buf_test, 0, sizeof(buf_test));
            int c = Serial.readBytesUntil('\n', buf_test, 40-1);
          }
          
          if (ite > 10000){
            break;
          }
        }
        ite = 0;
        if(sdcard)
        {
          index_filename = 0;
          bool isfile = false;
          memset(buf_test, 0, sizeof(buf_test));
          while(strstr(buf_test, "list") == NULL && index_filename <= 8)
          {
            ite = ite + 1;
            while(Serial.available() && index_filename <= 8)
            {
              isfile = false;
              memset(buf_test, 0, sizeof(buf_test));
              int c = Serial.readBytesUntil(' ', buf_test, 40-1);
              //delay(100);
              strcpy(filenames_engraver[index_filename], buf_test);
              if(strstr(buf_test, ".GCO") != NULL)
              {
                isfile = true;
              }
              memset(buf_test, 0, sizeof(buf_test));
              c = Serial.readBytesUntil(' ', buf_test, 40-1);
              memset(buf_test, 0, sizeof(buf_test));
              c = Serial.readBytesUntil('\n', buf_test, 40-1);
              if(isfile)
              {
                if (c > 20);
                {
                   buf_test[19] = '\0';
                }
                
                strcpy(filenames[index_filename], buf_test);
                index_filename++;
              }
            }
            if (ite > 10000){
              break;
            }
          }
        }    
        init_file_done = 1;
      } 
   
      nb_file = index_filename; //on mets  jour le nombre de fichier max
      
      joy = CheckJoystick();
      delay(50);
      if (joy != prevjoy && (joy != Neutral || prevjoy == Press))
      {
        switch (joy)
        {
          case Up:
            if (position_cursor == 4){
              position_cursor = (nb_file + 3);
            }
            else if (position_cursor >= 4 && position_cursor < (nb_file + 3)){ 
              position_cursor = position_cursor - 1;
            }
            else if (position_cursor >= 1) {
              position_cursor = position_cursor - 1;
            }
            else if (position_cursor == 0) {
              position_cursor = 3;
            }
            break;
          case Down:
            if (position_cursor == (nb_file + 3)) {
              position_cursor = 4;
            }
            else if (position_cursor >= 4 && position_cursor < (nb_file + 3)){ 
              position_cursor = position_cursor = position_cursor + 1;
            }
            else if (position_cursor <= 2) {
              position_cursor = position_cursor + 1;
            }
            else if (position_cursor == 3) {
              position_cursor = 0;
            }
            break;
          case Right : 
            if (position_cursor == 1){
              position_cursor = position_file;
            }
            break;
          case Left : 
            if (position_cursor >= 4 && position_cursor < (nb_file + 4)){
              position_file = position_cursor;
              position_cursor = 1;
            }
            break;
          case Press:
            if (position_cursor == 0 || position_cursor == 1  || position_cursor ==2 ) { 
              break;
            }
            else if ((position_cursor >= 4 && position_cursor < (nb_file + 4))){ //Cliquer sur le fichier
              //M23 filename
              String chaine_buffer = "";
              index_filename = position_cursor - 4; 
              chaine_buffer = chaine_buffer + "M23 " + filenames_engraver[index_filename] + "\n";
              writeString(chaine_buffer);
              Serial.write("G28\n");
              Serial.write("G0 Z30\n"); //pour le focus
              state = WARNING_GLASSES ; 
              position_cursor = 0; //rinitialise
              prevjoy = 0;
              break;
            }
            else if (position_cursor == 3) { //Back
              state = SELECT_SCREEN;
              position_cursor = 0; //rinitialise
              prevjoy = 0;
              break;
            }
            break;
          default:
            state = FILE_SCREEN;
            break;
        }
        engraving();
      }
      prevjoy = joy;
      break;

    case ADVANCEMENT_SCREEN : //ecran warning glasses et door puis ecran advancement
      state_bouton = digitalRead(PIN_DOOR) ; 
      if(Serial.available())
      {
        //Serial.print("Heree\n"); 
        memset(buf_test, 0, sizeof(buf_test));
        int c = Serial.readBytesUntil('\n', buf_test, 40-1);
        if (strstr(buf_test, "Done") != NULL) 
        {
          Serial.write("M25\n");
          Serial.write("M22\n");
          Serial.write("M21\n");
          Serial.write("M5\n");
          Serial.write("G0 Z120\n");
          state = FINAL_SCREEN;
          position_cursor = 0; //rinitialise
          prevjoy = 0;
          break;
        }
      }
      if (state_bouton == 1){
        Serial.write("M25\n");
        Serial.write("M5\n");
        state = PAUSED_SCREEN;
        position_cursor = 0; //rinitialise
        prevjoy = 0;
        paused();
        break;
      }
      else {
        joy = CheckJoystick(); //Advancement
        delay(50);
        if (joy != prevjoy && (joy != Neutral || prevjoy == Press))
        {
          switch (joy)
          {
            case Up:
              if (position_cursor == 0) {
                position_cursor = 2;
              }
              else if (position_cursor >= 1) {
                position_cursor = position_cursor - 1;
              }
              break;
            case Down:
              if (position_cursor == 2) {
                position_cursor = 0;
              }
              else if (position_cursor <= 1) {
                position_cursor = position_cursor + 1;
              }
              break;
            case Press:
              if (position_cursor == 0) {
                break;
              }
              else if (position_cursor == 1) { //Pause
                Serial.write("M25\n");
                Serial.write("M5\n");
                state = PAUSED_SCREEN;
                position_cursor = 0; //rinitialise
                prevjoy = 0;
                break;
              }
              else if (position_cursor == 2) { //Quit
                state = QUIT_SCREEN;
                position_cursor = 1; //rinitialise (pour tre par dfaut sur non)
                prevjoy = 0;
                break;
              }
              break;
            default:
              state = ADVANCEMENT_SCREEN;
              break;
          }
          advancement();
        }
        prevjoy = joy;
      }
      break;

    case PAUSED_SCREEN : //ecran engraving paused
      joy = CheckJoystick();
      delay(50);
      if (joy != prevjoy && (joy != Neutral || prevjoy == Press))
      {
        switch (joy)
        {
          case Up:
            if (position_cursor == 0) {
              position_cursor = 1;
            }
            else if (position_cursor >= 1) {
              position_cursor = position_cursor - 1;
            }
            break;
          case Down:
            if (position_cursor == 1) {
              position_cursor = 0;
            }
            else if (position_cursor < 1) {
              position_cursor = position_cursor + 1;
            }
            break;
          case Press:
            if (position_cursor == 0) { //Engraving
              break;
            }
            else if (position_cursor == 1) { //Resume
              Serial.write("M24\n");
              state = ADVANCEMENT_SCREEN;
              position_cursor = 0; //rinitialise
              prevjoy = 0;            
              break;
            }
            break;
          default:
            state = PAUSED_SCREEN;
            break;
        }
        paused();
      }
      prevjoy = joy;
      break;

    case FINAL_SCREEN : //ecran de fin (engraving done)
      finish();
      joy = CheckJoystick();
      while (joy != 1) {
        joy = CheckJoystick();
        prevjoy = joy;
      }
      state = SELECT_SCREEN;
      break;

    case QUIT_SCREEN : //ecran confirmation quitter
      joy = CheckJoystick();
      delay(50);
      if (joy != prevjoy && (joy != Neutral || prevjoy == Press))
      {
        switch (joy)
        {
          case Right:
            if (position_cursor == 0) {
              position_cursor = position_cursor + 1;
            }
            break;
          case Left:
            if (position_cursor == 1) {
              position_cursor = position_cursor - 1;
            }
            break;
          case Press:
            if (position_cursor == 0) { //Yes
              Serial.write("M25\n");
              Serial.write("M22\n");
              Serial.write("M21\n");
              Serial.write("M5\n");
              Serial.write("G0 Z120\n");
              state = FINAL_SCREEN; 
              position_cursor = 0; //rinitialise
              prevjoy = 0;
              break;
            }
            if (position_cursor == 1) { //No
              state = ADVANCEMENT_SCREEN;
              position_cursor = 0; //rinitialise
              prevjoy = 0;
              break;
            }
            break;
          default:
            state = QUIT_SCREEN;
            break;
        }
        quit();
      }
      prevjoy = joy;
      break;

    case DEVELOPMENT_SCREEN : //ecran developing
      joy = CheckJoystick();
      delay(50);
      if (joy != prevjoy && (joy != Neutral || prevjoy == Press))
      {
        switch (joy)
        {
          case Press :
            position_cursor = 0; //rinitialise
            state = SELECT_SCREEN;
            break;
        }
        developing();
      }
      prevjoy = joy;
      break;

    default : 
      Serial.println("Error\n");
      break;
  }  

}

//-------------------------------------------------------------------------------------------------
//                                             Fonctions
//-------------------------------------------------------------------------------------------------


// Check the joystick position
int CheckJoystick()
{
  int joystickState = analogRead(3);

  if (joystickState < 50) return Left;
  if (joystickState < 150) return Down;
  if (joystickState < 250) return Press;
  if (joystickState < 500) return Right;
  if (joystickState < 650) return Up;
  return Neutral;
}

void drawtext(char *text, uint16_t color) {
  tft.setTextColor(color);
  tft.print(text);
}



//-------------------------------------------------------------------------------------------------
//                                               Screens
//-------------------------------------------------------------------------------------------------


//Titre et dessin
void initialize(){
  tft.setTextWrap(false);
  tft.fillScreen(ST77XX_BLUE);
  tft.setTextColor(ST77XX_WHITE);
  tft.setTextSize(1);
  tft.fillCircle(35,60,3,ST77XX_WHITE);
  tft.drawLine(15,40,55,80,ST77XX_WHITE);
  tft.drawLine(25,30,45,90,ST77XX_WHITE);
  tft.drawLine(25,90,45,30,ST77XX_WHITE);
  tft.drawLine(15,80,55,40,ST77XX_WHITE);
  tft.drawLine(10,60,148,60,ST77XX_WHITE);
  tft.setCursor(83, 40);
  tft.println("VIATECH");
  tft.setCursor(79, 75);
  tft.println("Polytech");
  tft.setCursor(79, 85);
  tft.println("Sorbonne");
  tft.setCursor(0, 111);
  tft.println("Caroline A., Michael B.");
  tft.println("Alexandre V., Hugo V.");
}

void warning_glasses(){
  tft.setTextWrap(false);
  tft.fillScreen(ST77XX_BLUE);
  tft.setTextColor(ST77XX_WHITE);
  tft.setTextSize(1);
  tft.drawTriangle(47,30,37,50,57,50,ST77XX_WHITE);
  tft.setCursor(45, 40);
  tft.println("!");
  tft.setCursor(80, 40);
  tft.println("Warning");
  tft.setCursor(23, 74);
  tft.println("Wear eye protection");
  tft.setCursor(30, 119);
  tft.println("PRESS to continue");
}

void warning_door(){
  tft.setTextWrap(false);
  tft.fillScreen(ST77XX_BLUE);
  tft.setTextColor(ST77XX_WHITE);
  tft.setTextSize(1);
  tft.drawTriangle(47,30,37,50,57,50,ST77XX_WHITE);
  tft.setCursor(45, 40);
  tft.println("!");
  tft.setCursor(80, 40);
  tft.println("Warning");
  tft.setCursor(39, 70);
  if (state_bouton == 0){
    tft.println("Closing");
  }
  else {
    tft.println("Close the door");
  }
  tft.setCursor(15, 80);
  tft.println("of the laser engraving");
  tft.setCursor(30, 119);
  tft.println("PRESS to continue");
}

//Info 
void info() {
  tft.setTextWrap(false);
  tft.fillScreen(ST77XX_BLACK);
  tft.setCursor(0, 0);
  tft.setTextColor(ST77XX_WHITE);
  tft.setTextSize(1);
  tft.println("Informations:\n\n");
  tft.setCursor(0, 27);
  tft.println("Use the joystick to \nmove and select");
  tft.setCursor(0, 64);
  tft.println("Move :\nUp, Right, Down, Left\n");
  tft.println("Select :\nPress on the joystick\n\n");
  tft.println("PRESS to continue\n");
}

//Choix 
void choice() {
  tft.setTextWrap(false);
  tft.fillScreen(ST77XX_BLACK);
  tft.setCursor(0, 0);
  tft.setTextSize(1);

  tft.setTextColor(ST77XX_WHITE);
  if (position_cursor == 0){tft.setTextColor(ST77XX_RED);}
  tft.println("Select:\n");
  tft.setTextColor(ST77XX_WHITE);
  if (position_cursor == 1){tft.setTextColor(ST77XX_RED);}
  tft.setCursor(0, 60);
  tft.println("Control");
  tft.setTextColor(ST77XX_WHITE);
  if (position_cursor == 2){tft.setTextColor(ST77XX_RED);}
  tft.println("Engraving");
  tft.setTextColor(ST77XX_WHITE);
  if (position_cursor == 3){tft.setTextColor(ST77XX_RED);}
  tft.setCursor(135, 120);
  tft.println("Back");
}

//Control //Move axis*, Autohome, Laser (Warning)*, Leveling, Resume
void control() {
  tft.setTextWrap(false);
  tft.fillScreen(ST77XX_BLACK);
  tft.setCursor(0, 0);
  tft.setTextSize(1);
...

This file has been truncated, please download it to see its full contents.

Firmware

C/C++
All files concerning Marlin
No preview (download only).

Credits

Caroline Alonso
2 projects • 5 followers
Vodhel
2 projects • 1 follower
Michaël Baudeur
2 projects • 1 follower
I'm a student in electrical engineering. Learning everything I can.
VouauxHugo
2 projects • 1 follower

Comments