Etape 9: Mise à jour : ajouté un capteur à ultrasons et mise à jour le programme juste mettre à jour les numéros de
#define sclk 4
#define mosi 5
#define cs 6
#define dc 7
#define rst 8 / / vous pouvez également vous connecter cela à la réinitialisation de l’Arduino
#define ANALOG_IN 0 / / pour les CD capteur de lumière
#define TRIGGER_PIN 12 / / goupille de Arduino lié à déclencher la broche sur le capteur à ultrasons.
#define ECHO_PIN 11 / / goupille de Arduino liée à la broche sur le capteur à ultrasons d’écho.
#define MAX_DISTANCE 200 / / distance maximale que nous voulons faire un ping pour (en centimètres). Distance maximum sensor est évalué à 400-500cm.
#include < Adafruit_GFX.h > / / bibliothèque graphique de base
#include < Adafruit_ST7735.h > / / spécifiques au matériel bibliothèque
#include < SPI.h >
#include < dht11.h > / / dht temp bibliothèque de capteur d’humidité
#include < NewPing.h > / / capteur à ultrasons S04 bibliothèque
dht11 DHT11 ;
Tft Adafruit_ST7735 = Adafruit_ST7735 (cs, dc, mosi, sclk, rst) ;
NewPing sonar (TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE) ; NewPing configuration des broches et distance maximale.
void setup(void) {}
DHT11.Attach(2) ; valeur numérique port 2 en sens dht d’entrée
Serial.Begin(115200) ;
Serial.Print("Hello!") ;
tft.initR(INITR_BLACKTAB) ; initialiser un onglet de puce, noire ST7735S
Serial.println("init") ;
tft.setRotation(tft.getRotation()+1) ; Décommentez pour appliquer une rotation écran
temps d’uint16_t = millis() ;
tft.fillScreen(ST7735_BLACK) ;
temps = millis() - temps ;
Serial.println (temps, DEC) ;
Delay(500) ;
Serial.println("Done") ;
Delay(1000) ;
tftPrintTest() ;
Delay(500) ;
tft.fillScreen(ST7735_BLACK) ; Efface l’écran
les lignes commentées ci-dessous sont grille et carré splash Screen
lignes optimisées
testfastlines (ST7735_RED, ST7735_BLUE) ;
Delay(500) ;
testdrawrects(ST7735_GREEN) ;
Delay(500) ;
tft.fillScreen(ST7735_BLACK) ;
}
void loop() {}
tft.invertDisplay(true) ;
Delay(500) ;
tft.invertDisplay(false) ;
tft.setTextColor(ST7735_WHITE) ;
tft.setTextSize(1) ;
tft.setCursor(0,0) ;
TFT.println (« esquisse a été ») ;
TFT.println ("en cours d’exécution pour:") ;
tft.setCursor (50, 20) ;
tft.setTextSize(2) ;
tft.setTextColor (ST7735_BLUE, ST7735_BLACK) ;
TFT.Print(Millis() / 1000) ;
tft.setTextSize(1) ;
tft.setCursor (40, 40) ;
tft.setTextColor(ST7735_WHITE) ;
TFT.println("seconds") ;
tft.setCursor (0, 60) ;
tft.drawLine (0, 50, tft.width ()-1, 50, ST7735_WHITE) ;
tft.setTextColor(ST7735_YELLOW) ;
TFT.Print ("Temperature (C):") ;
tft.setTextColor (ST7735_GREEN, ST7735_BLACK) ;
TFT.println((float)DHT11.Temperature,1) ;
tft.setTextColor(ST7735_WHITE) ;
TFT.Print ("humidité (%):") ;
tft.setTextColor (ST7735_RED, ST7735_BLACK) ;
TFT.println((float)DHT11.Humidity,1) ;
tft.setTextColor(ST7735_YELLOW) ;
TFT.Print ("température (F):") ;
tft.setTextColor (ST7735_GREEN, ST7735_BLACK) ;
TFT.println(DHT11.Fahrenheit(), 1) ;
tft.setTextColor(ST7735_YELLOW) ;
TFT.Print ("température (K):") ;
TFT.Print("") ;
tft.setTextColor (ST7735_GREEN, ST7735_BLACK) ;
TFT.println(DHT11.Kelvin(), 1) ;
tft.setTextColor(ST7735_WHITE) ;
TFT.Print ("Dew Point (C):") ;
tft.setTextColor (ST7735_RED, ST7735_BLACK) ;
TFT.println(DHT11.dewPoint(), 1) ;
tft.setTextColor(ST7735_WHITE) ;
TFT.Print("DewPointFast(C):") ;
tft.setTextColor (ST7735_RED, ST7735_BLACK) ;
TFT.println(DHT11.dewPointFast(), 1) ;
tft.drawLine (0, 110, tft.width ()-1, 110, ST7735_WHITE) ;
tft.setCursor(0,115) ;
TFT.Print (« intensité lumineuse") ;
int val = analogRead(ANALOG_IN) ;
tft.setCursor (60, 130) ;
tft.setTextColor (ST7735_YELLOW, ST7735_BLACK) ;
TFT.println (val, 1) ;
Delay(2000) ;
Delay(500) ; Attendre 50ms entre les pings (environ 20 pings/sec). 29ms devrait être le délai le plus court entre les pings.
unsigned int nous = sonar.ping() ; Envoyer des ping, ping temps en microsecondes (nous).
tft.setCursor(0,130) ;
tft.setTextColor(ST7735_RED) ;
TFT.Print ("Distance:") ;
tft.setTextColor (ST7735_YELLOW, ST7735_BLACK) ;
TFT.Print(US / US_ROUNDTRIP_CM) ; Convertir les temps de ping à distance et d’imprimer le résultat (0 = distance définie hors plage, aucun écho de ping)
tft.setTextColor(ST7735_RED,ST7735_BLACK) ;
TFT.Print ("cm") ;
Delay(50) ;
tft.fillScreen(ST7735_BLACK) ;
}
void tftPrintTest() {}
tft.setTextWrap(false) ;
tft.fillScreen(ST7735_BLACK) ;
tft.setCursor (0, 10) ;
tft.setTextColor(ST7735_WHITE) ;
tft.setTextSize(1) ;
TFT.println(" ;
Delay(500) ;
tft.setCursor (0, 60) ;
tft.setTextColor(ST7735_RED) ;
tft.setTextSize(2) ;
TFT.println("Temperature") ;
tft.setTextColor(ST7735_YELLOW) ;
tft.setTextSize(2) ;
TFT.println("Humidity") ;
tft.setTextColor(ST7735_GREEN) ;
tft.setTextSize(2) ;
TFT.println("Monitor") ;
tft.setTextColor(ST7735_BLUE) ;
tft.setTextSize(3) ;
TFT.Print(3598865) ;
Delay(50) ;
}
void testfastlines (uint16_t color1, color2 uint16_t) {}
tft.fillScreen(ST7735_BLACK) ;
pour (int16_t y = 0; y < tft.height(); y += 5) {}
tft.drawFastHLine (0, y, tft.width(), color1) ;
}
pour (int16_t x = 0; x < tft.width() ; x+= 5) {}
tft.drawFastVLine (x, 0, tft.height(), color2) ;
}
}
void testdrawrects (couleur uint16_t) {}
tft.fillScreen(ST7735_BLACK) ;
pour (int16_t x = 0; x < tft.width() ; x+= 6) {}
tft.drawRect (tft.width () / 2 - x / 2, tft.height () / 2 - x / 2, x, x, couleur) ;
}
}