Last active
June 30, 2019 07:53
-
-
Save samuelbles07/6dd0985b21e0c04ed9d7d33c3cab7482 to your computer and use it in GitHub Desktop.
Workshop Road to RIoT 2019
This file contains hidden or 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 <Arduino.h> | |
#include <ESPectro32_Board.h> | |
void button_cb() { | |
if (digitalRead(ESPECTRO32_BUTTON_A_PIN) == LOW) { | |
digitalWrite(ESPECTRO32_LED_PIN, LOW); | |
} | |
else { | |
digitalWrite(ESPECTRO32_LED_PIN, HIGH); | |
} | |
} | |
void setup() { | |
Serial.begin(9600); | |
pinMode(ESPECTRO32_LED_PIN, OUTPUT); | |
pinMode(ESPECTRO32_BUTTON_A_PIN, INPUT); | |
attachInterrupt(ESPECTRO32_BUTTON_A_PIN, button_cb, CHANGE); | |
} | |
void loop() { | |
} |
This file contains hidden or 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 <Arduino.h> | |
#include <ESPectro32_Board.h> | |
int i = 0; | |
void button_cb() { | |
if (digitalRead(ESPECTRO32_BUTTON_A_PIN) == LOW) { | |
digitalWrite(ESPECTRO32_LED_PIN, LOW); | |
Serial.println("On!"); | |
} | |
else { | |
digitalWrite(ESPECTRO32_LED_PIN, HIGH); | |
Serial.println("Off!"); | |
} | |
} | |
void setup() { | |
Serial.begin(115200); | |
pinMode(ESPECTRO32_LED_PIN, OUTPUT); | |
pinMode(ESPECTRO32_BUTTON_A_PIN, INPUT); | |
attachInterrupt(ESPECTRO32_BUTTON_A_PIN, button_cb, CHANGE); | |
} | |
void loop() { | |
Serial.sprintf("Hi %d", ++i); | |
delay(1000); | |
} |
This file contains hidden or 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 <Arduino.h> | |
#include <ESPectro32_Board.h> | |
void setup() { | |
pinMode(ESPECTRO32_LED_PIN, OUTPUT); | |
} | |
void loop() { | |
digitalWrite(ESPECTRO32_LED_PIN, HIGH); | |
delay(1000); | |
digitalWrite(ESPECTRO32_LED_PIN, LOW); | |
delay(1000); | |
} |
This file contains hidden or 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 <Arduino.h> | |
#include <ESPectro32_Board.h> | |
#include <ESPectro32_LedMatrix_Animation.h> | |
ESPectro32_LedMatrix_Animation ledMatrixAnim; | |
void setup() { | |
ESPectro32.begin(); | |
ledMatrixAnim.setLedMatrix(ESPectro32.LedMatrix()); | |
ledMatrixAnim.addFrameWithData((uint8_t*)LED_MATRIX_ICON_HEART); | |
ledMatrixAnim.addFrameWithData((uint8_t*)LED_MATRIX_ICON_HEART_OUTLINE); | |
ledMatrixAnim.addFrameWithData((uint8_t*)LED_MATRIX_ICON_HEART); | |
ledMatrixAnim.addFrameWithData((uint8_t*)LED_MATRIX_ICON_HEART_OUTLINE); | |
ledMatrixAnim.addFrameWithDataCallback([](ESPectro32_LedMatrix &ledM) { | |
ledM.drawCircle(3, 3, 3, 200); | |
}); | |
ledMatrixAnim.addFrameWithDataCallback([](ESPectro32_LedMatrix &ledM) { | |
ledM.fillCircle(3, 3, 3, 200); | |
}); | |
ledMatrixAnim.start(3000); | |
} | |
void loop() { | |
} |
This file contains hidden or 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 <Arduino.h> | |
#include <ESPectro32_Board.h> | |
void setup() { | |
Serial.begin(9600); | |
pinMode(36, INPUT); | |
} | |
void loop() { | |
Serial.println(analogRead(36)); | |
delay(200); | |
} |
This file contains hidden or 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 <Arduino.h> | |
#include <WiFi.h> | |
#include <PubSubClient.h> | |
const char* ssid = "YOUR-SSID"; | |
const char* password = "YOUR-PASSWORD"; | |
const char* mqtt_server = "broker.mqtt-dashboard.com"; | |
WiFiClient myClient; | |
PubSubClient client(myClient); | |
long lastMsg = 0; | |
char msg[50]; | |
int value = 0; | |
void setup_wifi() { | |
delay(10); | |
Serial.println(); | |
Serial.print("Connecting to "); | |
Serial.println(ssid); | |
WiFi.begin(ssid, password); | |
while (WiFi.status() != WL_CONNECTED) { | |
delay(500); | |
Serial.print("."); | |
} | |
Serial.println(""); | |
Serial.println("WiFi connected"); | |
Serial.println("IP address: "); | |
Serial.println(WiFi.localIP()); | |
} | |
void callback(char* topic, byte* payload, unsigned int length) { | |
Serial.print("Message arrived ["); | |
Serial.print(topic); | |
Serial.print("] "); | |
for (int i = 0; i < length; i++) { | |
Serial.print((char)payload[i]); | |
} | |
Serial.println(); | |
if ((char)payload[0] == '1') { | |
Serial.println("Led Hidup"); | |
digitalWrite(LED_BUILTIN, LOW); | |
} else { | |
Serial.println("Led Mati"); | |
digitalWrite(LED_BUILTIN, HIGH); | |
} | |
} | |
void reconnect() { | |
while (!client.connected()) { | |
Serial.print("Attempting MQTT connection..."); | |
if (client.connect("")) { | |
Serial.println("connected"); | |
client.publish("espectro32/test/send", "hello world"); | |
client.subscribe("espectro32/test/receive"); | |
} else { | |
Serial.println(" try again in 5 seconds"); | |
delay(5000); | |
} | |
} | |
} | |
void setup() { | |
delay(10); | |
pinMode(LED_BUILTIN, OUTPUT); | |
Serial.begin(9600); | |
setup_wifi(); | |
client.setServer(mqtt_server, 1883); | |
client.setCallback(callback); | |
} | |
void loop() { | |
if (!client.connected()) { | |
reconnect(); | |
} | |
client.loop(); | |
long now = millis(); | |
if (now - lastMsg > 7000) { | |
lastMsg = now; | |
++value; | |
snprintf (msg, 50, "hello world #%ld", value); | |
Serial.print("Publish message: "); | |
Serial.println(msg); | |
client.publish("espectro32/test/send", msg); | |
} | |
} |
This file contains hidden or 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 <Arduino.h> | |
#include <ESPectro32_Board.h> | |
#include <ESPectro32_RGBLED_Animation.h> | |
RgbLedColor_t aCol(200, 0, 80); | |
ESPectro32_RGBLED_GlowingAnimation glowAnim(ESPectro32.RgbLed(), aCol); | |
#include <ESPectro32_LedMatrix_Animation.h> | |
ESPectro32_LedMatrix_Animation ledMatrixAnim; | |
void setup() { | |
ESPectro32.begin(); | |
ESPectro32.LED().setAnimation(ESPectro_LED_Animation_Fading, 3000, 3); | |
glowAnim.start(3000, 3); | |
} | |
void loop() { | |
} |
This file contains hidden or 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 <Arduino.h> | |
#include "WiFi.h" | |
void setup() | |
{ | |
Serial.begin(115200); | |
// Set WiFi to station mode and disconnect from an AP if it was previously connected | |
WiFi.mode(WIFI_STA); | |
WiFi.disconnect(); | |
delay(100); | |
Serial.println("Setup done"); | |
} | |
void loop() | |
{ | |
Serial.println("scan start"); | |
// WiFi.scanNetworks will return the number of networks found | |
int n = WiFi.scanNetworks(); | |
Serial.println("scan done"); | |
if (n == 0) { | |
Serial.println("no networks found"); | |
} else { | |
Serial.print(n); | |
Serial.println(" networks found"); | |
for (int i = 0; i < n; ++i) { | |
// Print SSID and RSSI for each network found | |
Serial.print(i + 1); | |
Serial.print(": "); | |
Serial.print(WiFi.SSID(i)); | |
Serial.print(" ("); | |
Serial.print(WiFi.RSSI(i)); | |
Serial.print(")"); | |
Serial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN)?" ":"*"); | |
delay(10); | |
} | |
} | |
Serial.println(""); | |
// Wait a bit before scanning again | |
delay(5000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment