added arduino_bluetooth

This commit is contained in:
Paul Lecuq 2016-09-03 11:39:49 +02:00
parent f0fb7dedc7
commit a8a5e32dc7

76
arduino_bluetooth.cpp Normal file
View File

@ -0,0 +1,76 @@
#define HC06 Serial1
const int second = 100;
bool var = false;
int ledmin = 8;
int ledmax = 13;
void setup()
{
delay(1000);
Serial.begin(9600);
// init module bluetooth
HC06.begin(9600);
// init sorties leds
for(int i=13;i>=6;i--){
pinMode(i,OUTPUT);
}
}
void up(int led,int second) {
digitalWrite(led,HIGH);
delay(second);
}
void down(int led,int second) {
digitalWrite(led,LOW);
delay(second);
}
void blink(bool dir) {
if (dir)
{
for(int j=ledmax;j>=ledmin;j--){
up(j,second);
}
for(int j=ledmax;j>=ledmin;j--){
down(j,second);
}
}
else
{
for(int j=ledmin;j<=ledmax;j++){
up(j,second);
}
for(int j=ledmin;j<=ledmax;j++){
down(j,second);
}
}
}
void loop() {
while(HC06.available())
{
char data = HC06.read();
Serial.write(data);
if (data == 'A')
{
blink(true);
}
if (data == 'B')
{
blink(false);
/*
for(int j=13;j>=6;j--){
down(j,second);
}*/
}
//HC06.write(data);
}
}