Stap 12: Mening gecontroleerde laser lichtshow Code
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 verbonden laser-
int Pin2 = 10; In2 verbonden met digitale 10 verbonden met de motor 2-
int Pin3 = 11; 3 aangesloten op digitale 11 verbonden met motor 1-
int Pin4 = 12; IN4 verbonden met digitale 12 hier niet gebruikt
motor 1 & 2 +, en laser + verbinden met 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_CYAN,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 ("LASER is op");
digitalWrite (Pin1, 0);
}
else {}
tft.setCursor(0,140);
tft.setTextColor(ST7735_RED,ST7735_BLACK); kleur voor TIME ON instellen
tft.setTextSize (1), de grootte van de tekst van de //set
TFT.Print ("LASER is uitgeschakeld');
digitalWrite (Pin1, 1);
}
}
if(Brain.readAttention() > 5) {}
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 ("MOTOR 2 is ON");
analogWrite (PIN2-, brain.readAttention());
}
else {}
tft.setCursor(0,75);
tft.setTextColor(ST7735_RED,ST7735_BLACK); kleur voor TIME ON instellen
tft.setTextSize (1), de grootte van de tekst van de //set
TFT.Print ("MOTOR 2 is OFF");
digitalWrite (Pin2, 1);
}
if(Brain.readMeditation() > 5) {}
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 ("MOTOR 1 is ON");
analogWrite (Pin3, brain.readMeditation());
}
else {}
tft.setCursor(0,118);
tft.setTextColor(ST7735_RED,ST7735_BLACK); kleur voor TIME ON instellen
tft.setTextSize (1), de grootte van de tekst van de //set
TFT.Print ("MOTOR 1 is OFF");
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);
}