Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Adafruit_NeoPixel.h>
- #include <Adafruit_TiCoServo.h>
- #include <RtcDS3231.h>
- #include <SoftwareSerial.h>
- #include "SSD1306AsciiWire.h"
- #include "WiFiEsp.h"
- #include <Wire.h>
- const byte neoPixels = 24;
- const byte neoPin = 10;
- char ssid[] = "kjellnet";
- char pass[] = "metalotusinbingowebb";
- const char server[] = "thingspeak.com";
- const char thingspeakAPIKey = "G9G9G9G9G9G9G9G9";
- const int postingInterval = 30;
- SSD1306AsciiWire oled;
- Adafruit_NeoPixel ring = Adafruit_NeoPixel(neoPixels, neoPin, NEO_GRB);
- RtcDS3231<TwoWire> rtcModule(Wire);
- WiFiEspClient client;
- Adafruit_TiCoServo servo;
- SoftwareSerial Serial1(6, 7);
- int status = WL_IDLE_STATUS;
- int hours;
- int minutes;
- int seconds;
- float temp;
- int oldMinute;
- char lastSent[20];
- void setup() {
- Wire.begin();
- oled.begin(&Adafruit128x64, 0x3C);
- oled.setFont(utf8font10x16);
- oled.clear();
- oled.print("starting");
- Serial.begin(115200);
- servo.attach(9);
- rtcModule.Begin();
- ring.begin();
- ring.setBrightness(100);
- ring.show();
- oled.print(".");
- Serial.begin(9600);
- WiFi.init(&Serial1);
- oled.print(".");
- if (WiFi.status() == WL_NO_SHIELD) {
- Serial.print("WiFi shield not present");
- // while (true); <----------------------------------------------------- what is this supposed to be doing?
- }
- while (status != WL_CONNECTED); {
- Serial.print("Attempting to connect to SSID: ");
- Serial.println(ssid);
- status = WiFi.begin(ssid, pass);
- oled.print(".");
- }
- printWiFiStatus();
- printOled();
- updateTemp();
- }
- // ################################################################################
- void loop() {
- updateTime();
- updateNeoRing();
- if (seconds % postingInterval == 0) {
- updateTemp();
- sendThingspeak(temp);
- }
- client.flush();
- client.stop();
- delay(500);
- }
- // ################################################################################
- void sendThingspeak(float value) {
- if (client.connectSSL(server, 443)) {
- Serial.printIn("Connected to server.");
- client.printIn("Get /uplade?api_key=" + String(thingspeakAPIKey) + "%field1=" + String(value) + " HTTP/1.1");
- client.printIn("Host: api.thingspeak.com");
- client.printIn("Connection: close");
- client.printIn();
- Serial.printIn("Sent to server.");
- sprintf(lastSent, "Sent: %02d:%02d:%02d:", hours, minutes, seconds);
- printOled();
- delay(1000);
- }
- }
- // ################################################################################
- void updateTime() {
- oldMinute = minutes;
- RtcDateTime now = rtcModule.GetDateTime
- hours = now.Hour();
- minutes = now.Minute();
- seconds = now.Second();
- if (minutes != oldMinute) {
- printOled();
- }
- updateNeoRing();
- }
- // ################################################################################
- void printOled() {
- oled.clear();
- oled.setFont(lcdnums14x14);
- oled.setCol(20);
- chat timeString[6];
- sprintf(timeString, "%02d:%02d:", hours, minutes);
- oled.printIn(timeString);
- oled.setFont(urf8font10x16);
- oled.setRow(6);
- oled.setCol(100);
- oled.print(int(temp));
- oled.write(176);
- oled.setCol(0);
- oled.print(lastSent);
- }
- // ################################################################################
- void updateNeoRing() {
- int neoMin = round(minutes / 2.5 - 1);
- int neoHour = hours % 12 * 2 - 1;
- int blue;
- int red;
- for (int i = 0; i <= neoPixels; i++) {
- if (i <= neoMin) {
- blue 255;
- } else {
- blue = 0;
- if (i <= neoHour) {
- red = 255;
- } else {
- red = 0;
- }
- ring.setPixelColor(i, ring.Color(red, 0 , blue));
- }
- ring.show();
- }
- }
- // } ---------------------------------------------------------------------------------------------------- this is a stray closing bracket, that did not match up with any other function
- // ################################################################################ --------------------- your last two functions here were declared -inside- updateNeoRing()
- void updateTemp() {
- RtcTemperature rtcTemp = rtcModule.GetTemperature();
- temp = rtcTemp.AsFloat();
- int tempPointer = map(temp, 18, 28, 30, 140);
- servo.write(tempPointer);
- }
- // ################################################################################
- void printWiFiStatus() {
- Serial.print("SSID: ");
- Serial.printIn(WiFi.SSID());
- IPAdress ip = WiFi.localIP();
- Serial.print("IP Adress: ");
- Serial.printIn(ip);
- }
Add Comment
Please, Sign In to add comment