简体   繁体   English

arduino中的实时条形图

[英]Real Time Bar Charts in arduino

I have written a test program to see that my pressure sensor is working correctly and it does. 我编写了一个测试程序,以查看我的压力传感器是否正常工作并且可以正常工作。

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;
  }
}

So in this code above, what I want to do is to store all the times the functions write either red, green, blue, yellow, etc. and display it on a computer screen in real time bar graphs. 因此,在上面的代码中,我要做的就是存储函数编写红色,绿色,蓝色,黄色等的所有时间,并将其实时显示在计算机屏幕上。 Something like Flot Examples but with bars. Flot Example一样,但带有条形。

So naturally I need to do somehing like this: 所以自然地,我需要做这样的事情:

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;
}

How can this be achieved since Arduino is a very limited language? 由于Arduino语言非常有限,如何实现? I was thinking about writing these variable values to a simple .json file and read them from there with jQuery, but I don't know how to do that either. 我当时正在考虑将这些变量值写入一个简单的.json文件,并使用jQuery从那里读取它们,但是我也不知道该怎么做。 Is there a smarter solution? 有没有更聪明的解决方案?

I'm using an Arduino Mega . 我正在使用Arduino Mega

First, you are going to have something going between JQuery and the Arduino Mega. 首先,您需要在JQuery和Arduino Mega之间进行操作。 Some of your options are: 您的一些选择是:

  • Access the arudino through a usb cable and use some sort of server based technology to access it, such as php. 通过USB电缆访问arudino,并使用某种基于服务器的技术来访问它,例如php。 There is an example of how to do this here: 这里有一个如何执行此操作的示例:

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

  • Use an ethernet or wifi shield and provide the data back in the format of your choice. 使用以太网或wifi防护罩,并以您选择的格式提供数据。 This would add about $30-60 to your cost but make the arduino part of this project self contained and not require a computer for it to run. 这将使您的成本增加30-60美元左右,但会使该项目的arduino部分完全独立,并且不需要计算机即可运行。

  • if you want it wireless you could look into bluetooth and zigbee recievers. 如果您想要无线,则可以研究蓝牙和Zigbee接收器。 you would still need a server and something like php with this option. 您仍然需要带有此选项的服务器和类似php的文件。

  • for flash, you typically use something called a serial socket server. 对于闪存,通常使用称为串行套接字服务器的东西。 There is more inforamation about this on the Aruduino Playground . Aruduino游乐场上有更多有关此的信息 It is possible you could also access the same type of server through jquery directly. 您也可以直接通过jquery访问相同类型的服务器。 This would be similar to the first option and would require a direct usb connection to the computer. 这将与第一个选项相似,并且需要直接将USB连接到计算机。

If you wanted to try something different, I would recommend looking at processing and firmata as there are lots of examples of how take data from an arduino and create some sort of visual based on that data. 如果您想尝试不同的方法,我建议您看一下处理固件,因为有许多示例说明如何从arduino中获取数据并基于这些数据创建某种视觉效果。

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

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