请耐心等待。我是Arduino的业余程序员,之前从未使用过粒子光子。
我使用了Arduino Uno并使用Grove Ear夹心跳传感器和Grove温度传感器编写附加代码来检测心跳和温度,然后每隔20秒在控制台中打印它们。以前,这段代码是为了在Grove OLED屏幕上显示,但后来将其简化为在没有OLED屏幕的情况下使用它。
我现在正在研究在粒子光子上使用相同的传感器使用相同的应用程序和功能(因为它更小并具有WiFi功能)。我之前从未使用过这项技术,但我在网上看到它或多或少使用相同的代码应用程序。我已经浏览了其网站上的在线示例代码,但我不知道如何将我的Arduino代码转换为光子代码(Photon控制台编译代码时没有任何错误,但没有显示任何传感器数据)。有人可以指出我正确的方向/适当的在线资源/帮助我在这里更改此代码,使其在Photon上工作? (我刚刚在我使用Arduino Particle.publish()
的任何地方添加了Serial.println()
,但它仍然没有打印任何内容。
控制台中的结果显示:
Please be ready
This will now begin
然后每秒打印1到20,然后是传感器读数。
再次感到不便,感谢您的帮助。
我使用了传感器文档博客中的直接代码(链接页面的页面底部):
Grove heart bear sensor
Grove Temperature sensor
#define LED 4//indicator, Grove - LED is connected with D4 of Arduino
boolean led_state = LOW;//state of LED, each time an external interrupt
//will change the state of LED
float tempa;
int tempPin = 0;
unsigned char counter;
unsigned long temp[21];
unsigned long sub;
bool data_effect=true;
unsigned int heart_rate;//the measurement result of heart rate
const int max_heartpluse_duty = 2000;//you can change it follow your system's request.
//2000 meams 2 seconds. System return error
//if the duty overtrip 2 second.
void setup()
{
pinMode(LED, OUTPUT);
Serial.begin(9600);
while (!Serial){
;
}
Serial.println("Please be ready");
delay(5000);
arrayInit();
Serial.println("This will now begin.");
attachInterrupt(0, interrupt, RISING);//set interrupt 0,digital port 2
}
void loop()
{
digitalWrite(LED, led_state);//Update the state of the indicator
}
/*Function: calculate the heart rate*/
void sum()
{
if(data_effect)
{
heart_rate=1200000/(temp[20]-temp[0]);//60*20*1000/20_total_time
Serial.print("Heart_rate_is:\t");
Serial.println(heart_rate);
tempa = analogRead(tempPin);
tempa = tempa * 0.11;
Serial.print("Body Temperature = ");
Serial.print(tempa);
Serial.print("*C");
Serial.println();
delay(1000);
}
data_effect=1;//sign bit
}
/*Function: Interrupt service routine.Get the sigal from the external interrupt*/
void interrupt()
{
temp[counter]=millis();
Serial.println(counter,DEC);
switch(counter)
{
case 0:
sub=temp[counter]-temp[20];
break;
default:
sub=temp[counter]-temp[counter-1];
break;
}
if(sub>max_heartpluse_duty)//set 2 seconds as max heart pluse duty
{
data_effect=0;//sign bit
counter=0;
Serial.println("measurement error,test will restart!" );
arrayInit();
}
else if (counter==20&&data_effect)
{
counter=0;
sum();
}
else if(counter!=20&&data_effect)
{
counter++;
}
else
{
counter=0;
data_effect=1;
}
}
/*Function: Initialization for the array(temp)*/
void arrayInit()
{
for(unsigned char i=0;i < 20;i ++)
{
temp[i]=0;
}
temp[20]=millis();
}