Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions hardware/hardware/hardware.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#define SW1 22
#define SW2 23
#include <LiquidCrystal.h>
LiquidCrystal lcd(32, 25, 26, 27, 14, 13);
byte title[] = { 0xB1, 0xC5, 0xC0, 0xB6, 0xDE, 0xB4, 0xD7, 0xCC, 0xDE, 0xC9, 0xCA }; //アナタガエラブノハ

//質問の配列
char Q[4][50] = {
"Boy/Girl",
"New/Old",
"Real/Fantasy",
"Rice/Bread"
};

//回答を保存するための文字列
String ans = "";

//ボタンの状態を保存する変数
int state1 = 1;
int state2 = 1;

void setup() {
//シリアルモニターを使用するため
Serial.begin(115200);

//wifi接続
wifi();

//ボタンの設定
pinMode(SW1, INPUT_PULLUP);
pinMode(SW2, INPUT_PULLUP);

//LCDを使用するため
lcd.begin(16, 2);

//質問の数繰り返し
for (int i = 0; i < 4; i++) {
Serial.println(i);
lcd.clear();
lcd.write(title, 11);//1行目を表示
//lcd.print("aaa");
//2行目に質問の選択肢を表示
lcd.setCursor(0, 1);
lcd.print(Q[i]);

//ボタンの状態を変数に保存
state1 = digitalRead(SW1);
state2 = digitalRead(SW2);

//ボタンがどちらか押されるまで先に進まない
while (state1 && state2) {
//ボタンの状態更新
state1 = digitalRead(SW1);
state2 = digitalRead(SW2);
}

//ボタン1が押されたら0,ボタン2が押されたら1で回答を保存
if (!state1) {
ans += "0";
} else {
ans += "1";
}

//ボタンがどちらか離されるまで先に進まない
while (!state1 || !state2) {
//ボタンの状態更新
state1 = digitalRead(SW1);
state2 = digitalRead(SW2);
}

//確認用にシリアルモニターに出力
Serial.println(ans);
}
lcd.clear();
lcd.print("finish");

//サーバーにデータ送信
senddata();
}

void loop() {
//loopは使わない
}
43 changes: 43 additions & 0 deletions hardware/hardware/wifi.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <WiFi.h>
#include <HTTPClient.h>

//discordに送ったやつコピペ(wifi関連)


void wifi(){
/* --- Wi-Fi 接続 --- */
lcd.begin(16, 2);
lcd.clear();
lcd.print("Connecting...");

Serial.print("Connecting to WiFi");
WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

Serial.println("\nWiFi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}

void senddata(){
/* --- サーバー へ送信 --- */
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;

http.begin(serverUrl);
http.addHeader("Content-Type", "text/plain");

int responseCode = http.POST(ans);

Serial.print("HTTP Response code: ");
Serial.println(responseCode);

http.end();
} else {
Serial.println("WiFi not connected");
}
}
Loading