Stap 9: Sketch om te controleren de relais met uw geest
Deze sketch is bewerkt sneller de lus wordt uitgevoerd... vernieuwingsfrequentie is ongeveer 1.5 seconden.
Kopieer de schets hieronder en plak het in de Arduino IDE controleren en uitvoeren van het programma.
deze schets is gemaakt met behulp van de code uit de adafruit en hersenen-libraries
#define sclk 4
#define mosi 5
#define cs 6
#define dc 7
#define rst 8
Aangesloten op de Arduino GND GND
int Pin1 = 9; IN1 verbonden met digitale 9
int Pin2 = 10; In2 verbonden met digitale 10
int Pin3 = 11; Aangesloten op digital 11 3
int Pin4 = 12; IN4 verbonden met digitale 12
VCC aangesloten op de Arduino + 5v
#include < Adafruit_GFX.h > / / Core grafische bibliotheek
#include < Adafruit_ST7735.h > / / hardwarespecifieke bibliotheek
#include < SPI.h >
#include < Brain.h >
Adafruit_ST7735 tft = Adafruit_ST7735 (cs, dc, mosi, sclk, rst);
Brain brain(Serial);
ongeldig setup(void) {}
tft.initR(INITR_BLACKTAB); initialiseren van een tab ST7735S-chip, zwart
pinMode (Pin1, uitvoer);
pinMode (PIN2-, OUTPUT);
pinMode (Pin3, uitvoer);
pinMode (Pin4, uitvoer);
digitalWrite (Pin1, 1);
digitalWrite (Pin2, 1);
digitalWrite (Pin3, 1);
digitalWrite (Pin4, 1);
tftPrintTest(); Eerste introductie tekst,
delay(1000);
tft.fillScreen(ST7735_BLACK); scherm wissen
tft.setTextColor(ST7735_WHITE);
tft.setTextSize(1);
tft.setCursor(30,0);
TFT.println ("Brain beheer");
Serial.begin(9600);
}
void loop {}
Als (brain.update()) {}
Als (brain.readSignalQuality() > 199) {}
tft.fillScreen(ST7735_BLACK);
tft.setCursor(10,60);
tft.setTextSize(1);
tft.setTextColor(ST7735_RED,ST7735_BLACK);
TFT.println ("SQ low");
tft.fillScreen(ST7735_BLACK);
}
else {}
tft.setCursor(30,0);
tft.setTextSize(1);
TFT.println ("Brain beheer");
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 ("signaal kwaliteit:");
TFT.Print(Brain.readSignalQuality());
TFT.println("");
TFT.println("");
tft.setTextColor(ST7735_GREEN,ST7735_BLACK);
TFT.println ("aandacht:");
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 ("meditatie:");
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); kleur voor TIME ON instellen
tft.setTextSize (1), de grootte van de tekst van de //set
TFT.Print ("Relay 1 is op");
digitalWrite (Pin1, 0);
}
else {}
tft.setCursor(0,140);
tft.setTextColor(ST7735_RED,ST7735_BLACK); kleur voor tijd OFF instellen
tft.setTextSize (1), de grootte van de tekst van de //set
TFT.Print ("Relay 1 is uitgeschakeld');
digitalWrite (Pin1, 1);
}
}
if(Brain.readAttention() > 50) {}
tft.setCursor(0,75);
tft.setTextColor(ST7735_GREEN,ST7735_BLACK); kleur voor TIME ON instellen
tft.setTextSize (1), de grootte van de tekst van de //set
TFT.Print ("Relay 2 is op");
digitalWrite (Pin2, 0);
}
else {}
tft.setCursor(0,75);
tft.setTextColor(ST7735_RED,ST7735_BLACK); kleur voor tijd OFF instellen
tft.setTextSize (1), de grootte van de tekst van de //set
TFT.Print ("Relay 2 is uitgeschakeld');
digitalWrite (Pin2, 1);
}
if(Brain.readMeditation() > 50) {}
tft.setCursor(0,118);
tft.setTextColor(ST7735_GREEN,ST7735_BLACK); kleur voor TIME ON instellen
tft.setTextSize (1), de grootte van de tekst van de //set
TFT.Print ("Relay 3 is op");
digitalWrite (Pin3, 0);
}
else {}
tft.setCursor(0,118);
tft.setTextColor(ST7735_RED,ST7735_BLACK); kleur voor tijd OFF instellen
tft.setTextSize (1), de grootte van de tekst van de //set
TFT.Print ("Relay 3 is uitgeschakeld');
digitalWrite (Pin3, 1);
}}}
ongeldig 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);
}