繁体   English   中英

arduino中的实时条形图

[英]Real Time Bar Charts in arduino

我编写了一个测试程序,以查看我的压力传感器是否正常工作并且可以正常工作。

int redpin = 10;
int greenpin = 9;
int bluepin = 8;
int presurepin = 0;

//Program variables
int time = 100;
int presure = 0;
int thresholddown = 19;
int thresholdup = 52;
int color = 0;
int red   = 0;
int green = 0;
int blue  = 0;
int relesepresure = 1;

void setup() {
  pinMode(redpin, OUTPUT);
  pinMode(greenpin, OUTPUT);
  pinMode(bluepin, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  // Read presure
  presure = analogRead(presurepin);

  // For bug finding purpose
  delay(time);
  Serial.print(presure);
  Serial.print("   ");
  Serial.println(color);

  // High presure = 0 low = 300-500
  // If high presure change color and wait until presure is low to send out the color
  if (presure < thresholddown && relesepresure == 1){
    if (color == 0){
          red   = 0;
          green = 0;
          blue  = 0;
          color = color + 1;
    }
    else if (color == 1) {
          red   = 1;
          green = 0;
          blue  = 0;
          color = color + 1;
    }
    else if (color == 2) {
          red   = 0;
          green = 1;
          blue  = 0;
          color = color + 1;
    }
    else if (color == 3) {
          red   = 0;
          green = 0;
          blue  = 1;
          color = color + 1;
    }
    else if (color == 4) {
          // Yellow
          red   = 1;
          green = 1;
          blue  = 0;
          color = 1;

    }
    // Turn of light while tile is presured
    digitalWrite(redpin,   0);   // Write current values to LED pins
    digitalWrite(greenpin, 0);
    digitalWrite(bluepin,  0);
    relesepresure = 0;
  }
  else if (presure > thresholdup && relesepresure == 0){
      //Send color to tile
      digitalWrite(redpin,   red);
      digitalWrite(greenpin, green);
      digitalWrite(bluepin,  blue);
      relesepresure = 1;
  }
}

因此,在上面的代码中,我要做的就是存储函数编写红色,绿色,蓝色,黄色等的所有时间,并将其实时显示在计算机屏幕上。 Flot Example一样,但带有条形。

所以自然地,我需要做这样的事情:

else if (color == 3) {

      //Color3++;
      //Update the bar graph with the new values (Color1,0),(Color2,1), (Color3,2), (Color4,3) where the numbers inside the paragraph are the x,y values of the graph.

      red   = 0;
      green = 0;
      blue  = 1;
      color = color + 1;
}

由于Arduino语言非常有限,如何实现? 我当时正在考虑将这些变量值写入一个简单的.json文件,并使用jQuery从那里读取它们,但是我也不知道该怎么做。 有没有更聪明的解决方案?

我正在使用Arduino Mega

首先,您需要在JQuery和Arduino Mega之间进行操作。 您的一些选择是:

  • 通过USB电缆访问arudino,并使用某种基于服务器的技术来访问它,例如php。 这里有一个如何执行此操作的示例:

http://wanderr.com/jay/controlling-arduino-via-serial-usb-php/2010/12/28/

  • 使用以太网或wifi防护罩,并以您选择的格式提供数据。 这将使您的成本增加30-60美元左右,但会使该项目的arduino部分完全独立,并且不需要计算机即可运行。

  • 如果您想要无线,则可以研究蓝牙和Zigbee接收器。 您仍然需要带有此选项的服务器和类似php的文件。

  • 对于闪存,通常使用称为串行套接字服务器的东西。 Aruduino游乐场上有更多有关此的信息 您也可以直接通过jquery访问相同类型的服务器。 这将与第一个选项相似,并且需要直接将USB连接到计算机。

如果您想尝试不同的方法,我建议您看一下处理固件,因为有许多示例说明如何从arduino中获取数据并基于这些数据创建某种视觉效果。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM