TA的每日心情 | 难过 2014-9-4 00:09 |
---|
签到天数: 1 天 连续签到: 1 天 [LV.1]初来乍到
|
大家好,我是一个新手。之前用Arduino HC05的蓝牙模块用安卓手机控制继电器,在x宝上买的设备和板子,所以卖家给我了所有的代码和app。现在我想用Galileo去控制,不知道Galieo上能不能达到之前的效果。我发现不能用Arduino uno上的代码用在Galieo上,需要怎么修改呢? 多谢啦
/*
* Android app control Relay
*/
#include <Arduino.h>
#include "HC05.h"
#ifdef HC05_SOFTWARE_SERIAL
#include <SoftwareSerial.h>
HC05 btSerial = HC05(A2, A5, A3, A4); // cmd, state, rx, tx
#else
HC05 btSerial = HC05(3, 2); // cmd, state
#endif
char command[3]={0};
char i = 0;
int Relay1_GPIO = 4;
int Relay2_GPIO = 5;
int Relay3_GPIO = 6;
int Relay4_GPIO = 7;
int Relay5_GPIO = 8;
int Relay6_GPIO = 9;
void setup()
{
DEBUG_BEGIN(57600);
btSerial.findBaud();
Init_GPIO();
}
void loop()
{
char n = 0;
while (btSerial.connected())
{
if (btSerial.available())
{
command[i++] = btSerial.read();
if(3 == i)
{
i = 0;
switch(command[1])
{
case '1':
if(command[2] == '1')
{
digitalWrite(Relay1_GPIO,HIGH);
}
else
{
digitalWrite(Relay1_GPIO,LOW);
}
break;
case '2':
if(command[2] == '1')
{
digitalWrite(Relay2_GPIO,HIGH);
}
else
{
digitalWrite(Relay2_GPIO,LOW);
}
break;
case '3':
if(command[2] == '1')
{
digitalWrite(Relay3_GPIO,HIGH);
}
else
{
digitalWrite(Relay3_GPIO,LOW);
}
break;
case '4':
if(command[2] == '1')
{
digitalWrite(Relay4_GPIO,HIGH);
}
else
{
digitalWrite(Relay4_GPIO,LOW);
}
break;
case '5':
if(command[2] == '1')
{
digitalWrite(Relay5_GPIO,HIGH);
}
else
{
digitalWrite(Relay5_GPIO,LOW);
}
break;
case '6':
if(command[2] == '1')
{
digitalWrite(Relay6_GPIO,HIGH);
}
else
{
digitalWrite(Relay6_GPIO,LOW);
}
break;
}
}
}
}
}
void Init_GPIO(void)
{
pinMode(Relay1_GPIO, OUTPUT); // sets the digital pin as output
pinMode(Relay2_GPIO, OUTPUT); // sets the digital pin as output
pinMode(Relay3_GPIO, OUTPUT); // sets the digital pin as output
pinMode(Relay4_GPIO, OUTPUT); // sets the digital pin as output
pinMode(Relay5_GPIO, OUTPUT); // sets the digital pin as output
pinMode(Relay6_GPIO, OUTPUT); // sets the digital pin as output
}
|
|