MKR Iot Carrier (Rev2) OS (Operating System)

I am happy to present my project to you today: The first operating system for the MKR IoT Carrier Rev2. It probably also works with the 1st generation, but this has not yet been tested: With the operating system you can display the humidity, switch on a "torch" via the LEDs, and soon much more! The project is currently still in development. Of course it is also on Hackster.io, where the program code is. It's definitely worth stopping by here, because the updates are always announced here. But I will also try to always announce the updates here as well. I would appreciate comments and a like both here in the forum and on hackster! Thanks very much!
HACKSTER: Carrier OS - Hackster.io
For anyone who wants to see the code right here, here it is:
(I'm using an MKR WiFi 1010 board with MKR IoT Carrier Rev2, but others should normally work too!)

#include <Arduino_MKRIoTCarrier.h>
#include <FastLED.h>
MKRIoTCarrier carrier;

float temperature = 0;
float humidity = 0;
unsigned long lastTempUpdate = 0;
int currentPage = 0;
bool inSubMenu = false;
int subMenuPage = 0;
bool ledState = false;

void printDashboard() {
carrier.display.fillScreen(ST77XX_BLACK);
carrier.display.setTextColor(ST77XX_WHITE);
carrier.display.setTextSize(2);
int16_t x, y;
uint16_t width, height;
carrier.display.getTextBounds("SCHAECHNER", 0, 0, &x, &y, &width, &height);
carrier.display.setCursor((carrier.display.width() - width) / 2, (carrier.display.height() - height) / 2);
carrier.display.print("SCHAECHNER");
}

void printTemperature() {
carrier.display.fillScreen(ST77XX_BLUE);
carrier.display.setTextColor(ST77XX_WHITE);
carrier.display.setTextSize(2);
int16_t x, y;
uint16_t width, height;
String tempStr = "Temp: " + String(temperature) + " C";
carrier.display.getTextBounds(tempStr, 0, 0, &x, &y, &width, &height);
carrier.display.setCursor((carrier.display.width() - width) / 2, (carrier.display.height() - height) / 2);
carrier.display.print(tempStr);
}

void printHumidity() {
carrier.display.fillScreen(ST77XX_GREEN);
carrier.display.setTextColor(ST77XX_WHITE);
carrier.display.setTextSize(2);
int16_t x, y;
uint16_t width, height;
String humidityStr = "Humidity: " + String(humidity) + " %";
carrier.display.getTextBounds(humidityStr, 0, 0, &x, &y, &width, &height);
carrier.display.setCursor((carrier.display.width() - width) / 2, (carrier.display.height() - height) / 2);
carrier.display.print(humidityStr);
}

void printWeather() {
carrier.display.fillScreen(ST77XX_YELLOW);
carrier.display.setTextColor(ST77XX_BLACK);
carrier.display.setTextSize(2);
int16_t x, y;
uint16_t width, height;
carrier.display.getTextBounds("WEATHER", 0, 0, &x, &y, &width, &height);
carrier.display.setCursor((carrier.display.width() - width) / 2, (carrier.display.height() - height) / 2);
carrier.display.print("WEATHER");
}

void printTemperatureSubMenu() {
carrier.display.fillScreen(ST77XX_BLUE);
carrier.display.setTextColor(ST77XX_WHITE);
carrier.display.setTextSize(2);
int16_t x, y;
uint16_t width, height;
String tempStr = "Temp: " + String(temperature) + " C";
carrier.display.getTextBounds(tempStr, 0, 0, &x, &y, &width, &height);
carrier.display.setCursor((carrier.display.width() - width) / 2, (carrier.display.height() - height) / 2);
carrier.display.print(tempStr);
}

void printHumiditySubMenu() {
carrier.display.fillScreen(ST77XX_GREEN);
carrier.display.setTextColor(ST77XX_WHITE);
carrier.display.setTextSize(2);
int16_t x, y;
uint16_t width, height;
String humidityStr = "Humidity: " + String(humidity) + " %";
carrier.display.getTextBounds(humidityStr, 0, 0, &x, &y, &width, &height);
carrier.display.setCursor((carrier.display.width() - width) / 2, (carrier.display.height() - height) / 2);
carrier.display.print(humidityStr);
}


void printSettings() {
carrier.display.fillScreen(ST77XX_MAGENTA);
carrier.display.setTextColor(ST77XX_BLACK);
carrier.display.setTextSize(2);
int16_t x, y;
uint16_t width, height;
carrier.display.getTextBounds("Settings", 0, 0, &x, &y, &width, &height);
carrier.display.setCursor((carrier.display.width() - width) / 2, (carrier.display.height() - height) / 2);
carrier.display.print("Settings");
}

void printLight() {
  carrier.display.fillScreen(ST77XX_BLACK);
  carrier.display.setTextColor(ST77XX_WHITE);
  carrier.display.setTextSize(2);
  int16_t x, y;
  uint16_t width, height;
  String text = "LED: ";
  if (ledState) {
    text += "ON";
  } else {
    text += "OFF";
  }
  carrier.display.getTextBounds(text, 0, 0, &x, &y, &width, &height);
  carrier.display.setCursor((carrier.display.width() - width) / 2, (carrier.display.height() - height) / 2);
  carrier.display.print(text);
  if (ledState) {
    carrier.leds.fill(CRGB::White);
    carrier.leds.show();
  } else {
    carrier.leds.fill(CRGB::Black);
    carrier.leds.show();
  }
}

void setup() {
  CARRIER_CASE = false;
  carrier.begin();
  carrier.display.setRotation(0);
  temperature = carrier.Env.readTemperature();
  humidity = carrier.Env.readHumidity();
}

void loop() {

if (carrier.Buttons.onTouchDown(TOUCH0)) {
    if (inSubMenu && currentPage == 2 && subMenuPage == 0) {
      ledState = !ledState;
      printLight();
    }
    else if (currentPage == 2) {
      inSubMenu = true;
      subMenuPage = 0;
      printLight();
    }
}
 
  carrier.Buttons.update();
  unsigned long now = millis();
  
  if(now - lastTempUpdate > 60000){
    temperature = carrier.Env.readTemperature();
    humidity = carrier.Env.readHumidity();
    lastTempUpdate = now;
  }

  if (carrier.Buttons.onTouchDown(TOUCH2)) {
    currentPage = 0;
    inSubMenu = false;
    printDashboard();
  }
  else if (carrier.Buttons.onTouchDown(TOUCH1) || carrier.Buttons.onTouchDown(TOUCH3)) {
    if (!inSubMenu) {
      currentPage = (currentPage + 1) % 4;
      switch(currentPage) {
        case 0:
          printDashboard();
          break;
        case 1:
          printWeather();
          break;
        case 2:
          printSettings();
          break;
      }
    }
    else {
      subMenuPage = (subMenuPage + 1) % 2;
      switch(currentPage) {
        case 1:
          switch(subMenuPage) {
            case 0:
              printTemperatureSubMenu();
              break;
            case 1:
              printHumiditySubMenu();
              break;
          }
          break;
        case 2:
          switch(subMenuPage) {
            case 0:
              printLight();
              break;
            case 1:
              printTemperature();
              break;
          }
          break;
      }
    }
  }
  else if (carrier.Buttons.onTouchDown(TOUCH4)) {
    if ((currentPage == 1 || currentPage ==2) && !inSubMenu) {
      inSubMenu = true;
      subMenuPage = (subMenuPage + 1) %2;
      switch(currentPage) {
        case 1:
          switch(subMenuPage) {
            case 0:
              printTemperatureSubMenu();
              break;
            case 1:
              printHumiditySubMenu();
              break;
          }
          break;
        case 2:
          switch(subMenuPage) {
            case 0:
              printLight();
              break;
            case 1:
              printTemperature();
              break;
          }
          break; 
      }
    }
    else if (inSubMenu) {
      inSubMenu = false;
      switch(currentPage) {
        case 1:
          printWeather();
          break;
        case 2:
          printSettings();
          break; 
      }
    }
}}

No answer - why?

Are you promoting your project here or need some help
Also I noticed that many of the answer was solved by you yourself only.
By visiting your profile

And this the solution of your topic?? :thinking::thinking::face_with_raised_eyebrow:

I posted my code here because I was hoping to have a bit of discussion about this project, get suggestions for changes (maybe criticism too).
It's not the solution. But I don't want to leave it open for so long if nobody answers anyway. But I can undo it!

So, what do you think of the code/Project?

OP needs to look up the definition of OS(Operating System). Anyone coming here as the result of a search would feel defrauded.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.