Étape 4: Arduino programme
Bibliothèque de Arduino cerveau - cerveau essai de série
Description : Saisit les données de cerveau de la broche RX série et envoie CSV sur la broche TX (Half duplex.) / / plus d’informations : https://github.com/kitschpatrol/Arduino-Brain-Library
#include #include servo myservo ; Créez l’objet servo pour contrôler un servo / / peut créer un maximum de huit objets servo Servo myservo1 ; int pos = 0 ; pos1 int = 0 ; variable pour stocker la position du servo / / ensemble vers le haut de l’analyseur de cerveau, passez-lui l’objet de série de matériel que vous souhaitez écouter sur. Brain(Serial) cerveau ;
void setup() {/ / le matériel de démarrage série. Serial.Begin(9600) ; myservo.Attach(9) ; myservo1.Attach(10) ; }
void loop() { // Expect packets about once per second. // The .readCSV() function returns a string (well, char*) listing the most recent brain data, in the following format: // "signal strength, attention, meditation, delta, theta, low alpha, high alpha, low beta, high beta, low gamma, high gamma" if (brain.update()) { //Serial.println(brain.readErrors()); //Serial.println(brain.readCSV()); Serial.println(brain.readAttention()); if(brain.readAttention()>40) { for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees { // in steps of 1 degree myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } } else { myservo.write(0); } Serial.println(brain.readMeditation()); if(brain.readMeditation()>40) { for(pos1 = 0; pos1 < 180; pos1 += 1) // goes from 0 degrees to 180 degrees { // in steps of 1 degree myservo1.write(pos1); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } } else { myservo1.write(0); } } delay(10); }