top of page

code du serveur

#include <VirtualWire.h>                                       

uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;

#include <Adafruit_GFX.h>    // Core graphics library
#include "Adafruit_ILI9340.h" // Hardware-specific library
#include <SPI.h>
#include <SD.h>

#if defined(__SAM3X8E__)
#undef __FlashStringHelper::F(string_literal)
#define F(string_literal) string_literal
#endif
#define TFT_RST 8
#define TFT_DC 9
#define TFT_CS 10
#define SD_CS 4
Adafruit_ILI9340 tft = Adafruit_ILI9340(TFT_CS, TFT_DC, TFT_RST);

​

File root;

​

long randNumber; 
char bluetooth;
int interupteur;
int connexion;
int ok;
int varselection = 1;
int rsttime;
int rectangles;
int premierephoto;
int tree;
int etatblue;

 

unsigned long previousMillis = 0;
long interval = 300000;

void setup() {
Serial.begin(9600);

vw_setup(2000);              
vw_set_tx_pin(5);
vw_set_rx_pin(6);  
vw_rx_start(); 

pinMode(2, OUTPUT);
pinMode(7, INPUT);
digitalWrite(2, HIGH);
pinMode(SD_CS, OUTPUT);
digitalWrite(SD_CS, HIGH);
tft.begin();
tft.fillScreen(ILI9340_BLACK);
Serial.print("Initializing SD card...");
if (!SD.begin(SD_CS)) {
Serial.println("failed!");
return;
}
SD.begin(4);


randomSeed(analogRead(0));
menu();
}

 

 

void loop() {
  
unsigned long currentMillis = millis();

interupteur = digitalRead(7);
if(interupteur == HIGH){
digitalWrite(2, HIGH); etatblue = 1;}                                             //partie interupteur si il est on logo blue devient noir + on allume le module hc_06 sinon rouge
else{ digitalWrite(2, LOW); etatblue = 0; connexion = 0;}        //et le module est eteint


blue();

if(ok == 0){
  
interval = 300000;                                                 //300000 ms = 300 s = 5 minutes (temps avant que le serveur se mette en veille si aucune action n'est faite)
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
tft.fillScreen(ILI9340_BLACK);
tft.setTextSize(3);
tft.setCursor(0, 0);                                            //ecran de veille
tft.print("veille...");
rectangles = 1;
}
if(rsttime = 1){ rsttime = 0; currentMillis = 0; }

if(rectangles == 0){
if(varselection == 1){                             //------------------------------------------ ci dessous c'est l'entourage (couleur) des applications pour savoir lequel on choisit
tft.drawRect(30, 60, 40, 40, ILI9340_GREEN); tft.drawRect(29, 59, 42, 42, ILI9340_GREEN); tft.drawRect(28, 58, 44, 44, ILI9340_GREEN); tft.drawRect(27, 57, 46, 46, ILI9340_GREEN);
tft.drawRect(30, 250, 40, 40, ILI9340_BLACK); tft.drawRect(29, 249, 42, 42, ILI9340_BLACK); tft.drawRect(28, 248, 44, 44, ILI9340_BLACK); tft.drawRect(27, 247, 46, 46, ILI9340_BLACK);
tft.drawRect(160, 60, 40, 40, ILI9340_BLACK); tft.drawRect(159, 59, 42, 42, ILI9340_BLACK); tft.drawRect(158, 58, 44, 44, ILI9340_BLACK); tft.drawRect(157, 57, 46, 46, ILI9340_BLACK);
}
if(varselection == 2){
tft.drawRect(30, 60, 40, 40, ILI9340_BLACK); tft.drawRect(29, 59, 42, 42, ILI9340_BLACK); tft.drawRect(28, 58, 44, 44, ILI9340_BLACK); tft.drawRect(27, 57, 46, 46, ILI9340_BLACK);
tft.drawRect(30, 250, 40, 40, ILI9340_BLACK); tft.drawRect(29, 249, 42, 42, ILI9340_BLACK); tft.drawRect(28, 248, 44, 44, ILI9340_BLACK); tft.drawRect(27, 247, 46, 46, ILI9340_BLACK);
tft.drawRect(160, 60, 40, 40, ILI9340_GREEN); tft.drawRect(159, 59, 42, 42, ILI9340_GREEN); tft.drawRect(158, 58, 44, 44, ILI9340_GREEN); tft.drawRect(157, 57, 46, 46, ILI9340_GREEN);
}
if(varselection == 3){
tft.drawRect(30, 60, 40, 40, ILI9340_BLACK); tft.drawRect(29, 59, 42, 42, ILI9340_BLACK); tft.drawRect(28, 58, 44, 44, ILI9340_BLACK); tft.drawRect(27, 57, 46, 46, ILI9340_BLACK);
tft.drawRect(30, 250, 40, 40, ILI9340_GREEN); tft.drawRect(29, 249, 42, 42, ILI9340_GREEN); tft.drawRect(28, 248, 44, 44, ILI9340_GREEN); tft.drawRect(27, 247, 46, 46, ILI9340_GREEN);
tft.drawRect(160, 60, 40, 40, ILI9340_BLACK); tft.drawRect(159, 59, 42, 42, ILI9340_BLACK); tft.drawRect(158, 58, 44, 44, ILI9340_BLACK); tft.drawRect(157, 57, 46, 46, ILI9340_BLACK);
}
if(etatblue == 0){tft.drawRect(160, 250, 40, 40, ILI9340_RED); tft.drawRect(159, 249, 42, 42, ILI9340_RED); tft.drawRect(158, 248, 44, 44, ILI9340_RED); tft.drawRect(157, 247, 46, 46, ILI9340_RED); }
if(etatblue == 1 && connexion == 0){tft.drawRect(160, 250, 40, 40, ILI9340_BLACK); tft.drawRect(159, 249, 42, 42, ILI9340_BLACK); tft.drawRect(158, 248, 44, 44, ILI9340_BLACK); tft.drawRect(157, 247, 46, 46, ILI9340_BLACK); }
if(connexion == 1){tft.drawRect(160, 250, 40, 40, ILI9340_BLUE); tft.drawRect(159, 249, 42, 42, ILI9340_BLUE); tft.drawRect(158, 248, 44, 44, ILI9340_BLUE); tft.drawRect(157, 247, 46, 46, ILI9340_BLUE); } 
}
}
if(varselection == 1 && ok == 1){   // si on a cliqué sur ok et que la variable selection etait sur 1 alor on demare l'application bloc notes
if(tree == 0){
tft.fillScreen(ILI9340_BLACK);
tft.setTextSize(2);
tft.setCursor(0, 0);
File dataFile = SD.open("texte.txt");

if (dataFile) {
while (dataFile.available()) {
tft.write(dataFile.read());
}
}
tree++;
bluetooth = 0;
}
if(Serial.available() > 0){
bluetooth = Serial.read();
}

if(bluetooth == '5'){ok = 0; menu(); bluetooth = 0; rsttime = 1; rectangles = 0; premierephoto = 0; tree = 0;}
if(bluetooth == 'a'){ tft.print("a"); bluetooth = 0;}
if(bluetooth == 'b'){ tft.print("b"); bluetooth = 0;}
if(bluetooth == 'c'){ tft.print("c"); bluetooth = 0;}
if(bluetooth == 'd'){ tft.print("d"); bluetooth = 0;}
if(bluetooth == 'e'){ tft.print("e"); bluetooth = 0;}
if(bluetooth == 'f'){ tft.print("f"); bluetooth = 0;}
if(bluetooth == 'g'){ tft.print("g"); bluetooth = 0;}
if(bluetooth == 'h'){ tft.print("h"); bluetooth = 0;}
if(bluetooth == 'i'){ tft.print("i"); bluetooth = 0;}
if(bluetooth == 'j'){ tft.print("j"); bluetooth = 0;}
if(bluetooth == 'k'){ tft.print("k"); bluetooth = 0;}
if(bluetooth == 'l'){ tft.print("l"); bluetooth = 0;}
if(bluetooth == 'm'){ tft.print("m"); bluetooth = 0;}
if(bluetooth == 'n'){ tft.print("n"); bluetooth = 0;}
if(bluetooth == 'o'){ tft.print("o"); bluetooth = 0;}
if(bluetooth == 'p'){ tft.print("p"); bluetooth = 0;}
if(bluetooth == 'q'){ tft.print("q"); bluetooth = 0;}
if(bluetooth == 'r'){ tft.print("r"); bluetooth = 0;}
if(bluetooth == 's'){ tft.print("s"); bluetooth = 0;}
if(bluetooth == 't'){ tft.print("t"); bluetooth = 0;}
if(bluetooth == 'u'){ tft.print("u"); bluetooth = 0;}
if(bluetooth == 'v'){ tft.print("v"); bluetooth = 0;}
if(bluetooth == 'w'){ tft.print("w"); bluetooth = 0;}
if(bluetooth == 'x'){ tft.print("x"); bluetooth = 0;}
if(bluetooth == 'y'){ tft.print("y"); bluetooth = 0;}
if(bluetooth == 'z'){ tft.print("z"); bluetooth = 0;}
if(bluetooth == '1'){ tft.print(" "); bluetooth = 0;}
if(bluetooth == '2'){ tft.println(""); bluetooth = 0;}
if(bluetooth == '3'){ tft.fillScreen(ILI9340_BLACK); bluetooth = 0;}

}

if(varselection == 2 && ok == 1){                         //idem mais pour l'appli diaporama
if(premierephoto == 0){ bmpDraw("a.bmp", 0, 0); premierephoto++; }
interval = 15000;
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
randNumber = random(1, 10);
if(randNumber == 1){ 
bmpDraw("1.bmp", 0, 0);
}
if(randNumber == 2){
bmpDraw("2.bmp", 0, 0);
}
if(randNumber == 3){
bmpDraw("3.bmp", 0, 0);
}
if(randNumber == 4){
bmpDraw("4.bmp", 0, 0);
}
if(randNumber == 5){
bmpDraw("5.bmp", 0, 0);
}
if(randNumber == 6){
bmpDraw("6.bmp", 0, 0);
}
if(randNumber == 7){
bmpDraw("7.bmp", 0, 0);
}
if(randNumber == 8){
bmpDraw("8.bmp", 0, 0);
}
if(randNumber == 9){
bmpDraw("9.bmp", 0, 0);
}
if(randNumber == 10){
bmpDraw("10.bmp", 0, 0);
}
}  
}

if(varselection == 3 && ok == 1){    //pareil pour l'appli arborescence
if(tree == 0){  
  tft.fillScreen(ILI9340_BLACK);
  tft.setCursor(0, 0);
  root = SD.open("/");
  printDirectory(root, 0);
  tree++;
}
}

}

 

 

 


void blue(){                                //void pour la lecture du module bluetooth
if(Serial.available() > 0){
bluetooth = Serial.read();
}

if(bluetooth == '5'){ok = 0; menu(); bluetooth = 0; rsttime = 1; rectangles = 0; premierephoto = 0; tree = 0;}

if(ok == 0){ 
if(bluetooth == '1'){connexion = 1; bluetooth = 0;
}  
if(bluetooth == '4'){varselection = varselection + 1; bluetooth = 0;}
if(bluetooth == '2'){varselection = varselection - 1; bluetooth = 0;}
}

if(bluetooth == '3'){ok = 1;}

if(bluetooth == '6'){const char *msg = "pon"; vw_send((uint8_t *)msg, strlen(msg)); vw_wait_tx(); bluetooth = 0;}
if(bluetooth == '7'){const char *msg = "pof"; vw_send((uint8_t *)msg, strlen(msg)); vw_wait_tx(); bluetooth = 0;}
if(bluetooth == '8'){const char *msg = "aon"; vw_send((uint8_t *)msg, strlen(msg)); vw_wait_tx(); bluetooth = 0;}
if(bluetooth == '9'){const char *msg = "aof"; vw_send((uint8_t *)msg, strlen(msg)); vw_wait_tx(); bluetooth = 0;}

if(bluetooth == 'a'){const char *msg = "csc"; vw_send((uint8_t *)msg, strlen(msg)); vw_wait_tx(); bluetooth = 0;}
if(bluetooth == 'b'){const char *msg = "cof"; vw_send((uint8_t *)msg, strlen(msg)); vw_wait_tx(); bluetooth = 0;}
if(bluetooth == 'c'){const char *msg = "cfu"; vw_send((uint8_t *)msg, strlen(msg)); vw_wait_tx(); bluetooth = 0;}
if(bluetooth == 'd'){const char *msg = "cfd"; vw_send((uint8_t *)msg, strlen(msg)); vw_wait_tx(); bluetooth = 0;}

if(bluetooth == 'e'){const char *msg = "cft"; vw_send((uint8_t *)msg, strlen(msg)); vw_wait_tx(); bluetooth = 0;}
if(bluetooth == 'f'){const char *msg = "cfq"; vw_send((uint8_t *)msg, strlen(msg)); vw_wait_tx(); bluetooth = 0;}
if(bluetooth == 'g'){const char *msg = "cfc"; vw_send((uint8_t *)msg, strlen(msg)); vw_wait_tx(); bluetooth = 0;}

if(bluetooth == 'h'){const char *msg = "von"; vw_send((uint8_t *)msg, strlen(msg)); vw_wait_tx(); bluetooth = 0;}
if(bluetooth == 'i'){const char *msg = "vof"; vw_send((uint8_t *)msg, strlen(msg)); vw_wait_tx(); bluetooth = 0;}

if(ok > 1){ ok = 1; }
if(varselection > 3){ varselection = 1; }
if(varselection < 1){ varselection = 3; }
}


void menu(){                            //affichage du menu (void qui peut etre appelé n'importe quand dans le code
bmpDraw("fond.bmp", 0, 0);
bmpDraw("diap.bmp", 160, 60);
bmpDraw("bloc.bmp", 30, 60);
bmpDraw("sd.bmp", 30, 250);
bmpDraw("blue.bmp", 160, 250);
}

 

#define BUFFPIXEL 20        // la partie ci dessous est le decryptage et l'affichage d'images format bmp
void bmpDraw(char *filename, uint16_t x, uint16_t y) {
File     bmpFile;
int      bmpWidth, bmpHeight;   
uint8_t  bmpDepth;             
uint32_t bmpImageoffset;       
uint32_t rowSize;              
uint8_t  sdbuffer[3*BUFFPIXEL];
uint8_t  buffidx = sizeof(sdbuffer); 
boolean  goodBmp = false;      
boolean  flip    = true;       
int      w, h, row, col;
uint8_t  r, g, b;
uint32_t pos = 0, startTime = millis();
if((x >= tft.width()) || (y >= tft.height())) return;
Serial.println();
Serial.print("Loading image '");
Serial.print(filename);
Serial.println('\'');
if ((bmpFile = SD.open(filename)) == NULL) {
Serial.print("File not found");
return;
}
if(read16(bmpFile) == 0x4D42) { // BMP signature
Serial.print("File size: "); Serial.println(read32(bmpFile));
(void)read32(bmpFile); // Read & ignore creator bytes
bmpImageoffset = read32(bmpFile); // Start of image data
Serial.print("Image Offset: "); Serial.println(bmpImageoffset, DEC);
Serial.print("Header size: "); Serial.println(read32(bmpFile));
bmpWidth  = read32(bmpFile);
bmpHeight = read32(bmpFile);
if(read16(bmpFile) == 1) { 
bmpDepth = read16(bmpFile);
Serial.print("Bit Depth: "); Serial.println(bmpDepth);
if((bmpDepth == 24) && (read32(bmpFile) == 0)) {
goodBmp = true;
Serial.print("Image size: ");
Serial.print(bmpWidth);
Serial.print('x');
Serial.println(bmpHeight);
rowSize = (bmpWidth * 3 + 3) & ~3;
if(bmpHeight < 0) {
bmpHeight = -bmpHeight;
flip      = false;
}
w = bmpWidth;
h = bmpHeight;
if((x+w-1) >= tft.width())  w = tft.width()  - x;
if((y+h-1) >= tft.height()) h = tft.height() - y;
tft.setAddrWindow(x, y, x+w-1, y+h-1);
for (row=0; row<h; row++) { 
if(flip)
pos = bmpImageoffset + (bmpHeight - 1 - row) * rowSize;
else 
pos = bmpImageoffset + row * rowSize;
if(bmpFile.position() != pos) {
bmpFile.seek(pos);
buffidx = sizeof(sdbuffer);
}
for (col=0; col<w; col++) { 
if (buffidx >= sizeof(sdbuffer)) {
bmpFile.read(sdbuffer, sizeof(sdbuffer));
buffidx = 0; 
}
b = sdbuffer[buffidx++];
g = sdbuffer[buffidx++];
r = sdbuffer[buffidx++];
tft.pushColor(tft.Color565(r,g,b));

}
Serial.print("Loaded in ");
Serial.print(millis() - startTime);
Serial.println(" ms");

}
}
bmpFile.close();
if(!goodBmp) Serial.println("BMP format not recognized.");
}
uint16_t read16(File & f) {
uint16_t result;
((uint8_t *)&result)[0] = f.read(); // LSB
((uint8_t *)&result)[1] = f.read(); // MSB
return result;
}
uint32_t read32(File & f) {
uint32_t result;
((uint8_t *)&result)[0] = f.read(); // LSB
((uint8_t *)&result)[1] = f.read();
((uint8_t *)&result)[2] = f.read();
((uint8_t *)&result)[3] = f.read(); // MSB
return result;
}

​

​

void printDirectory(File dir, int numTabs) {      // ce void la c'est pour afficher tous les dossiers (l'arborescence des fichiers) sur l'ecran
  while (true) {
    tft.setTextSize(2);
    File entry =  dir.openNextFile();
    if (! entry) {
    break;
    }
    for (uint8_t i = 0; i < numTabs; i++) {
    tft.print('\t');
    }
    tft.print(entry.name());
    if (entry.isDirectory()) {
    tft.println("/");
    printDirectory(entry, numTabs + 1);
    } else {
    tft.print("\t\t");
    tft.println(entry.size(), DEC);
    }
    entry.close();
  }
}

​

//ce code contient plusieurs morceaux ou gros morceaux de codes provenants de librairies tel que adafruit GFX ou sd.h il y a beaucoup moins de remarques puisque

//j'ai moins bien compris certaines partie de leur code

​

bottom of page