Last active
May 8, 2016 03:20
-
-
Save kaeton/a776d085b93dbe77118e3604b69faa8a 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 <ArduinoJson.h> | |
const int BUTTON = 11; // プッシュボタンが接続されているピン | |
const int led_1 = 9; // 7segLED the one's place | |
const int led_10 = 10; // 7segLED the ten's place | |
const int led_100 = 11; | |
const int led_1000 = 12; | |
int val = 0; // 入力ピンの状態がこの変数(val)に記憶される | |
int old_val = 0; // valの前の値を保存しておく変数 | |
int state = 0; // LEDの状態(0ならオフ、1ならオン) | |
int state_1=0; // the one's digit | |
int state_10 =0; // the ten's digit | |
int state_100 =0; | |
int state_1000 =0; | |
void setup(){ | |
//1~8番ピン デジタル出力へセット | |
for (int i=1; i<=8; i++){ | |
pinMode(i,OUTPUT); | |
} | |
pinMode(BUTTON, INPUT); // BUTTONは入力に設定 | |
pinMode(led_10, OUTPUT); // 7segLED はoutput | |
pinMode(led_1, OUTPUT); | |
pinMode(led_100, OUTPUT); | |
pinMode(led_1000, OUTPUT); | |
} | |
//LEDレイアウトを定義 | |
boolean Num_Array[11][8]={ | |
{1,1,1,0,1,0,1,1},{0,0,1,0,1,0,0,0},{1,0,1,1,0,0,1,1},{1,0,1,1,1,0,1,0}, | |
{0,1,1,1,1,0,0,0},{1,1,0,1,1,0,1,0},{1,1,0,1,1,0,1,1},{1,1,1,0,1,0,0,0}, | |
{1,1,1,1,1,0,1,1},{1,1,1,1,1,0,1,0},{0,0,0,0,1,0,0} | |
}; | |
boolean Num_pointArray[11][8]={ | |
{1,1,1,0,1,1,1,1},{0,0,1,0,1,1,0,0},{1,0,1,1,0,1,1,1},{1,0,1,1,1,1,1,0}, | |
{0,1,1,1,1,1,0,0},{1,1,0,1,1,1,1,0},{1,1,0,1,1,1,1,1},{1,1,1,0,1,1,0,0}, | |
{1,1,1,1,1,1,1,1},{1,1,1,1,1,1,1,0},{0,0,0,0,1,0,0} | |
}; | |
//LED表示関数を定義 | |
//void NumPrint(int Number){ | |
// for (int w=0; w<=7; w++){ | |
// digitalWrite(w+1,Num_Array[Number][w]); | |
// } | |
//} | |
void NumPrint(int Number, int Point){ | |
if(Point == 0){ | |
for (int w=0; w<=7; w++){ | |
digitalWrite(w+1,Num_Array[Number][w]); | |
} | |
digitalWrite(13,Num_Array[Number][0]); | |
} | |
else{ | |
for (int w=0; w<=7; w++){ | |
digitalWrite(w+1,Num_pointArray[Number][w]); | |
} | |
digitalWrite(13,Num_Array[Number][0]); | |
} | |
} | |
void exec(JsonObject& root){ | |
if (!root.success()) { | |
output(-1, "\"Parse error! Json invalied (10)\"", -1, -1); | |
return; | |
} | |
const char* message = root["message"]; | |
float primary = root["primary"]; | |
float secondary = root["secondary"]; | |
val = digitalRead(BUTTON); // 入力を読み取りvalに格納 | |
float primary = 77.77; | |
//state = (state+1) % 10000; | |
state_1 = int(primary * 100) % 10; | |
state_10 = int(primary * 10) % 10; | |
state_100 = int(primary) % 10; | |
state_1000 = int(primary /10) % 10; | |
digitalWrite(led_1000,1); | |
digitalWrite(led_100,1); | |
digitalWrite(led_10,1); | |
digitalWrite(led_1,0); | |
NumPrint(state_1,0); | |
delay(3); | |
digitalWrite(led_1000,1); | |
digitalWrite(led_100,1); | |
digitalWrite(led_10,0); | |
digitalWrite(led_1,1); | |
NumPrint(state_10,0); | |
delay(3); | |
digitalWrite(led_1000,1); | |
digitalWrite(led_100,0); | |
digitalWrite(led_10,1); | |
digitalWrite(led_1,1); | |
NumPrint(state_100,1); | |
delay(3); | |
digitalWrite(led_1000,0); | |
digitalWrite(led_100,1); | |
digitalWrite(led_10,1); | |
digitalWrite(led_1,1); | |
NumPrint(state_1000,0); | |
delay(3); | |
} | |
void loop(){ | |
if(Serial.available() > 0){ | |
c = Serial.read(); | |
if(c == '{'){ | |
buf = ""; | |
buf.concat(c); | |
parsing = true; | |
}else if(c == '}'){ | |
buf.concat(c); | |
parsing = false; | |
StaticJsonBuffer<200> jsonBuffer; | |
JsonObject& root = jsonBuffer.parseObject(buf); | |
exec(root); | |
buf = ""; | |
}else{ | |
if(parsing){ | |
buf.concat(c); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment