Étape 9: Esquisse pour contrôler les relais avec votre esprit
Cette esquisse a été modifiée pour exécuter la boucle plus vite... taux de rafraîchissement est d’environ 1,5 secondes.
Copiez le schéma ci-dessous et le coller dans l’IDE Arduino vérifier et exécuter le programme.
cette esquisse a été créée à l’aide de code à partir du adafruit et cerveau-bibliothèques
#define sclk 4
#define mosi 5
#define cs 6
#define dc 7
#define rst 8
GND relié au GND de l’Arduino
int Broche1 = 9 ; IN1 connecté au numérique 9
int broche 2 = 10 ; IN2 connecté à 10 numérique
int Pin3 = 11 ; In3 connecté à 11 numérique
int broche4 = 12 ; IN4 relié à 12 numérique
VCC connecté à Arduino + 5v
#include < Adafruit_GFX.h > / / bibliothèque graphique de base
#include < Adafruit_ST7735.h > / / spécifiques au matériel bibliothèque
#include < SPI.h >
#include < Brain.h >
Tft Adafruit_ST7735 = Adafruit_ST7735 (cs, dc, mosi, sclk, rst) ;
Brain(Serial) cerveau ;
void setup(void) {}
tft.initR(INITR_BLACKTAB) ; initialiser un onglet de puce, noire ST7735S
pinMode (Pin1, sortie) ;
pinMode (Pin2, sortie) ;
pinMode (broche 3, sortie) ;
pinMode (Pin4, sortie) ;
digitalWrite (broche 1, 1) ;
digitalWrite (Pin2, 1) ;
digitalWrite (broche 3, 1) ;
digitalWrite (Pin4, 1) ;
tftPrintTest() ; Texte de l’introduction initiale,
Delay(1000) ;
tft.fillScreen(ST7735_BLACK) ; effacer l’écran
tft.setTextColor(ST7735_WHITE) ;
tft.setTextSize(1) ;
tft.setCursor(30,0) ;
TFT.println ("Brain Control") ;
Serial.Begin(9600) ;
}
void loop() {}
Si (brain.update()) {}
Si {(brain.readSignalQuality() > 199)
tft.fillScreen(ST7735_BLACK) ;
tft.setCursor(10,60) ;
tft.setTextSize(1) ;
tft.setTextColor(ST7735_RED,ST7735_BLACK) ;
TFT.println ("low SQ ») ;
tft.fillScreen(ST7735_BLACK) ;
}
else {}
tft.setCursor(30,0) ;
tft.setTextSize(1) ;
TFT.println ("Brain Control") ;
tft.drawLine (0, 20, tft.width ()-1, 20, ST7735_WHITE) ;
tft.drawLine (0, 130, tft.width ()-1, 130, ST7735_WHITE) ;
tft.setCursor (0, 30) ;
tft.setTextColor(ST7735_YELLOW,ST7735_BLACK) ;
tft.setTextSize(1) ;
TFT.Print (« signal de qualité: ") ;
TFT.Print(Brain.readSignalQuality()) ;
TFT.println("") ;
TFT.println("") ;
tft.setTextColor(ST7735_GREEN,ST7735_BLACK) ;
TFT.println ("Attention:") ;
tft.setTextSize(2) ;
tft.setCursor (60, 60) ;
TFT.Print(Brain.readAttention()) ;
TFT.println("") ;
tft.setTextColor(ST7735_WHITE,ST7735_BLACK) ;
tft.setTextSize(1) ;
TFT.println("") ;
TFT.Print ("méditation:") ;
tft.setTextSize(2) ;
tft.setCursor (60, 100) ;
TFT.Print(Brain.readMeditation()) ;
TFT.println("") ;
if(Brain.readSignalQuality() == 0) {}
tft.setCursor(0,140) ;
tft.setTextColor(ST7735_GREEN,ST7735_BLACK) ; définir la couleur pour le moment ON
tft.setTextSize (1); //set la taille du texte
TFT.Print ("Relais 1 est sur") ;
digitalWrite (Pin1, 0) ;
}
else {}
tft.setCursor(0,140) ;
tft.setTextColor(ST7735_RED,ST7735_BLACK) ; définir la couleur pour TIME OFF
tft.setTextSize (1); //set la taille du texte
TFT.Print ("Relais 1 est éteint") ;
digitalWrite (broche 1, 1) ;
}
}
{if(Brain.readAttention() > 50)
tft.setCursor(0,75) ;
tft.setTextColor(ST7735_GREEN,ST7735_BLACK) ; définir la couleur pour le moment ON
tft.setTextSize (1); //set la taille du texte
TFT.Print ("Relais 2 est sur") ;
digitalWrite (Pin2, 0) ;
}
else {}
tft.setCursor(0,75) ;
tft.setTextColor(ST7735_RED,ST7735_BLACK) ; définir la couleur pour TIME OFF
tft.setTextSize (1); //set la taille du texte
TFT.Print ("Relais 2 est éteint") ;
digitalWrite (Pin2, 1) ;
}
{if(Brain.readMeditation() > 50)
tft.setCursor(0,118) ;
tft.setTextColor(ST7735_GREEN,ST7735_BLACK) ; définir la couleur pour le moment ON
tft.setTextSize (1); //set la taille du texte
TFT.Print ("Relais 3 est sur") ;
digitalWrite (broche 3, 0) ;
}
else {}
tft.setCursor(0,118) ;
tft.setTextColor(ST7735_RED,ST7735_BLACK) ; définir la couleur pour TIME OFF
tft.setTextSize (1); //set la taille du texte
TFT.Print ("Relais 3 est éteint") ;
digitalWrite (broche 3, 1) ;
}}}
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 (30, 60) ;
tft.setTextColor(ST7735_RED) ;
tft.setTextSize(2) ;
TFT.println("Brain") ;
tft.setTextColor(ST7735_YELLOW) ;
tft.setCursor (5, 80) ;
TFT.println ("Controler") ;
tft.setTextColor(ST7735_BLUE) ;
Delay(50) ;
}