Jquery arduino中的实时条形图

Jquery arduino中的实时条形图,jquery,c,json,arduino,Jquery,C,Json,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 =

我已经写了一个测试程序,看看我的压力传感器是否工作正常,它是否工作正常

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;
  }
}
由于Arduino是一种非常有限的语言,如何实现这一点?我曾考虑将这些变量值写入一个简单的.json文件,然后用jQuery从中读取它们,但我也不知道如何做到这一点。有更聪明的解决方案吗


我使用的是。

首先,您将在JQuery和Arduino Mega之间找到一些东西。您的一些选择包括:

通过usb电缆访问arudino,并使用某种基于服务器的技术来访问它,例如php。这里有一个如何执行此操作的示例: 使用以太网或wifi屏蔽,以您选择的格式提供数据。这将增加约30-60美元的成本,但使该项目的arduino部分自给自足,不需要计算机来运行

如果你想要无线的话,你可以看看蓝牙和zigbee接收器。您仍然需要一个服务器和类似php的东西来使用此选项

对于flash,通常使用称为串行套接字服务器的东西。网上有更多关于这方面的信息。您也可以通过jquery直接访问同一类型的服务器。这与第一个选项类似,需要与计算机直接usb连接


如果你想尝试一些不同的东西,我建议你看看,因为有很多例子说明了如何从arduino获取数据,并根据这些数据创建某种视觉效果。

首先,你将在JQuery和arduino Mega之间找到一些东西。您的一些选择包括:

通过usb电缆访问arudino,并使用某种基于服务器的技术来访问它,例如php。这里有一个如何执行此操作的示例: 使用以太网或wifi屏蔽,以您选择的格式提供数据。这将增加约30-60美元的成本,但使该项目的arduino部分自给自足,不需要计算机来运行

如果你想要无线的话,你可以看看蓝牙和zigbee接收器。您仍然需要一个服务器和类似php的东西来使用此选项

对于flash,通常使用称为串行套接字服务器的东西。网上有更多关于这方面的信息。您也可以通过jquery直接访问同一类型的服务器。这与第一个选项类似,需要与计算机直接usb连接


如果你想尝试一些不同的东西,我建议你看看,因为有很多例子说明了如何从arduino获取数据,并根据这些数据创建某种视觉效果。

看看这是否有用:你能说明你想让graph stuff运行在哪个操作系统下吗。ie:windows、mac等。图形需要是web吗?您建议如何将值发送到pc?Usb/串行、网络或其他一些通信方法?您最好只将数据发送到计算机,例如使用串行电缆,让计算机处理数据。看看这是否有用:您能否说明希望图形在哪个操作系统下运行。ie:windows、mac等。图形需要是web吗?您建议如何将值发送到pc?Usb/串行、网络或其他一些通信方法?您最好只将数据发送到计算机,例如使用串行电缆,让计算机处理数据。非常感谢,为了精确显示oposite,如php示例中所示,namley从arduino获取数据,而不是将数据发送到arduino,但我会调查它,看看我是否能设法找出如何反转代码。Cheers=非常感谢,正如php示例中所示,namley从arduino获取数据,而不是将其发送给arduino,但将研究它,看看我是否能够找到如何反转代码的方法。干杯=
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;
}