簡體   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