我在 Arduino Uno 上存储信息,然后,当我将 Arduino 插入电脑时,我希望 google chrome 读取传入的串行数据()。我找到了谷歌的 api http://developer.chrome.com/apps/serial,并认为这可以帮助我。但实际上我不知道如何使用它:D
这是我的 Arduino 代码,它工作正常:
//Importing libraries
#include <VirtualWire.h>
#include <stdio.h>
#include <LiquidCrystal.h>
#include <EEPROM.h>
//Main temperature variable
float temp2;
//Measurements saving variable
int addr = 0;
int address = 0;
int tvalue =0;
int svalue;
//Function for saving data to Arduino's storage
int save_data_to_storage()
{
EEPROM.write(addr, (temp2)*10);
addr = addr + 1;
if (addr == 12)
addr = 0;
delay(5000);
}
int save;
//Display variables
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
//Begin loops...
void setup()
{
//Initialize serial port bitRate
Serial.begin(9600);
//Alarm pin
pinMode(9, OUTPUT);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD For 7 seconds:
lcd.print("BALGHI");
delay(7000);
lcd.clear();
//Receiver set up
vw_set_rx_pin(8);
vw_rx_start();
vw_setup(2000);
}
void loop()
{
if (Serial.available() > 0) {
//Display USB Connection
lcd.clear();
lcd.print("BALGHI");
lcd.setCursor(0, 1);
lcd.print("USB Connection");
// Send the measurements values to the PC
svalue = EEPROM.read(address);
//Serial.write(svalue);
Serial.println(svalue, DEC);
address = address + 1;
if (address == 12){
address = 0;
//Delete all measurements data
/*for (int d = 0; d < 12; d++)
EEPROM.write(d, 0);*/
}
delay(500);
}
else{
//Displaying temperature
lcd.setCursor(0, 0);
lcd.print("Body Temperature");
lcd.setCursor(0, 1);
lcd.print(temp2, 1) + lcd.print(" C Degree");
// Get the message from the transmiter
uint8_t buflen = VW_MAX_MESSAGE_LEN;
uint8_t buf[buflen];
if(vw_get_message(buf, &buflen))
{
int i = 0;
//Convert the number to DEC
float temp1 = (((buf[i]-48)*100+(buf[i+1]-48)*10+buf[i+2]-48));
//Convert the number to C degrees
temp2 = (temp1)/6.8; // k = 6.8
}
//store Numer
//tvalue = (temp2, 1);
//Alarm if Temperature is too high
if(temp2 > 38.4) {
digitalWrite(9, HIGH);
delay(500);
digitalWrite(9, LOW);
delay(1000);
}
//Or keep calm
else {
digitalWrite(9, LOW);
}
//Write the measurement data to Arduino storage
save = save_data_to_storage();
}
}