Authors

Workshop: Arduino ninja

Advisors & Mentors

Abstract

>>> Ensomhed på twitter <<<

Jeg har lavet et projekt der sætter fokus på ensomhed og fællesskab.

I min video forklarer jeg i korte træk hvordan det teknisk fungerer (med data der hentes ned fra Twitter).
Men konceptet er et visuelt output der simplificere den data der kommer ind og er tilgængelig for alle og til fri fortolkning.

Det er en prototype af en installation der kunne være spændende at have i byrummet og se hvordan folk reagerer og interagerer!

Jeg håber det vil inspirere dig til at tale om ensomhed med dine medstuderende.

(Billedet: boFÆLLESSKABET hvor jeg er vokset op)

#include #include #include #include #include #include // https://github.com/bblanchon/ArduinoJson #include "secret.h" // uncomment if using secret.h file with credentials //#define TWI_TIMEOUT 3000 // varies depending on network speed (msec), needs to be before TwitterWebAPI.h #include std::string search_str = "fællesskab"; // Default search word for twitter std::string search_str1 = "ensomhed"; const char *ntp_server = "pool.ntp.org"; // time1.google.com, time.nist.gov, pool.ntp.org int timezone = +1; // US Eastern timezone -05:00 HRS unsigned long twi_update_interval = 5; // (seconds) minimum 5s (180 API calls/15 min). Any value less than 5 is ignored! int counter = 0; String last_tweet; String last_tweet1; bool newTweet; bool newTweet1; bool newWeek = true; int weekDayStart; #include "FastLED.h" #include Servo motor; // How many leds in your strip? #define NUM_LEDS 7 #define DATA_PIN D2 // Define the array of leds CRGB leds[NUM_LEDS]; // Dont change anything below this line // /////////////////////////////////////////////// unsigned long api_mtbs = twi_update_interval * 1000; //mean time between api requests unsigned long api_lasttime = 0; bool twit_update = false; std::string search_msg = "No Message Yet!"; std::string search_msg1 = "No Message 1 Yet!"; WiFiUDP ntpUDP; NTPClient timeClient(ntpUDP, ntp_server, timezone * 3600, 60000); // NTP server pool, offset (in seconds), update interval (in milliseconds) TwitterClient tcr(timeClient, consumer_key, consumer_sec, accesstoken, accesstoken_sec); void setup(void) { motor.attach(D8); motor.write(90); //Begin Serial Serial.begin(115200); // WiFi Connection WiFi.begin(ssid, password); Serial.print("nConnecting to "); Serial.print(ssid); // Wait for connection while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println("Connected. yay!"); Serial.print("IP address: "); Serial.println(WiFi.localIP()); delay(100); // Connect to NTP and force-update time tcr.startNTP(); Serial.println("NTP Synced"); delay(100); // Setup internal LED pinMode(LED_BUILTIN, OUTPUT); digitalWrite(LED_BUILTIN, HIGH); if (twi_update_interval < 5) api_mtbs = 5000; // Cant update faster than 5s. weekDayStart = timeClient.getDay(); FastLED.addLeds(leds, NUM_LEDS); } void extractJSON(String tmsg) { const char* msg2 = const_cast (tmsg.c_str()); DynamicJsonBuffer jsonBuffer; JsonObject& response = jsonBuffer.parseObject(msg2); if (!response.success()) { Serial.println("Failed to parse JSON!"); Serial.println(msg2); //jsonBuffer.clear(); return; } if (response.containsKey("statuses")) { String usert = response["statuses"][0]["user"]["screen_name"]; String text = response["statuses"][0]["text"]; if (text != "") { text = "@" + usert + " says " + text; search_msg = std::string(text.c_str(), text.length()); } } else if (response.containsKey("errors")) { String err = response["errors"][0]; search_msg = std::string(err.c_str(), err.length()); } else { Serial.println("No useful data"); } jsonBuffer.clear(); delete [] msg2; } void extractJSON1(String tmsg) { const char* msg2 = const_cast (tmsg.c_str()); DynamicJsonBuffer jsonBuffer; JsonObject& response = jsonBuffer.parseObject(msg2); if (!response.success()) { Serial.println("Failed to parse JSON!"); Serial.println(msg2); //jsonBuffer.clear(); return; } if (response.containsKey("statuses")) { String usert = response["statuses"][0]["user"]["screen_name"]; String text = response["statuses"][0]["text"]; if (text != "") { text = "@" + usert + " says " + text; search_msg1 = std::string(text.c_str(), text.length()); } } else if (response.containsKey("errors")) { String err = response["errors"][0]; search_msg1 = std::string(err.c_str(), err.length()); } else { Serial.println("No useful data"); } jsonBuffer.clear(); delete [] msg2; } void loop(void) { timeClient.update(); if (weekDayStart == timeClient.getDay()) { if (newWeek == true) { counter = 0; //nullstiller counter fordi der er gået en uge newWeek = false; Serial.println("newWeek"); } } else { newWeek = true; } if (millis() > api_lasttime + api_mtbs) { digitalWrite(LED_BUILTIN, LOW); extractJSON(tcr.searchTwitter(search_str)); extractJSON1(tcr.searchTwitter(search_str1)); Serial.print("Search: "); Serial.println(search_str.c_str()); Serial.print("MSG: "); Serial.println(search_msg.c_str()); Serial.print("Search1: "); Serial.println(search_str1.c_str()); Serial.print("MSG1: "); Serial.println(search_msg1.c_str()); String current_tweet = search_msg.c_str(); String current_tweet1 = search_msg1.c_str(); if (current_tweet != last_tweet) { last_tweet = search_msg.c_str(); counter = counter + 1; newTweet = true; Serial.println(); Serial.println("new tweet"); } if (current_tweet1 != last_tweet1) { last_tweet1 = search_msg1.c_str(); counter = counter - 1; newTweet1 = true; Serial.println(); Serial.println("new tweet1"); } Serial.print("Counter: "); Serial.println(counter); api_lasttime = millis(); } delay(2); yield(); digitalWrite(LED_BUILTIN, HIGH); int countermaped = map(counter, -5, 5, 0, 180); motor.write(countermaped); if (counter < 10) { for (int i = 0; i = 10 && counter <= 20) { for (int i = 0; i 20) { for (int i = 0; i < NUM_LEDS; i = i + 1) { FastLED.setBrightness(255); leds[i] = CRGB( 255, 255, 0); //red + more green } FastLED.show(); } if (newTweet == true) { for (int i = 0; i < 255; i = i + 1) { FastLED.setBrightness(i); FastLED.show(); } newTweet = false; } }

Related