-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnalog_Multiplexer.ino
104 lines (72 loc) · 2.21 KB
/
Analog_Multiplexer.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <ESP8266WiFi.h>
#include <Milkcocoa.h>
/************************* WiFi Access Point *********************************/
#define WLAN_SSID ""
#define WLAN_PASS ""
/************************* Your Milkcocoa Setup *********************************/
#define MILKCOCOA_APP_ID ""
#define MILKCOCOA_DATASTORE "esp8266/tout"
/************* Milkcocoa Setup (you don't need to change this!) ******************/
#define MILKCOCOA_SERVERPORT 1883
/************ Global State (you don't need to change this!) ******************/
// Create an ESP8266 WiFiClient class to connect to the MQTT server.
WiFiClient client;
const char MQTT_SERVER[] PROGMEM = MILKCOCOA_APP_ID ".mlkcca.com";
const char MQTT_CLIENTID[] PROGMEM = __TIME__ MILKCOCOA_APP_ID;
Milkcocoa milkcocoa = Milkcocoa(&client, MQTT_SERVER, MILKCOCOA_SERVERPORT, MILKCOCOA_APP_ID, MQTT_CLIENTID);
void onpush(DataElement *elem) {
Serial.println("onpush");
Serial.println(elem->getInt("v"));
};
void setupWiFi() {
Serial.println(); Serial.println();
Serial.print("Connecting to ");
Serial.println(WLAN_SSID);
WiFi.begin(WLAN_SSID, WLAN_PASS);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println();
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
// ポート番号を指定
int s0 = 2;
int s1 = 3;
int s2 = 4;
int led = 5;
// 変数宣言
int cal0 = 0;
int cal1 = 0;
int cal2 = 0;
int count = 0;
void setup() {
Serial.begin(115200);
delay(10);
Serial.println(F("Milkcocoa SDK demo"));
setupWiFi();
Serial.println( milkcocoa.on(MILKCOCOA_DATASTORE, "push", onpush) );
pinMode(s0, OUTPUT);
pinMode(s1, OUTPUT);
pinMode(s2, OUTPUT);
pinMode(led, OUTPUT);
Serial.begin(9600);
};
void loop() {
milkcocoa.loop();
int val = analogRead(A0);
Serial.println(String(val));
for (count = 0; count <= 7; count++) {
cal0 = bitRead(count, 0);
cal1 = bitRead(count, 1);
cal2 = bitRead(count, 2);
digitalWrite(s0, cal0);
digitalWrite(s1, cal1);
digitalWrite(s2, cal2);
DataElement elem = DataElement();
elem.setValue("v", val);
milkcocoa.push(MILKCOCOA_DATASTORE, &elem);
delay(7000);
};