- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在对传感器节点 (XM1000) 进行编程,我正在使用 Contiki 操作系统对该设备进行编程(我正在使用终端查看输出,并使用 GEdit 写入我的“C”代码。该传感器节点具有温度、光照板载湿度传感器以及 3 个 LED 灯。
下面我有两组代码。第一组代码起作用并为我提供温度、光照和湿度值的传感器读数。
第二组代码函数。它打开/关闭 LED 灯并使其在传感器节点 XM1000 上定期闪烁,计算 LED 闪烁的次数并将计数输出到控制台。
我遇到的问题是创建一个 if 语句来满足以下条件,并且我正在努力将两个代码组合在一起。这就是我想要实现的目标:
• 如果温度超过 26 度,则打开 LED 灯 1 5 秒,否则,如果温度等于或低于 26 度,则关闭 LED 灯 1。
• 如果湿度超过 40%,则打开 LED 灯 2 5 秒,否则,如果湿度等于或低于 40%,则关闭 LED 灯 2。
• 如果光强度超过 510 纳米,则打开 LED 灯 3 5 秒,否则如果光强度等于或低于 510 纳米,则关闭 LED 灯 3。
第一组代码:它测量温度、光照和湿度,并将结果输出到终端窗口上。
#include "contiki.h" //Contiki Header File
#include "dev/light-sensor.h" //Light Sensor Header File
#include "dev/sht11-sensor.h" //Temperature and Humidity Header File
#include <stdio.h> /* for printf() */ // standard input/output library needed to write to the standard output
static struct etimer timer; //Process Requires a Timer
int light=0, temp=0, humid=0;
//To Start
/*___________________________________________________*/
PROCESS(sensor_reading_process, "Sensor Reading Process");
AUTOSTART_PROCESSES(&sensor_reading_process);
/*___________________________________________________*/
//PROCESS BEGINS
PROCESS_THREAD(sensor_reading_process, ev, data)
{
PROCESS_BEGIN();
SENSORS_ACTIVATE(light_sensor); //Activate the Light Sensor
SENSORS_ACTIVATE(sht11_sensor);//Activate Temp/Humidity Sensor
etimer_set(&timer, CLOCK_CONF_SECOND);//Configuring Timer 1SEC
while(1) { //Start of While Loop
PROCESS_WAIT_EVENT_UNTIL(ev==PROCESS_EVENT_TIMER);//Wait4Time
// This is how we get the Sensor Values for light, temp, hum
light = light_sensor.value(LIGHT_SENSOR_PHOTOSYNTHETIC);
temp = sht11_sensor.value(SHT11_SENSOR_TEMP);
humid = sht11_sensor.value(SHT11_SENSOR_HUMIDITY);
printf("Light=%d, Temp=%d, Humid=%d\n", light, temp, humid);
//Above Line if Print Plus Values
etimer_reset(&timer); //Reset the Timer
}
PROCESS_END(); //End of Process
}
第二个代码:
#include "contiki.h"
#include "leds.h" // LED HEADER FILE
#include <stdio.h> /* for printf() */
static struct etimer timer;
/*____________________________________________________*/
PROCESS(led_blinking_process, "LED Blinking Process");
PROCESS(LED_process, "LED process");
AUTOSTART_PROCESSES(&LED_process);
/*____________________________________________________*/
PROCESS_THREAD(LED_process, ev, data)
{
static int count = 0;
PROCESS_BEGIN();
etimer_set(&timer, CLOCK_CONF_SECOND/2); // 0.5S timer
leds_init(); // initialise the LEDs
while(1) {
PROCESS_WAIT_EVENT_UNTIL(ev==PROCESS_EVENT_TIMER); // wait for timer event
count++; // count the blinking times
process_start(&led_blinking_process, NULL); // to blink the BLUE Led
printf("Count: %d\n", count); // output the counter number to console
etimer_reset(&timer); // reset the timer
}
PROCESS_END();
}
CODE FOR LED LIGHTS
/*____________________________________________________*/
PROCESS_THREAD(led_blinking_process, ev, data)
{
PROCESS_BEGIN();
leds_toggle(LEDS_BLUE); // Blinking the Blue LED
PROCESS_END();
}
请注意,当我运行这两个代码时,它们都是有效的,我只是想将它们组合起来,使用 if 语句,这样我就可以满足我上面提到的功能。
预先感谢您的任何帮助或贡献!
最佳答案
这就是我认为它会是什么样子,给予或采取一点黑客攻击。我将代码构建为单个循环,仅以 5 秒的间隔轮询所有三个传感器。因此,每 5 秒,所有三个灯的开/关状态可能会发生变化。我认为浇草坪时,你并不需要瞬间精确地知道什么时候变热,什么时候变黑,或者什么时候。
根据您在OP评论部分的回复,可能需要完成一些涉及传感器读数返回值的计算。我认为在编译时进行计算可能更容易,因此代码是有偏见的。
#include <stdio.h> /* for printf() */
#include "contiki.h"
#include "leds.h"
#include "dev/light-sensor.h"
#include "dev/sht11-sensor.h"
PROCESS(Led_management_process, "LED Management Process");
AUTOSTART_PROCESSES(&Led_management_process);
static struct etimer Timer;
/* Per the online docs at http://www.advanticsys.com/wiki/index.php?title=TestCM5000
T = -39.6 + 0.01 × SO(T)
So, solving for SOt gives:
*/
#define degreesC(n) (n)
#define TEMP_D1 degreesC(-39.6)
#define TEMP_D2 degreesC(0.01)
#define TEMP_THRESHOLD(tempC) (int)(((((double)(tempC))-(TEMP_D1))/(TEMP_D2)))
#define TARGET_TEMP_READING TEMP_THRESHOLD(degreesC(26))
#define LIGHT_LED LEDS_GREEN
#define HUM_LED LEDS_BLUE
#define TEMP_LED LEDS_RED
PROCESS_THREAD(Led_management_process, ev, data)
{
static int humidity_led_on = 0;
static int light_led_on = 0;
static int temp_led_on = 0;
PROCESS_BEGIN();
SENSORS_ACTIVATE(light_sensor);
SENSORS_ACTIVATE(sht11_sensor);
leds_init();
unsigned int cycle = 0;
while (1) {
printf("%8u:", cycle);
/* This part is questionable, since I don't know if the
sensors are guaranteed to return ints (vs. floats or
something) and I don't know what units they use. */
int temp = sht11_sensor.value(SHT11_SENSOR_TEMP);
if (temp > TARGET_TEMP_READING) {
printf(" TEMP warm- ");
if (!temp_led_on) {
printf("toggle LED");
temp_led_on = 1;
leds_toggle(TEMP_LED);
}
else {
printf("LED is ok ");
}
}
else {
printf(" TEMP cold- ");
if (temp_led_on) {
printf("toggle LED");
temp_led_on = 0;
leds_toggle(TEMP_LED);
}
else {
printf("LED is ok ");
}
}
/* Code for humidity */
/* Code for light */
printf("\n");
/* Sleep 5 seconds */
etimer_set(&Timer, CLOCK_CONF_SECOND * 5);
PROCESS_WAIT_EVENT_UNTIL(ev==PROCESS_EVENT_TIMER);
etimer_reset(&Timer);
++cycle;
}
PROCESS_END();
}
关于c - 使用 C 编程语言对 XM1000 传感器设备进行编程 需要 if 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36828908/
我想通过自己编写的C API来控制一些物理引擎,开关,灯光。 我已经对如何实现这一目标有了一个非常全面的概述: 使用内核抽象,在其上编写驱动程序并将其用作控制。驱动程序本身必须管理传入字节并解释它们(
过去做过一些 Android 开发,但已经有一段时间了 - 想构建一个使用方向和接近传感器的应用程序。所以... mSensorManager = (SensorManager) getSystemS
Android SDK 实际上提供了一个很好的接口(interface)来访问传感器。但是例如线性加速度传感器可以评估为 documentation从重力和加速度描述 - 所以这个传感器没有真正的物理
我是 android 开发的新手,我需要查看 android 3.1 设备上的传感器列表。 我有这个代码: package milos.exemplesensorlist; import java.u
我正在尝试为网络传感器实现虫洞攻击检测程序。我在互联网上四处寻找这方面的源代码,但一无所获。有谁知道在哪里可以找到虫洞传感器攻击(用于模拟目的)或虫洞检测的源代码?如果是这样,在哪里?它可以是任何编程
有没有办法使用内置传感器从 Android 手机获取二氧化碳。目前我通过环境传感器获得的是当前速度、气压、湿度和噪音幅度。 如果这是不可能的,有没有一种方法可以计算二氧化碳(该值可以是估计值)? 最佳
我正在尝试访问我的 Samsung Galaxy S3 上的传感器(特别是接近传感器和 RGBW 传感器),并且已获得可运行的代码来访问接近传感器。但是,我只得到值 1 或 8(近/远)。我知道有时硬
我想知道是否可以通过javascript获取诺基亚5800的传感器值。我知道在 HTML5 中有一个事件 DeviceOrientationEvent 可以提供一些值。但由于诺基亚 5800 没有 H
我想知道如何正确使用“旋转 vector 传感器”的输出。目前我想到了以下内容,并想根据 result[] 计算偏航和俯仰,以便了解设备指向的位置(处于横向模式)。但我对结果有疑问。偏航计算非常精确,
我正在编写一个方法,如果存在并启用了 GPS 传感器,该方法将返回 true,但如果不存在或已关闭,则返回 false。事实证明这很难,因为... hasSystemFeature("FEATURE_
我正在尝试从 Samsung Galaxy Tab GT-P1000 读取多个传感器,相对于我使用的应用程序,它们似乎非常占用 CPU。 作为测试,我创建了一个简短的程序,它为加速度计传感器实现了 S
我正在像这样从重新启动的接收步骤创建一个演示。 public class MainActivity extends AppCompatActivity implements SensorEventLi
我正在开发用于汽车加速跟踪的应用程序。我使用标准加速度计,事先在特定位置进行校准。 然后,假设手机的方向没有改变,我记录了指定时间的加速度计数据并计算了移动参数,其中之一是测试结束时汽车的速度。 在笔
下面是API中定义的几个代表sensor的常量。 Int TYPE_ACCELEROMETER A constant desc
我使用的 Arduino 具有多个 (3) 个传感器,使用正常模式(非寄生模式)连接到数字引脚 2。 其中两个传感器是使用库“OneWire”(Library Page)和“DallasTempera
我想让 android 传感器与 opengl 一起工作,以将 opengl 的相机旋转到手机指向的任何地方。 详细说明:如果玩家正在看东方,我希望 opengl 的相机在游戏中也指向东方;如果玩家指
我正在使用 Google Cardboard(它的 HeadTracker 类)来检测 AR 应用程序中有关设备旋转的某些事情。效果很好。 但是,在某些设备上,它不起作用(没有任何反应)。我认为这是因
是否有适用于 Apple Watch Kit 传感器(例如加速度计、心率监测器、触觉传感器)的 API? 我如何访问这些传感器? 最佳答案 WatchOS 2.0 的 Watchkit 中现已提供传感
我正在学习如何使用 Pyfst 创建换能器,并且我正在尝试可视化我创建的换能器。最终目标是能够将传感器写入点文件并在 Graphviz 中查看它们。 我拿了一个示例代码来看看如何可视化下面的接受器。
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
我是一名优秀的程序员,十分优秀!