Last active
October 11, 2016 03:08
-
-
Save Nonchalant/0794110905923aa336e4ad3fae6fc152 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SPI.h> | |
#include <SD.h> | |
const int chipSelect = 4; | |
const double R1 = 10; | |
void setup() { | |
Serial.begin(9600); | |
while (!Serial) { | |
; | |
} | |
Serial.print("Initializing SD card..."); | |
if (!SD.begin(chipSelect)) { | |
Serial.println("Card failed, or not present"); | |
return; | |
} | |
Serial.println("card initialized."); | |
} | |
void loop() { | |
// 変数の宣言 | |
double Vo, Rf, fg, kg; | |
int ain = analogRead(1); | |
// アナログ入力値から出力電圧を計算 | |
Vo = ain * 5.0 / 1024; | |
// 出力電圧からFRSの抵抗値を計算 | |
Rf = R1*Vo / (5.0 - Vo); | |
// FRSの抵抗値から圧力センサの荷重を計算 | |
fg = 880.79/Rf + 47.96; | |
kg = (fg / 4448) * 10; | |
File dataFile = SD.open("DATALOG.TXT", FILE_WRITE); | |
if (dataFile) { | |
dataFile.println(kg); | |
dataFile.close(); | |
Serial.println(kg); | |
} else { | |
Serial.println("error opening datalog.txt"); | |
} | |
delay(1000); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
file, msg = io.open("DATALOG.TXT", "r") | |
if file then | |
data = file:read("*a") | |
t = {} | |
for line in string.gmatch(data, "(.-)\n") do | |
table.insert(t, string.sub(line, 1, #line)) | |
end | |
latest = t[table.maxn(t)] | |
if latest == "" then | |
return | |
end | |
boundary = "--61141483716826" | |
contentType = "multipart/form-data; boundary=" .. boundary | |
token = "**************************************" | |
local ENDPOINT_URL = "https://slack.com/api/chat.postMessage?token=" .. token .. "&channel=%23toybox&text=" .. latest .. "kg&as_user=true&link_names=channel" | |
b, c, h = fa.request { | |
url = ENDPOINT_URL, | |
headers = { | |
["Content-Type"] = contentType | |
} | |
} | |
print(b) | |
print(c) | |
print(h) | |
else | |
print(msg) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment