// Arduino Brain Library
//基本的大脑示例,当您的“注意力”值增加时,更快地使针脚13上的LED闪烁。
//改编自Arduino环境下的Blink without Delay示例。#include <Brain.h>
/ *将此草图上传到Seeeduino并按下重置* /#include <SoftwareSerial.h> //软件串行端口
#define RxD 6
#define TxD 7SoftwareSerial blueToothSerial(RxD, TxD);//设置大脑解析器,将要传输的硬件序列对象传递给它。
Brain brain(Serial);const int ledPin = 13; //13很方便,因为它在板上。
long interval = 500; //基于注意力值的变化。
long previousMillis = 0;
int ledState = LOW; void setup(){//设置LED引脚。pinMode(ledPin, OUTPUT);//启动硬件序列。Serial.begin(9600);pinMode(RxD, INPUT);pinMode(TxD, OUTPUT);setupBlueToothConnection();
}void setup() {// Set up the LED pin. 点亮LEDpinMode(ledPin, OUTPUT);// Start the hardware serial. 启动硬件设备Serial.begin(9600); //初始化串口通信,并将波特率设置为9600pinMode(RxD, INPUT);pinMode(TxD, OUTPUT);setupBlueToothConnection();
}void loop() {// Expect packets about once per second. 预计每秒打包数据一次if (brain.update()) {blueToothSerial.println(brain.readCSV());// Attention runs from 0 to 100. 注意力从0增到100interval = (100 - brain.readAttention()) * 10;}// Make sure we have a signal. 确保我们收到了信号if(brain.readSignalQuality() == 0) {// Serial.write(blueToothSerial);// Blink the LED. 使LED闪烁if (millis() - previousMillis > interval) {// Save the last time you blinked the LED. 保持上次led闪烁的时间previousMillis = millis(); // If the LED is off turn it on and vice-versa: 如果led熄灭了,那么将其打开,反之亦然if (ledState == LOW)ledState = HIGH;elseledState = LOW;// Set the LED with the ledState of the variable:使用变量的ledState设置LED:digitalWrite(ledPin, ledState);} }else {digitalWrite(ledPin, LOW);}}
void setupBlueToothConnection()
{//将BluetoothBee BaudRate设置为默认波特率38400blueToothSerial.begin(38400); //Set BluetoothBee BaudRate to default baud rate 38400//将蓝牙设置为从属模式blueToothSerial.print("\r\n+STWMOD=0\r\n"); //set the bluetooth work in slave mode//将蓝牙名称设置为“SeeedBTSlave” blueToothSerial.print("\r\n+STNA=SeeedBTSlave\r\n"); //set the bluetooth name as "SeeedBTSlave"//允许配对设备连接我blueToothSerial.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me//这里禁止自动连接blueToothSerial.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here//此延迟是必需的。delay(2000); // This delay is required.//使隶属蓝牙不能再受访问blueToothSerial.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable //串口输出隶属蓝牙不能再受访问Serial.println("The slave bluetooth is inquirable!");//此延迟是必需的。delay(2000); // This delay is required.blueToothSerial.flush();
}