Ako osekať sketch na minimum

Sekcia určená pre Arduino nadšencov

Moderátor: Moderátori

Používateľov profilový obrázok
ITIaster
Stály člen
Stály člen
Príspevky: 177
Dátum registrácie: 01 Jún 2014, 13:00
Vek: 25

Ako osekať sketch na minimum

Príspevok od používateľa ITIaster » 12 Jún 2019, 17:24

Zdravím, už dlhšie študujem ako osekávať programy do arduina, zatiaľ pomerne úspešne, no stále si myslím že toho viem len málo, tak som prišiel sem, ak som dobre videl takáto téma tu nieje teda pevne verím že som prvý čo tu niečo také rieši ... (ak nie prepošlite mi vlákno a zmažte toto tuto)

Tak teda, snažím sa dostať pomerne maličký program do atmegy 328 (momentálne experimentujem s nanom ale final by mal byť poháňaný pro mini, tož je ten istý procesor). Mal by to byť diaľkový ovládač pre homemade veternú turbínu, kde sa budú zobrazovať hodnoty z turbíny + bude sa dať turbína ovládať manuálne na diaľku. Na to že zatiaľ robím len simulácie a nemám nadviazanú ešte komunikáciu a ani nemeriam napätie a teplotu jednotky ovládača tak som sa veľmi rýchlo dostal na 90% pamäte kde po nahratí už arduino iba blblo a veľmi často sa reštartovalo... tak nasledovalo osekávanie z => int tlačítko, tlačítko je input pullup, int stav tlačítka, stav tlačítka = digitalRead tlačítko a až potom z toho stavu sa vykonala akcia... na X je input pullup (X predstavuje pin), ak X == 0 vykonaj...
Takéto osekanie mi pridalo znova trocha pamäte, dokonca som si skúšal nahodiť vstupy/výstupy v čistom C, rozdiel bol už iba minimálny ale predsa to budem vo finálnom programe znova uvádzať v čistom C (pre lepšiu orientáciu v programe som si tam nechal tie digitalReady :D ) potom nasledovali variability... všetko som mal zapísané ako "int" hoc to bola funkcia kde sa len menila 1 a 0, po naštudovaní som to nahádzal na "bool" a "byte" čím som znova ušporil až 4% pamäte... taktiež som využíval veľa "char* " ktorých som sa tiež zbavil a ďalšie malé úpravy. Ak by bol záujem pošlem sem kód pred osekaním a po osekaní, taktiež prihodím veľkosť... Viac možností na osekávanie som nenašiel, jediná a posledná bola osekať knižnicu na minimum keďže používam OLED displej na I2C o rozlíšení 128*64 ale knižnica je písaná pre všetky OLED displeje + je tam nespočetné množstvo funkcii ktoré ja nevyužívam... no osekávanie knižnice som nikdy nerobil preto neviem ako na to, prijal by som nejaký návod alebo niečo :D
Budem Vám vďačný za každú pomoc :)
Ďalej by som bol rád ak by toto vlákno neslúžilo iba pre môj projekt ale pridalo sa sem viacero ľudí s rovnakým problémom :)

PS.: kód aj fotky hore popísanej srandy prihodím každou chvíľou :)

-- Spojený príspevok 12 Jún 2019, 16:39 --

Tak tuto je kód, po osekaní, s komentármi, tiež som zabudol na to že zvažujem ten úvodný screen (bitovú mapu) že ju nahrajem do EEPROMy a budem ju otiaľ čítať, celý ten úvodný screen zaberá momentálne 4% pamäte... no a potom je tam tá komunikácia pomocou serialu to som si iba skúšal, je to síce funkčné ale je to v komentári (teda je to kvázi komentár a nenahráva sa do pamäte teda neovplyvní to veľkosť) po vyhodení to z komentu naberie program veľkosť okolo 90% a znova začne všetko blbnúť, ak odkomentnem :D :D iba 2 - 3 inštrukcie funguje to krásne...
Program ktorý je tuto nižšie zaberá 23238 bitov čo je 75%, myslím si že na to aký primitivizmus to je tak to zaberá dosť veľa...

Kód: Vybrať všetko

// This code is for remote control module for ветроколесo

//Rolling menu added
//"Menu/Setting" screen removed
//Sellected item light bar added
//new frames for RC_unit and windmill screen added
//new underscreens added (for windmill screen)
//changed screen numbers (MENU screen from "2" to "0" and RC_unit from "3" to "2")
//changed "item_list" to "item", and allso number order
//new underscreens added (for RC_unit screen)
//button names was deleted, int for button_status was also deleted
//char* channel[4] was deleted
//char* RC_unit_items_variab [4] was deleted
//previous button statuses (int) was deleted
//char* head[3] wich contained head names was deleted
//void display_item_variabile was deleted
//char* windmill_items_variabile [10] was deleted
//all intriggers was changed to byte or boolean or unsigned int
//code was changed to work with new variabiles


#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>

// OLED display I2C address
#define OLED_ADDR   0x3C

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(128, 64, &Wire, 4); // (Width, Height, "&Wire", Reset Pin)


float windmill_battery = 4.20;       // 3.00 - 4.20
float windmill_temp = 20.00;         // (-45.00) - (+65.00)
float internal_battery = 4.20;       // 3.00 - 4.20
float internal_temp = 20.00;         // (-45.00) - (+65.00)
bool connection = 0;                 // ON/OFF
unsigned int RPM = 0;                // 0-10,000
unsigned int MAX_RPM_T = 0;          // 0-10,000 (MAX RPM TODAY)
unsigned int MAX_RPM_L = 0;          // 0-10,000 (MAX RPM TROUGHT WHOLE LIFE)
unsigned int refresh_rate = 5000;    // 5,000-30,000
byte brake = 0;                      // 0-100%
bool brake_manual = 0;               // ON/OFF (MANUAL/AUTO)
bool short_circuit_brake = 0;        // ON/OFF
bool short_circuit_brake_manual = 0; // ON/OFF (MANUAL/AUTO)
bool tail_deflection = 0;            // ON/OFF
bool tail_deflection_manual = 0;     // ON/OFF (MANUAL/AUTO)
byte windmill_humidity = 0;          // 0-100%
bool windmill_bluetooth = 0;         // ON/OFF
byte windmill_channel = 1;           // 1-4
byte RC_channel = 1;                 // 1-4
bool beeper = 0;                     // ON/OFF
byte screen = 1;                     // 0-40
bool screen_refresh = 1;             // ON/OFF
byte item = 0;                       // 0-10
byte underscreen_item = 0;           // 0-2
byte last_item_list = 1;             // 0-10   (change name in new version to "last_item")
byte frame = 0;                      // 0-10
byte last_screen = 1;                // 0-40



char* auto_manual [] = {"AUTO", "MANUAL"};
char* on_off [] = {"OFF", "ON"};
char* menu_items [] = {" MENU", "Windmill", "RC Unit"};
char* windmill_items [] = {"RPM", "MAX RPM T.", "MAX RPM L.", "Brake", "S.C. Brake", "Tail Def.", "Battery", "Temp.", "Humidity", "Bluetooth"};
char* RC_unit_items [] = {"Battery", "Temp.", "Channel", "Refresh", "Beeper"};














const unsigned char myBitmap [] PROGMEM = {
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xf7, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xcf, 0xff, 0xff, 
  0xff, 0xff, 0xf7, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xcf, 0xff, 0xff, 
  0xff, 0xff, 0xf3, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xdf, 0xff, 0xff, 
  0xff, 0xff, 0xf3, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xff, 0xff, 0x9f, 0xff, 0xff, 
  0xff, 0xff, 0xe3, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xff, 0xff, 0x9f, 0xff, 0xff, 
  0xff, 0xff, 0xe3, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xff, 0xff, 0x9f, 0xff, 0xff, 
  0xff, 0xff, 0xe3, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xff, 0xff, 0x9f, 0xff, 0xff, 
  0xff, 0xff, 0xe3, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x3f, 0xff, 0xff, 0xff, 0xff, 0x9f, 0xff, 0xff, 
  0xff, 0xff, 0xe3, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x3f, 0xff, 0xff, 0xff, 0xff, 0x9f, 0xff, 0xff, 
  0xff, 0xff, 0xe3, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x3f, 0xff, 0xff, 0xff, 0xff, 0x9f, 0xff, 0xff, 
  0xff, 0xff, 0xe3, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x3f, 0xff, 0xff, 0xff, 0xff, 0x9f, 0xff, 0xff, 
  0xff, 0xff, 0xe3, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x1f, 0xff, 0xff, 0xff, 0xff, 0x9f, 0xff, 0xff, 
  0xff, 0xff, 0xe3, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x1f, 0xff, 0xff, 0xff, 0xff, 0x9f, 0xff, 0xff, 
  0xff, 0xff, 0xe3, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x1f, 0xff, 0xff, 0xff, 0xff, 0x9f, 0xff, 0xff, 
  0xff, 0xff, 0xe3, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x1f, 0xff, 0xff, 0xff, 0xff, 0x9f, 0xff, 0xff, 
  0xff, 0xff, 0xe3, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x0f, 0xff, 0xff, 0xff, 0xff, 0x9f, 0xff, 0xff, 
  0xff, 0xff, 0xe3, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x1f, 0xff, 0xff, 0xff, 0xff, 0x9f, 0xff, 0xff, 
  0xff, 0xff, 0xe3, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x3f, 0xff, 0xff, 0xff, 0xff, 0x9f, 0xff, 0xff, 
  0xff, 0xff, 0xeb, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xe3, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x3f, 0xff, 0xff, 0xff, 0xff, 0x87, 0xff, 0xff, 
  0xff, 0xff, 0xc1, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x3f, 0xff, 0xff, 0xff, 0xff, 0x83, 0xff, 0xff, 
  0xff, 0xff, 0x81, 0xff, 0xff, 0xff, 0xff, 0x08, 0x3f, 0xff, 0xff, 0xff, 0xff, 0x81, 0xff, 0xff, 
  0xff, 0xfe, 0x00, 0x3f, 0xff, 0xff, 0xfe, 0x04, 0x2f, 0xff, 0xff, 0xff, 0xff, 0x84, 0x3f, 0xff, 
  0xff, 0xf8, 0x00, 0x0f, 0xff, 0xff, 0xfc, 0x02, 0x43, 0xff, 0xff, 0xff, 0xfe, 0x4e, 0x0f, 0xff, 
  0xff, 0xf0, 0x36, 0x03, 0xff, 0xff, 0xf8, 0x06, 0x40, 0xff, 0xff, 0xff, 0xfc, 0x4f, 0x83, 0xff, 
  0xff, 0xc0, 0x77, 0x01, 0xff, 0xff, 0xf0, 0x1e, 0x40, 0x3f, 0xff, 0xff, 0xf0, 0xcf, 0xe1, 0xff, 
  0xff, 0x01, 0xf7, 0xc0, 0x7f, 0xff, 0xe0, 0x7e, 0x60, 0x1f, 0xff, 0xff, 0xc1, 0xcf, 0xf8, 0x7f, 
  0xfe, 0x07, 0xf3, 0xf0, 0x3f, 0xff, 0xc1, 0xfe, 0x60, 0x07, 0xff, 0xff, 0x87, 0xcf, 0xfc, 0x3f, 
  0xfc, 0x0f, 0xf3, 0xfc, 0x0f, 0xff, 0x83, 0xfe, 0x7e, 0x01, 0xff, 0xfe, 0x0f, 0xcf, 0xff, 0x1f, 
  0xf0, 0x3f, 0xf3, 0xff, 0x07, 0xff, 0x0f, 0xfe, 0x7f, 0xc0, 0x7f, 0xf8, 0x3f, 0xcf, 0xff, 0x8f, 
  0xe1, 0xff, 0xf3, 0xff, 0xc3, 0xfe, 0x3f, 0xfe, 0x7f, 0xfc, 0x3f, 0xe0, 0xff, 0xcf, 0xff, 0xe7, 
  0xc7, 0xff, 0xf3, 0xff, 0xf1, 0xfc, 0x7f, 0xfe, 0x7f, 0xff, 0x9f, 0x03, 0xff, 0xcf, 0xff, 0xf3, 
  0xff, 0xff, 0xe3, 0xff, 0xff, 0xfd, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xcf, 0xff, 0xff, 
  0xff, 0xff, 0xe3, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xcf, 0xff, 0xff, 
  0xff, 0xff, 0xe3, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xcf, 0xff, 0xff, 
  0xff, 0xff, 0xe3, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 
  0xff, 0xff, 0xe3, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 
  0xff, 0xff, 0xe3, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 
  0xff, 0xff, 0xe3, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 
  0xff, 0xff, 0xe3, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x3f, 0xff, 0xff, 0xff, 0xff, 0x87, 0xff, 0xff, 
  0xff, 0xff, 0xe3, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x3f, 0xff, 0xff, 0xff, 0xff, 0x87, 0xff, 0xff, 
  0xff, 0xff, 0xe3, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x3f, 0xff, 0xff, 0xff, 0xff, 0x87, 0xff, 0xff, 
  0xff, 0xff, 0xe3, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x3f, 0xff, 0xff, 0xff, 0xff, 0x87, 0xff, 0xff, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x03, 0x80, 0x00, 0x00, 0x04, 0x20, 0x01, 0xc6, 0x31, 0xdf, 0x7b, 0xc0, 0x00, 0x00, 
  0x00, 0x00, 0x06, 0x00, 0x00, 0x40, 0x04, 0x20, 0x01, 0xca, 0x31, 0x04, 0x42, 0x40, 0x00, 0x00, 
  0x00, 0x00, 0x04, 0x1d, 0xce, 0x77, 0xbc, 0x3c, 0x91, 0x4a, 0x49, 0x04, 0x42, 0x40, 0x00, 0x00, 
  0x00, 0x00, 0x04, 0x12, 0x23, 0x44, 0xa4, 0x26, 0xa1, 0x2a, 0x48, 0xc4, 0x73, 0x80, 0x00, 0x00, 
  0x00, 0x00, 0x04, 0x12, 0x0b, 0x44, 0x24, 0x22, 0xa1, 0x32, 0x78, 0x44, 0x42, 0x40, 0x00, 0x00, 
  0x00, 0x00, 0x03, 0xd1, 0xcf, 0x77, 0xbc, 0x3c, 0x61, 0x32, 0x8f, 0xc4, 0x7a, 0x40, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
};





void setup() {
// initialize and clear display
display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
display.clearDisplay();
display.display();
//Serial.begin(115200);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);
pinMode(10, INPUT_PULLUP);
display.drawBitmap(0,0,myBitmap, 128, 64, WHITE);
display.display();
delay(1500); //poltera sekund
  
}

void loop() {
/*String HC = "";                   // make new string where data willbe stored, this also clean our string in every loop
while (Serial.available() > 0)   // if we send anything, start reading it
{
HC += (char) Serial.read();      // Read it
delay(5);                         // Delay for 5 ms so the next char has time to be received
}

if (HC.startsWith("RPM")) {
      delay(10);
      String stringRPM = HC.substring(HC.indexOf("M") + 1, HC.length());
      delay(10);
      RPM = stringRPM.toInt(); 
      Serial.println("OK");
      screen_refresh = 1;
 }
 if (HC.startsWith("MRT")) {
      delay(10);
      String stringRPMT = HC.substring(HC.indexOf("T") + 1, HC.length());
      delay(10);
      MAX_RPM_T = stringRPMT.toInt(); 
      Serial.println("OK");
      screen_refresh = 1;
 }
 if (HC.startsWith("MRL")) {
      delay(10);
      String stringRPML = HC.substring(HC.indexOf("L") + 1, HC.length());
      delay(10);
      MAX_RPM_L = stringRPML.toInt(); 
      Serial.println("OK");
      screen_refresh = 1;
 }
 if (HC.startsWith("MB")) {//Mechanical Brake
      delay(10);
      String stringBrake = HC.substring(HC.indexOf("B") + 1, HC.length());
      delay(10);
      brake = stringBrake.toInt(); 
      Serial.println("OK");
      screen_refresh = 1;
 }
 
 if (HC.startsWith("BAT")) {
      delay(10);
      String stringBattery = HC.substring(HC.indexOf("T") + 1, HC.length());
      delay(10);
      windmill_battery = stringBattery.toFloat(); 
      screen_refresh = 1;
 }
 if (HC.startsWith("T")) {
      delay(10);
      String stringW_Temp = HC.substring(HC.indexOf("T") + 1, HC.length());
      delay(10);
      windmill_temp = stringW_Temp.toFloat(); 
      screen_refresh = 1;
 }
if (HC.startsWith("HUM")) {
      delay(10);
      String stringHUM = HC.substring(HC.indexOf("M") + 1, HC.length());
      delay(10);
      windmill_humidity = stringHUM.toInt(); 
      Serial.println("OK");
      screen_refresh = 1;
 }
*/

if (digitalRead(4) == LOW && screen != 0) //MENU
 {item = 0;
  frame = 0;
  screen = 0;
  screen_refresh = 1;
  delay(250);
 }

if (digitalRead(10) == LOW) //BACK
 {
  if (screen != last_screen)
  {
   item = last_item_list;
   screen = last_screen;
   screen_refresh = 1;
   underscreen_item = 0;
   delay(250);
  } 
  else{}
 }

 if (digitalRead(5) == LOW) //UP
 { 
  if (screen < 10)
  {
  if (item == 0)
  {
    if (screen == 0)
      {item = 2;}

    if (screen == 1)
      {item = 9;
       frame = 6;}
                
    if(screen == 2)
    {item = 4;
     frame = 1;}  
  }
  else {item--;}
  
  if (item == 5 && frame > 5 && screen == 1)
  {frame = 5;}
  if (item == 4 && frame > 4 && screen == 1)
  {frame = 4;}
  if (item == 3 && frame > 3 && screen == 1)
  {frame = 3;}
  if (item == 2 && frame > 2 && screen == 1)
  {frame = 2;}
  if (item == 1 && frame > 1)
  {frame = 1;}
  if (item == 0 && frame != 0)
  {frame = 0;}
  screen_refresh = 1;
  delay(250);
 }
 if (screen > 10)
  {if (underscreen_item == 0)
    {underscreen_item = 1;}
   else{underscreen_item--;} 
   screen_refresh = 1;
   delay(250);
  } 
 
}

 if (digitalRead(7) == LOW) //DOWN
 {if (screen < 10)
  {
  
  item++;
  if ((item == 10 && screen == 1) || (item == 2 && screen == 0) || (item == 5 && screen == 2))
  {
    item = 0;
    frame = 0;
  }
  if (item == 4 && frame <= 1)
  {frame = 1;}
  if (item == 5 && frame <= 2)
  {frame = 2;}
  if (item == 6 && frame <= 3)
  {frame = 3;}
  if (item == 7 && frame <= 4)
  {frame = 4;}
  if (item == 8 && frame <= 5)
  {frame = 5;}
  if (item == 9 && frame != 6)
  {frame = 6;}
  screen_refresh = 1;
  delay(250);
 }
 if (screen > 10)
  {underscreen_item++;
   if (underscreen_item == 2)
    {underscreen_item = 0;}
   screen_refresh = 1;
   delay(250);
  } 
} 
 
 if (digitalRead(9) == LOW) // LEFT
 {
  if (screen == 19)
  {windmill_bluetooth = !windmill_bluetooth;
   screen_refresh = 1;
   delay(250);
  }
  if (screen == 22)
  {RC_channel--;
   if (RC_channel == 0)
   {RC_channel = 4;}
   screen_refresh = 1;
   delay(250);
  }
  if (screen == 23)
  {refresh_rate = refresh_rate - 5000;
   if (refresh_rate == 0)
   {refresh_rate = 30000;}
   screen_refresh = 1;
   delay(250);
  }
  if (screen == 24)
  {beeper = !beeper;
   screen_refresh = 1;
   delay(250);
  }
 }

 if (digitalRead(8) == LOW) //ENTER
 {
  if (item == 0 && screen == 0)
  {last_screen = screen;
   last_item_list = item;
   item = 0;
   frame = 0;
   screen = 1;
   screen_refresh = 1;
   delay(250);
 }
 
  else if (item == 1 && screen == 0)
  {last_screen = screen;
  last_item_list = item;
  item = 0;
  frame = 0;
  screen = 2;
  screen_refresh = 1;
  delay(250);
 }

 else if (screen > 0)
  {last_screen = screen;
   last_item_list = item;
   screen = (screen * 10) + item;
   screen_refresh = 1;
   delay(250);
  }
 
    
  else
  {
  display.clearDisplay();
  display.setTextColor(WHITE); 
  display.setCursor(0,22);
  display.print("Updates Needed");
  display.display();
  screen_refresh = 1;
  delay(2000);
  }
 }

 if (digitalRead(6) == LOW) // RIGHT
 {
 if (screen == 19)
  {windmill_bluetooth = !windmill_bluetooth;
   screen_refresh = 1;
   delay(250);
  }
  if (screen == 22)
  {RC_channel++;
   if (RC_channel == 5)
   {RC_channel = 1;}
   screen_refresh = 1;
   delay(250);
  }
  if (screen == 23)
  {if (refresh_rate == 30000)
   {refresh_rate = 0;}
   refresh_rate = refresh_rate + 5000;
   screen_refresh = 1;
   delay(250);
  } 
  if (screen == 24)
  {beeper = !beeper;
   screen_refresh = 1;
   delay(250);
  }
 }


//-------------------------------------------screens----------------------------------------------
//-----------------------------------------MENU SCREEN--------------------------------
if (screen == 0 && screen_refresh == 1)
{ homescreen();
  display_item_text(menu_items [1], 15, (item == 0));
  display_item_text(menu_items [2], 25, (item == 1));
  display.display();
  screen_refresh = 0;
  }

//-------------------------------------------windmill SCREEN--------------------------------------  
if (screen == 1 && screen_refresh == 1)
{ homescreen();

if (frame == 0)
{
  display_item_text(windmill_items [0], 15, (item == 0));
  display.setCursor(90, 15); 
  display.print (RPM);
  display_item_text(windmill_items [1], 25, (item == 1));
  display.setCursor(90, 25); 
  display.print (MAX_RPM_T);
  display_item_text(windmill_items [2], 35, (item == 2));
  display.setCursor(90, 35); 
  display.print (MAX_RPM_L);
  display_item_text(windmill_items [3], 45, (item == 3));
  display.setCursor(90, 45); 
  display.print(brake);
  display.print("%");
}


if (frame == 1)
{
  display_item_text(windmill_items [1], 15, (item == 1));
  display.setCursor(90, 15); 
  display.print (MAX_RPM_T);
  display_item_text(windmill_items [2], 25, (item == 2));
  display.setCursor(90, 25); 
  display.print (MAX_RPM_L);
  display_item_text(windmill_items [3], 35, (item == 3));
  display.setCursor(90, 35); 
  display.print(brake);
  display.print("%");
  display_item_text(windmill_items [4], 45, (item == 4));
  display.setCursor(90, 45); 
  display.print(on_off[short_circuit_brake]);
}


if (frame == 2)
{
  display_item_text(windmill_items [2], 15, (item == 2));
  display.setCursor(90, 15); 
  display.print (MAX_RPM_L);
  display_item_text(windmill_items [3], 25, (item == 3));
  display.setCursor(90, 25); 
  display.print(brake);
  display.print("%");
  display_item_text(windmill_items [4], 35, (item == 4));
  display.setCursor(90, 35); 
  display.print(on_off[short_circuit_brake]);
  display_item_text(windmill_items [5], 45, (item == 5));
  display.setCursor(90, 45); 
  display.print(on_off[tail_deflection]);
}

if (frame == 3)
{
  display_item_text(windmill_items [3], 15, (item == 3)); //brake
  display.setCursor(90, 15); 
  display.print(brake);
  display.print("%");
  display_item_text(windmill_items [4], 25, (item == 4)); //S.C. Brake
  display.setCursor(90, 25); 
  display.print(on_off[short_circuit_brake]);
  display_item_text(windmill_items [5], 35, (item == 5)); //Tail Def.
  display.setCursor(90, 35); 
  display.print(on_off[tail_deflection]);
  display_item_text(windmill_items [6], 45, (item == 6)); //Battery
  display.setCursor(90, 45); 
  display.print(windmill_battery);
  display.print("V");
}

if (frame == 4)
{
  display_item_text(windmill_items [4], 15, (item == 4));//S.C. Brake
  display.setCursor(90, 15); 
  display.print(on_off[short_circuit_brake]);
  display_item_text(windmill_items [5], 25, (item == 5));//Tail Def.
  display.setCursor(90, 25); 
  display.print(on_off[tail_deflection]);
  display_item_text(windmill_items [6], 35, (item == 6));//Battery
  display.setCursor(90, 35); 
  display.print(windmill_battery);
  display.print("V");
  display_item_text(windmill_items [7], 45, (item == 7));//Temp.
  display.setCursor(90, 45); 
  display.print(windmill_temp);
}

if (frame == 5)
{
  display_item_text(windmill_items [5], 15, (item == 5));//Tail Def.
  display.setCursor(90, 15); 
  display.print(on_off[tail_deflection]);
  display_item_text(windmill_items [6], 25, (item == 6));//Battery
  display.setCursor(90, 25);
  display.print(windmill_battery);
  display.print("V"); 
  display_item_text(windmill_items [7], 35, (item == 7));//Temp.
  display.setCursor(90, 35); 
  display.print(windmill_temp);
  display_item_text(windmill_items [8], 45, (item == 8));//Humidity
  display.setCursor(90, 45); 
  display.print(windmill_humidity);
  display.print("%");
}


if (frame == 6)
{
  display_item_text(windmill_items [6], 15, (item == 6));//Battery
  display.setCursor(90, 15); 
  display.print(windmill_battery);
  display.print("V"); 
  display_item_text(windmill_items [7], 25, (item == 7));//Temp.
  display.setCursor(90, 25); 
  display.print(windmill_temp);
  display_item_text(windmill_items [8], 35, (item == 8));//Humidity
  display.setCursor(90, 35); 
  display.print(windmill_humidity);
  display.print("%");
  display_item_text(windmill_items [9], 45, (item == 9));//Bluetooth
  display.setCursor(90, 45); 
  display.print(on_off[windmill_bluetooth]);
}


  display.display();
  screen_refresh = 0;
  }

  
//------------------------------RC_unit SCREEN------------------------------------------  
if (screen == 2 && screen_refresh == 1)
{homescreen();
 if (frame == 0)
 {
  display_item_text(RC_unit_items [0], 15, (item == 0));
  display.setCursor(90, 15); 
  display.print (internal_battery);
  display.print ("V");
  display_item_text(RC_unit_items [1], 25, (item == 1));
  display.setCursor(90, 25); 
  display.print (internal_temp);
  display_item_text(RC_unit_items [2], 35, (item == 2));
  display.setCursor(90, 35); 
  display.print("CH ");
  display.print (RC_channel);
  display_item_text(RC_unit_items [3], 45, (item == 3));
  display.setCursor(90, 45); 
  display.print (refresh_rate/1000);
  display.print ("s");
 }

 if (frame == 1)
 {
  display_item_text(RC_unit_items [1], 15, (item == 1));
  display.setCursor(90, 15); 
  display.print (internal_temp);
  display_item_text(RC_unit_items [2], 25, (item == 2));
  display.setCursor(90, 25); 
  display.print("CH ");
  display.print (RC_channel);
  display_item_text(RC_unit_items [3], 35, (item == 3));
  display.setCursor(90, 35); 
  display.print (refresh_rate/1000);
  display.print ("s");
  display_item_text(RC_unit_items [4], 45, (item == 4));
  display.setCursor(90, 45); 
  display.print (on_off[beeper]); 
 }
 
 display.display();
 screen_refresh = 0;
}
//--------------------------------underscreens----------------------------------  
//------------------------underscreens for windmill screen---------------------- 
// 10, 11, 12, 16, 17, 18.
if (screen == 10 && screen_refresh == 1) //RPM
{ homescreen();
  display.setTextSize(2);
  display.setCursor(1, 15); 
  display.print(windmill_items [item]);
  display.setCursor(1, 35); 
  display.print(RPM);
  display.setTextSize(1);
  display.display();
  screen_refresh = 0;
}
if (screen == 11 && screen_refresh == 1) //MAX_RPM_T
{ homescreen();
  display.setTextSize(2);
  display.setCursor(1, 15); 
  display.print(windmill_items [item]);
  display.setCursor(1, 35); 
  display.print(MAX_RPM_T);
  display.setTextSize(1);
  display.display();
  screen_refresh = 0;
}
if (screen == 12 && screen_refresh == 1) //MAX_RPM_L
{ homescreen();
  display.setTextSize(2);
  display.setCursor(1, 15); 
  display.print(windmill_items [item]);
  display.setCursor(1, 35); 
  display.print(MAX_RPM_L);
  display.setTextSize(1);
  display.display();
  screen_refresh = 0;
}
if (screen == 16 && screen_refresh == 1) //Battery
{ homescreen();
  display.setTextSize(2);
  display.setCursor(1, 15); 
  display.print(windmill_items [item]);
  display.setCursor(1, 35); 
  display.print(windmill_battery);
  display.print("V");
  display.setTextSize(1);
  display.display();
  screen_refresh = 0;
}
if (screen == 17 && screen_refresh == 1) //Temp
{ homescreen();
  display.setTextSize(2);
  display.setCursor(1, 15); 
  display.print(windmill_items [item]);
  display.setCursor(1, 35); 
  display.print(windmill_temp);
  display.print(" C");
  display.setTextSize(1);
  display.display();
  screen_refresh = 0;
}
if (screen == 18 && screen_refresh == 1) //Humidity
{ homescreen();
  display.setTextSize(2);
  display.setCursor(1, 15); 
  display.print(windmill_items [item]);
  display.setCursor(1, 35); 
  display.print(windmill_humidity);
  display.print(" %");
  display.setTextSize(1);
  display.display();
  screen_refresh = 0;
}


//bluetooth
if (screen == 19 && screen_refresh == 1)
{homescreen();  
 display.setTextSize(2);
 display.setCursor(1, 15); 
 display.print(windmill_items [item]);
 display.setCursor(1, 35); 
 display.print ("< ");
 display.print(on_off [windmill_bluetooth]);
 display.print(" >");
 display.setTextSize(1);
 display.display();
 screen_refresh = 0;
} 

if (screen == 15 && screen_refresh == 1)
{homescreen();  
 display.setTextSize(2);
 display.setCursor(1, 15); 
 display.print(windmill_items [item]);
 display.setTextSize(1);
 if (underscreen_item == 0)
 {display.setTextColor(BLACK, WHITE);
  display.fillRect(0, 35, 128, 10, 1);  }
 else {display.setTextColor(WHITE);}     
 display.setCursor(1, 35); 
 display.print ("< ");
 display.print(auto_manual [tail_deflection_manual]);
 display.print(" >");
 if (underscreen_item == 1)
 {display.setTextColor(BLACK, WHITE);
  display.fillRect(0, 45, 128, 10, 1);  }
 else {display.setTextColor(WHITE);}     
 display.setCursor(1, 45); 
 display.print ("< ");
 display.print(on_off[tail_deflection]);
 display.print(" >");
 display.display();
 screen_refresh = 0;
} 

if (screen == 14 && screen_refresh == 1)
{homescreen();  
 display.setTextSize(2);
 display.setCursor(1, 15); 
 display.print(windmill_items [item]);
 display.setTextSize(1);
 if (underscreen_item == 0)
 {display.setTextColor(BLACK, WHITE);
      display.fillRect(0, 35, 128, 10, 1);  }
 else {display.setTextColor(WHITE);}     
 display.setCursor(1, 35); 
 display.print ("< ");
 display.print(auto_manual [short_circuit_brake_manual]);
 display.print(" >");
 if (underscreen_item == 1)
 {display.setTextColor(BLACK, WHITE);
  display.fillRect(0, 45, 128, 10, 1);  }
 else {display.setTextColor(WHITE);}     
 display.setCursor(1, 45); 
 display.print ("< ");
 display.print(on_off [short_circuit_brake]);
 display.print(" >");
 display.display();
 screen_refresh = 0;
} 

if (screen == 13 && screen_refresh == 1)
{homescreen();  
 display.setTextSize(2);
 display.setCursor(1, 15); 
 display.print(windmill_items [item]);
 display.setTextSize(1);
 if (underscreen_item == 0)
 {display.setTextColor(BLACK, WHITE);
  display.fillRect(0, 35, 128, 10, 1);  }
 else {display.setTextColor(WHITE);}     
 display.setCursor(1, 35); 
 display.print ("< ");
 display.print(auto_manual [brake_manual]);
 display.print(" >");
 if (underscreen_item == 1)
 {display.setTextColor(BLACK, WHITE);
  display.fillRect(0, 45, 128, 10, 1);  }
 else {display.setTextColor(WHITE);}     
 display.setCursor(1, 45); 
 display.print ("< ");
 display.print(brake);
 display.print("% >");
 display.setTextColor(WHITE);
 display.display();
 screen_refresh = 0;
} 
//-------------------------------underscreens for RC_unit------------------------------------------------------

if ((screen == 20) && screen_refresh == 1)
{homescreen();
  display.setTextSize(2);
  display.setCursor(1, 15); 
  display.print(RC_unit_items [item]);
  display.setCursor(1, 35); 
  display.print(internal_battery);
  display.print("V");
  display.setTextSize(1);
  display.display();
  screen_refresh = 0;
} 

if ((screen == 21) && screen_refresh == 1)
{homescreen();
  display.setTextSize(2);
  display.setCursor(1, 15); 
  display.print(RC_unit_items [item]);
  display.setCursor(1, 35); 
  display.print(internal_temp);
  display.setTextSize(1);
  display.display();
  screen_refresh = 0;
} 

if (screen == 22 && screen_refresh == 1)
{homescreen();  
 display.setTextSize(2);
 display.setCursor(1, 15); 
 display.print(RC_unit_items [item]);
 display.setTextColor(BLACK, WHITE); 
 display.setCursor(1, 35); 
 display.print ("< CH ");
 display.print(RC_channel);
 display.print(" >");
 display.display();
 screen_refresh = 0;
} 

if (screen == 23 && screen_refresh == 1)
{homescreen();  
 display.setTextSize(2);
 display.setCursor(1, 15); 
 display.print(RC_unit_items [item]);
 display.setTextColor(BLACK, WHITE); 
 display.setCursor(1, 35); 
 display.print ("< ");
 display.print(refresh_rate /1000);
 display.print("s");
 display.print(" >");
 display.display();
 screen_refresh = 0;
} 

if (screen == 24 && screen_refresh == 1)
{homescreen();  
 display.setTextSize(2);
 display.setCursor(1, 15); 
 display.print(RC_unit_items [item]);
 display.setTextColor(BLACK, WHITE); 
 display.setCursor(1, 35); 
 display.print ("< ");
 display.print(on_off [beeper]);
 display.print(" >");
 display.display();
 screen_refresh = 0;
} 
//-------------------------------serial R/W----------------
//update needed
  
}

void homescreen()
{
  display.clearDisplay();
  display.setTextSize(1);
  display.drawRect(0,0,19,10,1);
  display.fillRect(19, 3, 3, 4, 1);  

  display.fillRect(2, 2, 3, 6, 1);
  display.fillRect(6, 2, 3, 6, 1);
  display.fillRect(10, 2, 3, 6, 1);
  display.fillRect(14, 2, 3, 6, 1);
  
  display.setTextColor(WHITE);
  display.setCursor(45,1);
  if (screen < 3)
  {display.print(menu_items[screen]);  }
  else if (screen >= 10 && screen < 20)
  {display.print(menu_items[1]);  }
  else if (screen >= 20 && screen < 30)
  {display.print(menu_items[2]);}
  display.drawPixel(117, 10, 1);
  display.drawPixel(118, 10, 1);
  
  display.drawLine(120, 10, 120, 7, 1);
  display.drawLine(121, 10, 121, 7, 1);
  
  display.drawLine(123, 10, 123, 4, 1);
  display.drawLine(124, 10, 124, 4, 1);
  
  display.drawLine(126, 10, 126, 1, 1);
  display.drawLine(127, 10, 127, 1, 1);

  display.drawLine(0, 12, 128, 12, 1); 

  
  display.drawLine(0, 55, 128, 55, 1);
  display.setCursor(1, 57); 
  display.print("BACK");
  display.setCursor(100, 57); 
  display.print("MENU");
  display.setTextColor(WHITE);
     
}


void display_item_text(char* text, int pos, boolean selected)
{
    if(selected)
    {
      display.setTextColor(BLACK, WHITE);
      display.fillRect(0, pos-1, 128, 10, 1);  
    }else
    {
      display.setTextColor(WHITE);
    }
    display.setCursor(2, pos);
    display.print(text);
}
-- Spojený príspevok 12 Jún 2019, 16:55 --

nejaké fotky
Prílohy
spomínaná bitová mapa
spomínaná bitová mapa
rc2.jpg
rc3.jpg
rc4.jpg
rc5.jpg
rc6.jpg
rc7.jpg
0
"Nemôžete sa báť ľudí, že vám ublížia, pretože ak sa budete obávať života, nikdy nebudete žiť..."
Chester Bennington

Používateľov profilový obrázok
budvar10
Pokročilý člen
Pokročilý člen
Príspevky: 983
Dátum registrácie: 15 Dec 2014, 10:55
Bydlisko: Košice

Re: Ako osekať sketch na minimum

Príspevok od používateľa budvar10 » 12 Jún 2019, 18:08

Tak napríklad, koľkokrát máš tam print "OK", toľkokrát je tam reťazec "OK". Použi premennú. Na reťazce je dobré využívať PROGMEM alebo makro F(). Šetrí to RAM, ale môže byť pomalé.

P.S.: Vyzerá to pekne.
0

Používateľov profilový obrázok
ITIaster
Stály člen
Stály člen
Príspevky: 177
Dátum registrácie: 01 Jún 2014, 13:00
Vek: 25

Re: Ako osekať sketch na minimum

Príspevok od používateľa ITIaster » 12 Jún 2019, 22:21

Okej, vďaka za radu, dáva to logiku prečo mi pri takom programe crashne celý systém je tam veľa premenných a RAMka to nedáva, škoda že neviem zistiť využitie RAM po nábehu programu :/ určite skúsim do budúcna použiť aj to aby som trocha odľahčil RAMku, no aktuálny problém je že nemám miesto vo flash pamäti(teda ak dobre hovorím flash by mala byť tá časť kde je program a jej veľkosť pre AtMega328p je 32kbit) teda nedokážem sa ďalej rozšíriť ako je moja simulácia, čoskoro mi príde modul HC-12 a hneď budem chcieť nadviazať komunikáciu, taktiež v simulácii je vidno že z diaľkového chcem vedieť čítať napätie baterky(bude zvolená vnútorná analógová referencia na 1,1V tuším keďže napájanie bude z 1S1P LiPo baterky) ďalej teplotu a pískať bzučiakom (aktívnym, čiže budem privádzať len log 1/0 na 1 pin) pričom nastavenie bzučiaku má ísť do EEPROMy aby bolo vždy zachované aj po vypnutí a zapnutí a aj ten "refresh rate" uvažujem nahodiť do EEPROMky len neviem ako dlho by to vydržalo :D čiže suma sumárum potrebujem uvolniť riadne kusisko pamäte pred prevedením tejto srandy zo simulácie do reality :D ešte raz vďaka za odpoveď do budúcna mi to môže pomôcť :) :thumbup:
0
"Nemôžete sa báť ľudí, že vám ublížia, pretože ak sa budete obávať života, nikdy nebudete žiť..."
Chester Bennington

peterple
Ultimate člen
Ultimate člen
Príspevky: 2328
Dátum registrácie: 25 Jún 2013, 21:06
Bydlisko: Krajné
Vek: 57
Kontaktovať používateľa:

Re: Ako osekať sketch na minimum

Príspevok od používateľa peterple » 12 Jún 2019, 23:09

Cesta nebude ľahká. Alebo aj bude. Záleží na tom ako k tomu pristúpiš. V prvom rade to čo ty voláš knižnica (alebo arduinisti) žiadna knižnica nieje. Je to hlavičkový súbor a ten ak raz do zdrojáku začleníš tak je tam všetko čo je aktuálne povolené prekladať. Teda aj funkcie ktoré nepotrebuješ. Ale je to tak vymyslené že si na začiatku konštantou definuješ aký displej máš a tak sa tam kompiluje iba ten.

Ozajstné knižnice sa tam používajú tiež ale to je pre teba skryté. To by si z toho arduinistického C++ klesnúť o poschodie nižšie na obyčajné C. Isté možnosti i keď drobné máš. A to prestať používať float aritmetiku. Prípadne prestať používať objekt String. Aj keď neviem či to je reálne lebo stačí že je použitý v jedinom riadku kdekoľvek a už to tam máš prilinkované všetko okolo String.
No a to by si samozrejme musel všetko riešiť funkciami na spracovanie stringov v C.

Ohľadom obsadeniu pamäti dát tak mne v AVR štúdiu kompilátor povie koľko je obsadenej aj pamäte dát. Samozrejme statickej. Netýka sa to zásobníka. V simulátore by si si mal pomerne ľahko nájsť adresu jednotlivých premenných.
Čo sa týka textov tak ich dávaj zásadne iba do FLASH. Inak ti zaberajú flash aj SRAM. Spamalenia sa obavať nemusíš. Hlavne ako to budeš naďalej riešiť systémom delay(250) a pod.

Vidím to ale skôr tak že jednoduchšie bude použiť model s viac FLASH aj SRAM
0
Ukáž múdremu chybu a on sa ti poďakuje. Ukáž chybu hlupákovi a on sa urazí.

pocitujlasku
Ultimate člen
Ultimate člen
Príspevky: 6201
Dátum registrácie: 20 Júl 2007, 00:00
Vek: 41

Re: Ako osekať sketch na minimum

Príspevok od používateľa pocitujlasku » 13 Jún 2019, 05:51

nebude pre teba lepsie tam dat esp8266 a vypnut mu wifi? ma 4 Mb flash a male rozmery. pripadne vyuzit aj wifi a budes to vediet ovladat na dialku. S kodom vela nenarobis, dost zabera ta kniznica na ovladanie displeja (su tam vlastne nadefinovane mapy pre vsetky pismena + velkosti).
0
Jedním z největších projevů nedůvěry v Boha je hromosvod na kostele.

Používateľov profilový obrázok
tom666
Zaslúžilý člen
Zaslúžilý člen
Príspevky: 1344
Dátum registrácie: 05 Máj 2009, 00:00
Bydlisko: NR

Re: Ako osekať sketch na minimum

Príspevok od používateľa tom666 » 13 Jún 2019, 08:32

@ITIaster
Nejake percenta sa daju ziskat pouzitim inych kniznic na ovladanie displeja SSD1306. Skus preto pouzit namiesto Adafruit kniznic alternativny ovladac U8glib.

Na vyslednu velkost skompilovaneho kodu ma vplyv aj verzia kompilatora (avr-gcc) a jeho nastavenie.
0

Používateľov profilový obrázok
budvar10
Pokročilý člen
Pokročilý člen
Príspevky: 983
Dátum registrácie: 15 Dec 2014, 10:55
Bydlisko: Košice

Re: Ako osekať sketch na minimum

Príspevok od používateľa budvar10 » 13 Jún 2019, 08:43

peterple napísal:...A to prestať používať float aritmetiku. ...
Áno, presne. Presnosť 1/10 alebo aj 1/100 sa dá urobiť aj s integer, len pri výpise dáš desatinnú čiarku tam, kde má byť.
0

Používateľov profilový obrázok
ITIaster
Stály člen
Stály člen
Príspevky: 177
Dátum registrácie: 01 Jún 2014, 13:00
Vek: 25

Re: Ako osekať sketch na minimum

Príspevok od používateľa ITIaster » 17 Jún 2019, 13:39

budvar10, je to geniálny nápad, neviem prečo ma to nenapadlo skôr :D no zaujímalo by ma ako to vypisovať s tou desatinou čiarkou stačilo by čosi takéto

Kód: Vybrať všetko

display.print(windmill_voltage /1000);
pričom

Kód: Vybrať všetko

int windmill_voltage = 4200;
? prinajhoršiom by som to nechal hoc tak a fakticky zobrazované číslo by bolo v mV to nezabolí :D podobne teplota, tam som už viackrát uvažoval že to zrežem len na celé číslo že tam nebude 20,10°C ale proste len 20°C .... no bol by som rád ak by mi niekto ukázal spôsob ako to zobrazovať s desatinou čiarkou, už len kvôli iným projektom kde by sa mi tiež zišlo posporiť pamäť :D

tom666, aj nad tým som už uvažoval, videl som video od istého youtubera, ktorý skúšal vlastne rýchlosť zobrazovania použitím týchto 2 knižníc a písaním vlastného kódu (I2C príkazy) samozrejme bolo to oveľa menšie a rýchlejšie pričom vlastné príkazy boli víťazom ... no niesom si celkom istý či by daná knižnica mala všetky funkcie ktoré teraz využívam v tejto od adafruit... určite sa na to mrknem čo tá knižnica poskytuje poprípade ju skúsim vymeniť a hodím sem feedback či to pomohlo. Popravde najviac sa mi ale páčila myšlienka posielať príkazy vlastné čož by malo zaberať absolútne minimum pamäte, alebo otvoriť tú adafruit knižnicu a vyhádzať z nej všetko čo nepotrebujem, veď ja vlastne používam len 2 veľkosti písma, inverzný text(čierny text na bielom pozadí), normálny text (biely text na čiernom pozadí) a pár grafických prvkov ktoré sú hore na lište, fakticky všetko sa nachádza v časti "void homescreen()" z tých grafických prvkov, pričom ešte tam chcem jeden trojuholník a čiarku ako kvázi anténu k tomu signálu čo je na pravo :D

pocitujlasku, tak samozrejme som uvažoval aj nad týmto, pre istotu už mám na ceste aj wemos D1 mini ale povedzme že takéto riešenie sa mi nepáči a taktiež natrieskať toto do 328 som si zobral ako challange :D preto sa chcem naučiť tie programy osekávať, už som tu raz dával príspevok kde mi na projekte došla pamäť aj piny a nakoniec som to riešil prechodom na AtMega128 no tam bol problém už hlavne s pinami keďže som použil absolútne každý jeden ktorý mi 328 ponúkala :D tu mi ostalo pinov na rozdávanie no nemám pamäť :/ ako hovorím beriem to ako krajné riešenie že buď tam dám to ESP alebo mám ešte z toho spomínaného projektu 2ks atmega128 v šaflíku tak tam dám tie :)

peterple, tak zaujíma ma či sa tá knižnica/hlavičkový súbor dá osekať o funkcie ktoré nepoužívam, lebo hoc sa to kompiluje len pre môj displej, stále sa tam kompiluje kopec funkcii ktoré možno ani neviem že existujú (lebo tupci nedali nikde návod so všetkými funkciami knižnice čiže som si to po úlomkoch vygooglil) alebo vôbec nepoužívam a nepotrebujem...
Čo sa týka prechodu na C, ako hovorím sem tam niečo použijem aj z C kedže je to neskutočne úsporné a funkcia je tá istá :D ale nieje to také čitateľné ako wiring teda mám viac riadkov komentárov ako samotného kódu, no nebránim sa ani C je to super.
na ten float som fakticky odpovedal aj tebe aj budvarovi.
String, takto v predchádzajúcich verziách bolo toho stringu dosť veľa pričom som ho nahradil "char*" výsledok bol ohromný ako zmena jedného "slova" zmenila výslednú veľkosť ale ponechala funkčnosť :thumbup: teraz konkrétne sa string nachádza len v tej komunikácii čo si myslím že nieje celkom šťastné riešenie, ale priznám sa tej jedinej časti kódu skutočne nerozumiem keďže je to okopírované z netu a len som tam natrieskal svoje hodnoty, ostatne ten zvyšok čo je tam (čo nieje v komentári) som písal sám od prázdnej stránky teda všetému ostatnému rozumiem :D
To s tým spracovaním stringov v C som celkom nepochopil.
Progmem, teda ak dobre rozumiem hovoríš že ak mám nejakú premennú tak sa ukladá aj do flash pamäte aj do ram ? a použitím progmem sa ukladá už čiste len do flash a teda nezaberá ram ?
Delay :D :D :D som rád že si to niekto všimol :D tiež mi to príde že to nieje najšťastnejšie riešenie, predtým som to mal riešené tak že MCU vedel pôvodnú hodnotu tlačítok + bol tam SW debounce cez millis :D ale proste začal som agresívne osekávať program a vyhodil som aj to, preto je tam teraz delay :D spomalenia sa nebojím teda pokiaľ to nebude zalagované ako každý smartfón po 2 rokoch :D netreba mi tam ani nejaké presné časy, znova tam hodím potom to millis a môj refresh rate mi bude udávať približnú dĺžku kedy má ovládač požiadať o nové dáta, ale ak to bude spomalené o tie delay alebo to progmem tak si myslím že mi to nebude veľmi vadiť :D
Iný model použiť veľmi nechcem, je to lenivé a jednoduché riešenie, skutočne som sa stretol viackrát s týmto problémom a preto sa chcem naučiť ako čo najviac odľahčiť program, taktiež si myslím že čím je program kompaktnejší tým rýchlejšie beží (resp príkazy sa vykonávajú rýchlejšie, rýchlosť ako takú udáva takt kryštálu)

Ešte raz vám všetkým ďakujem odpovede, aj za vašu rýchlu odozvu :)
0
"Nemôžete sa báť ľudí, že vám ublížia, pretože ak sa budete obávať života, nikdy nebudete žiť..."
Chester Bennington

Používateľov profilový obrázok
roboulbricht
Stály člen
Stály člen
Príspevky: 156
Dátum registrácie: 07 Jan 2015, 12:01
Bydlisko: Banská Bystrica
Vek: 54
Kontaktovať používateľa:

Re: Ako osekať sketch na minimum

Príspevok od používateľa roboulbricht » 17 Jún 2019, 15:54

@ITIaster
Určite prejdi od Adafruit displeja na U8g2. Cez víkend som si tvoj projekt osekol na minimum a len cvične som displej nahradil za ten druhý. Rozdiel bol skoro 4000 bajtov. Ešte som si všimol, že tam máš strašne veľa IF kusov kódu, ktoré sa líšia iba drobnosťami. Ak by si to nahradil za funkciu s vhodnými parametrami, tak by si mal byť schopný ušetriť skoro 200 bajtov na jeden IF blok.

https://github.com/olikraus/u8g2
0

peterple
Ultimate člen
Ultimate člen
Príspevky: 2328
Dátum registrácie: 25 Jún 2013, 21:06
Bydlisko: Krajné
Vek: 57
Kontaktovať používateľa:

Re: Ako osekať sketch na minimum

Príspevok od používateľa peterple » 17 Jún 2019, 23:45

To čo si vymyslel s tým celočíselným delením je len prvá polovica. Lebo 4200/1000=4. Ale existuje aj operácia zvyšok po delení to sa zapisuje takto

Kód: Vybrať všetko

tisiciny=4200%1000 //v premennej bude 200
Neviem ako je robená tá displejová knižnica. Samozrejme že môžeš vyhádzať všetko čo nepotrebuješ. Len je to dosť nepraktické čo keď tam budú chyby a budú tú knižnicu aktualizovať to ju budeš upravovať za každým?
Čo sa týka fontov, neviem aké dve veľkosti používaš ale ja si myslím že na napr dvojnásobnú šírku či výšku úplne stačí jeden. Kód ktorým sa prepočíta znak na dvojnásobok vyjde určite menší ako dva kompletné generátory znakov.
Inverzia je len negácia to je v podstate jediná inštrukcia pred odoslaním. To určite tá knižnica tak robí.
Trieda String
Tak sa teda pozri na to čo je to String.
https://android.googlesource.com/platfo ... String.cpp
https://android.googlesource.com/platfo ... /WString.h
Keď si trochu preštuduješ tieto dva súbory tak možno zbadáš niekoľko vecí
  1. Je to len pekný objektový obal na klasické C funkcie ktoré pracujú s reťazcami (pole znakov ukončené nulou). Plus k tomu treba ešte tri ďalšie premenné a dynamicky alokované pole znakov.
  2. toto je fajn ako sa hovorí v tejto prednáške https://youtu.be/YnWhqhNdYyk Len tam zabudli povedať že aby si to C++ ako tak mohol používať potrebuješ tak aspoň 4MiBy RAM. AK jazdíš na pionieri tak nemôžeš chcieť aby za teba parkoval parkovací asistent.
  3. Ako vidíš tým že si niekde použil jediný objekt String tak sa ti tam z knižnice prikompilovalo všetko čo je v tom súbore, plus všetky tie str funkcie zo standartnej knižnice C bez ohľadu na to či tie funkcie voláš alebo nie. Ako som letmo pozrel ty ale využívaš substring, indexOf, length a toFloat a to toInt. Ako to konkrétne ten String robí si môžeš pozrieť v tom prvom linku.
  4. Ešte používaš operátor += A to je dosť divočina. Predpokladám že do toho vobec nevidíš, ale neustále sa tam realokuje to pole kam sa tie znaky odkladajú. S nejakými chybovými stavmi sa arduinisti neobťažujú ani ich sledovať a nie to ich ešte riešiť. Myslia si že to ten alokátor zvládne sám. Hravo ak má k dispozícii tie spomínané 4MiBy RAM. Lenže tvoje železo má celkovo 2kiBy. To je na všetko, teda na statické premené, aj na zásobník, aj na hromadu. Ak ti tieto pojmy nič nehovoria tak ver že prúser je na spadnutie. Tu sa totiž balancuje na špičke noža. Akékoľvek pochybenie je potrestané úletom programu do neznáma.
  5. Ešte aj to testovanie konca správy zo seriovej linky je také typicky arduinistické. Ak znak nedorazí do 5ms je koniec správy. Nuž záleží na tom čo tie správy generuje či toto pravidlo dodržuje. Ale teda podľa mňa to moc robustné riešenie nie je.
Skúsil som koľko koštuje trieda String kódu a je to asi 1400 byte ak nepoužiješ float a 3000byte ak použiješ float. Koľko bude úspora ak použiješ klasické C string funkcie tažko povedať. Typujem že tak 400 byte by mohlo stačiť samozrejme bez float.
Tie klasické C string funkcie si naštuduj sám, ak chceš šetriť.

Posledná vec je ten Progmem. Zamyslel si sa nad tým ako je možné že ten text je po spustení tvojho programu v RAM? Ako sa tam dostal? RAM má po zapnutí náhodný obsah. Pri programovaní keby si niečo uložil do RAM a potom to vypol kde by to asi skončilo? Zase za teba niečo urobí C bez toho aby si to tom vedel. Tie stringy sa samozrejme musia pekne nasúkať do FLASH a po resete ich niekto musí načítať do tých statických polí v RAM a tam sedia ako pecky ani sa nepohnú a len zaberajú miesto. Aj tie čo používaš len tak pomimo ako "OK" a pod. Keby si poznal inštrukčnú sadu AVR tak by si vedel že či vyberám text z RAM alebo FLASH tak je na to príslušná inštrukcia (LD alebo LPM ale obe zaberajú rovnako - 2byte) a vykonanie trvá skoro rovnako (LD 2cykly, LPM 3cykly)

Ak sa vám tu mnohým zdá že idem zbytočne hlboko na hw, tak si pozrite nejaké prednášky ľudí čo programujú pre google alebo facebook aký sú happy ak sa im podarí pri objekte String ušetriť pár strojových cyklov a nejaký ten byte RAM. Tam ide o milony. Pri AVR ide o funkčnosť. Ak tomu človek nerozumie až na hw úroveň tak je to časovaná bomba, ktorá vytuhne pri hocijakom trochu neštandardnom stave. Prípadne hračka ktorú človek ľahučko zrúti len tým že tam pošle napríklad nejaký neštandardný vstup.
Je to ako v rozprávke. Vždy je viacero ciest, ale tie krásne vyasfaltované niekým iným zvyčajne časom vedú do pekla.
0
Ukáž múdremu chybu a on sa ti poďakuje. Ukáž chybu hlupákovi a on sa urazí.

Používateľov profilový obrázok
budvar10
Pokročilý člen
Pokročilý člen
Príspevky: 983
Dátum registrácie: 15 Dec 2014, 10:55
Bydlisko: Košice

Re: Ako osekať sketch na minimum

Príspevok od používateľa budvar10 » 18 Jún 2019, 08:06

@ITIaster
Samozrejme, ako píše @peterple s tou desatinnou čiarkou, celé sa vypíšu ako výsledok delenia a desatiny ako modulo. Takto sa dá ušetriť
cez 1000B. Ale, ak by som potreboval presnosť 1/1000 a menej, asi je lepšie použiť float.

Inak, pre výpisy radšej používam formátovaný výstup printf a pod. Je tam spotreba asi 1500B hneď na úvod. Avšak, pre množstvo rôznych výpisov sa to nakoniec vyplatí.

Ešte jedna vec, nastavenie portov cez pinMode je pekná vec, ale ak to potrebuješ pre celý port, treba zvážiť štandardnú AVR metódu viď.
datatsheet.

@peterple
To, čo píšeš o String, nie je úplne pravda. Áno, Arduino knižnica nie je optimálne napísaná pre AVR a pre bežného užívateľa spôsobuje veľkú spotrebu RAM. Ja osobne to mám trochu prispôsobené. Ale stačia aj jednoduché zásady:
1. Definovať konštanty zásadne vo FLASH. Potom tam bude navyše len jeden byte, String size. Toto sa ale vyplatí neskôr v programe.
2. Spracovávať operácie v dostatočne veľkom buffri. Zabráni to realokácii.
Výsledkom je omnoho prehľadnejší kód s minimálnou réžiou navyše.

V C++ sa dajú písať naozaj elegantné a úsporné programy. Samozrejme, treba študovať a venovať sa tomu. A ako už bolo napísané, trochu štúdia ASM, prípadne porovnanie ASM rôznych C kódov a ako to sa to prekladá, dá sa dospieť k veľmi dobrým výsledkom.
0

Používateľov profilový obrázok
ITIaster
Stály člen
Stály člen
Príspevky: 177
Dátum registrácie: 01 Jún 2014, 13:00
Vek: 25

Re: Ako osekať sketch na minimum

Príspevok od používateľa ITIaster » 23 Jún 2019, 17:21

Okej tak som za to znova sadol, float som zmenil za int a použil spôsob výpisu ako mi ukázal peterple, ušetrilo mi to presne 1040bitov, ďalej som chcel začal riešiť prechod na knižnicu u8g2, trvalo mi to vyše pol dňa kým som všetko poupravoval aby to fungovalo v pôvodnom znení, no po finálnej kompilácii som zistil že rozdiel nieje ani 500bit a pritom vkuse s tou knižnicou len bojujem, a tá moja bitová mapa čo je na úvode je inverzná (aj to sa mi to podarilo až po hodine, ostatne som tam mal všelijaké haky baky...) a aj tá veľkosť si myslím že je menšia lebo som to ukrátil o pár vizuálnych prvkov oproti adafruitu, ostatne si myslím že veľkosť by bola možno aj zhodná ... a ako bonus mám to že mám vkuse plnú pamäť pričom má už aj IDE upozorní že mám preplnenú pamäť a môže nastať problém so stabilitou (pri adafruite sa mi toto nikdy nestalo) samozrejme po prečítaní kódu mi poviete že využívam metódu fullbuffer, áno no to je iba preto lebo inak mi na displeji vypísalo asi prvých 30% a potom čau párky zvyšok displeja čierny...

Ku stringom a ostatným veciam sa vrátim potom, momentálne je to v komentári a neštve ma to :D (po premene stringtoInt je to určite menšie), taktiež PROGMEM budem riešiť hneď po displeji (keby som vedel ako to dopadne tak by som to riešil ako 2.)...

@budvar10 - Ten formátovaný text som celkom nepochopil na koľko som k tomu nenašiel rozumný popis iba fóra, no z tých fór som pochopil že ide asi o výpis textu s premenou niekde medzi textom, čiže napríklad moje "<" "on_off[beeper_status]" ">" by šlo napísať do jedného riadku miesto troch. Ak je tomu tak, tak neviem či to má celkom význam nakoľko sa snažím šetriť...
Nastavenie portov... myslíš nahradiť to 100x pinMode(n, INPUT_PULLUP); za

Kód: Vybrať všetko

DDRD = 0b00001111;
DDRB = 0b11111000;
PORTD = 0b11110000;
PORTB = 0b00000111;
Ak áno tak už som tu raz spomínal že to budem robiť, tak isto aj digitalRead(n) nahradím za čisté C, no plánujem to až vo finálnej verzii pretože v C++ mám lepší prehľad, pri čistom C mám viac riadkov komentáru ako samotného programu :D

@roboulbricht - k tomu u8g2 som sa vyjadril hore, tá premena IF za funkciu, znie to skvelo, no neviem celkom ako to spraviť, veľmi by mi pomohlo keby si mi tu hodil aspoň 1 príklad konkrétne z môjho programu, bol by som ti veľmi vďačný :)

No a aby ste mal všetci predstavu ako sa kód zmenil pridávam ho sem znova, všetky pre mňa dôležité zmeny/chyby si píšem ceeeeeelkom hore do komentov, tentokrát som tam začal uvádzať aj veľkosť v bitoch.

Kód: Vybrať všetko

// This code is for remote control module for ветроколесo

//Rolling menu added
//"Menu/Setting" screen removed
//Sellected item light bar added
//new frames for RC_unit and windmill screen added
//new underscreens added (for windmill screen)
//changed screen numbers (MENU screen from "2" to "0" and RC_unit from "3" to "2")
//changed "item_list" to "item", and allso number order
//new underscreens added (for RC_unit screen)
//button names was deleted, int for button_status was also deleted
//char* channel[4] was deleted
//char* RC_unit_items_variab [4] was deleted
//previous button statuses (int) was deleted
//char* head[3] wich contained head names was deleted
//void display_item_variabile was deleted
//char* windmill_items_variabile [10] was deleted
//all intriggers was changed to byte or boolean or unsigned int
//code was changed to work with new variabiles
//version 2.2.5, this sketch was uploaded to svetelektro.com
//final size 22594bit
//-----------------------------------------------------------
//version 2.2.6 
//float was changed to int
//sizes during programing was 21378bit, 21426bit
//final size 21554 - 1040bits was saved
//----------------------------------------------------------
//version 2.2.7.1
//adafruit library was keeped
//unnecessary setTextsize was removed
//final size 21472bits - 82bits was saved
//----------------------------------------------------------
//version 2.2.7.2
//display library was changed to u8g2
//size during programing was 19804bit
//final size 21086 - 386bits was saved
//bitmap is inverted !!! 
//IDE shows error about stability of system !!!


#include <U8g2lib.h>

U8G2_SSD1306_128X64_NONAME_F_HW_I2C display(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);

unsigned int windmill_battery = 4200;// 3,000 - 4,200 mV
int windmill_temp = 2350;            // (-4,500) - (+6,500)
unsigned int internal_battery = 4200;// 3,000 - 4,200 mV
int internal_temp = 2350;            // (-4,500) - (+6,500)
bool connection = 0;                 // ON/OFF
unsigned int RPM = 0;                // 0-10,000
unsigned int MAX_RPM_T = 0;          // 0-10,000 (MAX RPM TODAY)
unsigned int MAX_RPM_L = 0;          // 0-10,000 (MAX RPM TROUGHT WHOLE LIFE)
unsigned int refresh_rate = 5000;    // 5,000-30,000
byte brake = 0;                      // 0-100%
bool brake_manual = 0;               // ON/OFF (MANUAL/AUTO)
bool short_circuit_brake = 0;        // ON/OFF
bool short_circuit_brake_manual = 0; // ON/OFF (MANUAL/AUTO)
bool tail_deflection = 0;            // ON/OFF
bool tail_deflection_manual = 0;     // ON/OFF (MANUAL/AUTO)
byte windmill_humidity = 0;          // 0-100%
bool windmill_bluetooth = 0;         // ON/OFF
byte windmill_channel = 1;           // 1-4
byte RC_channel = 1;                 // 1-4
bool beeper = 0;                     // ON/OFF
byte screen = 1;                     // 0-40
bool screen_refresh = 1;             // ON/OFF
byte item = 0;                       // 0-10
byte underscreen_item = 0;           // 0-2
byte last_item_list = 1;             // 0-10   (change name in new version to "last_item")
byte frame = 0;                      // 0-10
byte last_screen = 1;                // 0-40



char* auto_manual [] = {"AUTO", "MANUAL"};
char* on_off [] = {"OFF", "ON"};
char* menu_items [] = {" MENU", "Windmill", "RC Unit"};
char* windmill_items [] = {"RPM", "MAX RPM T.", "MAX RPM L.", "Brake", "S.C. Brake", "Tail Def.", "Battery", "Temp.", "Humidity", "Bluetooth"};
char* RC_unit_items [] = {"Battery", "Temp.", "Channel", "Refresh", "Beeper"};


const unsigned char welcomeScreen [] PROGMEM = {
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 
  0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 
  0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x80, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 
  0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 
  0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x00, 
  0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x80, 
  0x01, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 
  0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 
  0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x80, 0x03, 0x00, 0x00, 0x00, 
  0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x80, 
  0x03, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 
  0x00, 0x00, 0x00, 0x80, 0x03, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 
  0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x80, 0x03, 0x00, 0x00, 0x00, 
  0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x80, 
  0x07, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 
  0x00, 0x00, 0x00, 0x80, 0x07, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 
  0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x80, 0x07, 0x00, 0x00, 0x00, 
  0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x00, 0x80, 
  0x07, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 
  0x00, 0x00, 0x00, 0x80, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 
  0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x00, 0x80, 0x07, 0x00, 0x00, 0x00, 
  0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x80, 
  0x03, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 
  0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x03, 0x00, 0x00, 0x00, 
  0x00, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x00, 0xE0, 
  0x03, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x00, 
  0x00, 0x00, 0x00, 0xCE, 0x03, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 
  0x00, 0x80, 0xBF, 0x03, 0x00, 0x00, 0x00, 0xFF, 0x0F, 0x00, 0x00, 0x00, 
  0x00, 0xDE, 0x03, 0x00, 0x00, 0xE0, 0xD7, 0x0F, 0x00, 0x00, 0xC0, 0xBF, 
  0x3D, 0x00, 0x00, 0x00, 0x80, 0x85, 0x07, 0x00, 0x00, 0xF8, 0x93, 0x3F, 
  0x00, 0x00, 0xE0, 0x0F, 0xFC, 0x00, 0x00, 0x00, 0xC0, 0x09, 0x3E, 0x00, 
  0x00, 0xFC, 0x11, 0x7F, 0x00, 0x00, 0xF0, 0x87, 0xFD, 0x01, 0x00, 0x00, 
  0xF0, 0x08, 0x78, 0x00, 0x00, 0x7E, 0x10, 0xFC, 0x01, 0x00, 0xF8, 0x81, 
  0xF8, 0x07, 0x00, 0x00, 0x38, 0x0C, 0xE0, 0x01, 0x80, 0x1F, 0x30, 0xF0, 
  0x03, 0x00, 0x7C, 0x80, 0xF1, 0x1F, 0x00, 0x00, 0x1E, 0x04, 0xC0, 0x03, 
  0xC0, 0x0F, 0x10, 0xC0, 0x0F, 0x00, 0x1E, 0x80, 0x81, 0x3F, 0x00, 0x80, 
  0x07, 0x0C, 0x00, 0x07, 0xF0, 0x01, 0x10, 0x00, 0x1F, 0x00, 0x0F, 0x80, 
  0x01, 0xFC, 0x00, 0xE0, 0x03, 0x0C, 0x00, 0x1C, 0x78, 0x00, 0x30, 0x00, 
  0x3C, 0x80, 0x03, 0x80, 0x01, 0xC0, 0x03, 0xF8, 0x00, 0x0C, 0x00, 0x18, 
  0x18, 0x00, 0x38, 0x00, 0x60, 0xC0, 0x00, 0x80, 0x01, 0x00, 0x02, 0x1E, 
  0x00, 0x0C, 0x00, 0x10, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x80, 
  0x01, 0x00, 0x00, 0x02, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 
  0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 
  0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 
  0x00, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x80, 
  0x01, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 
  0x00, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 
  0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x80, 0x03, 0x00, 0x00, 0x00, 
  0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0xC0, 
  0x01, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 
  0x00, 0x00, 0x00, 0xC0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 
  0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 
  0x00, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0xC0, 
  0x03, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 
  0x00, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x00, 0x00, 
  0xB5, 0x6D, 0xFF, 0x6D, 0xB5, 0x6D, 0xB7, 0xED, 0xD7, 0xB6, 0x6D, 0xDB, 
  0xAA, 0xBF, 0xDD, 0xB6, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xDF, 0xFB, 0xFF, 0xFF, 0xFF, 0xFF, 
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0xFC, 0xFF, 0xFF, 0xDF, 0xFB, 
  0x7F, 0x9C, 0x73, 0x04, 0x21, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0x9F, 0xFF, 
  0xDE, 0xF9, 0x9F, 0xFB, 0x7F, 0x8C, 0x33, 0xDF, 0xBD, 0xFD, 0xFF, 0xFF, 
  0xFF, 0xFF, 0xDF, 0x67, 0x0C, 0x19, 0xC2, 0x43, 0xF6, 0x8D, 0x65, 0xDE, 
  0xB9, 0xF9, 0xFF, 0xFF, 0xFF, 0xFF, 0xDF, 0x33, 0xBB, 0x49, 0xDA, 0x9B, 
  0x72, 0xB2, 0xE9, 0xDC, 0x31, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xDF, 0x37, 
  0x2E, 0xCD, 0xDB, 0x9B, 0x78, 0xB2, 0xE1, 0xDD, 0xBD, 0xFD, 0xFF, 0xFF, 
  0xFF, 0xFF, 0x1F, 0x76, 0x84, 0x19, 0x82, 0xC3, 0x79, 0x93, 0x0C, 0xDC, 
  0x31, 0xF9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF7, 0xDE, 0xB7, 0xFF, 0xFF, 
  0xFD, 0xFF, 0xFF, 0xDF, 0xFD, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
  0xFF, 0xFF, 0xFF, 0xFF, 0xFD, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
  0xFF, 0xFF, 0xFF, 0xFF, };





void setup() {
// initialize and clear display
display.begin();
display.clearDisplay();
display.updateDisplay();
//Serial.begin(115200);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);
pinMode(10, INPUT_PULLUP);
display.drawXBMP(0,0,128,64,welcomeScreen);
display.updateDisplay();
delay(1500); //poltera sekund
  
}

void loop() {
/*String HC = "";                   // make new string where data willbe stored, this also clean our string in every loop
while (Serial.available() > 0)   // if we send anything, start reading it
{
HC += (char) Serial.read();      // Read it
delay(5);                         // Delay for 5 ms so the next char has time to be received
}

if (HC.startsWith("RPM")) {
      delay(10);
      String stringRPM = HC.substring(HC.indexOf("M") + 1, HC.length());
      delay(10);
      RPM = stringRPM.toInt(); 
      Serial.println("OK");
      screen_refresh = 1;
 }
 if (HC.startsWith("MRT")) {
      delay(10);
      String stringRPMT = HC.substring(HC.indexOf("T") + 1, HC.length());
      delay(10);
      MAX_RPM_T = stringRPMT.toInt(); 
      Serial.println("OK");
      screen_refresh = 1;
 }
 if (HC.startsWith("MRL")) {
      delay(10);
      String stringRPML = HC.substring(HC.indexOf("L") + 1, HC.length());
      delay(10);
      MAX_RPM_L = stringRPML.toInt(); 
      Serial.println("OK");
      screen_refresh = 1;
 }
 if (HC.startsWith("MB")) {//Mechanical Brake
      delay(10);
      String stringBrake = HC.substring(HC.indexOf("B") + 1, HC.length());
      delay(10);
      brake = stringBrake.toInt(); 
      Serial.println("OK");
      screen_refresh = 1;
 }
 
 if (HC.startsWith("BAT")) {
      delay(10);
      String stringBattery = HC.substring(HC.indexOf("T") + 1, HC.length());
      delay(10);
      windmill_battery = stringBattery.toFloat(); 
      screen_refresh = 1;
 }
 if (HC.startsWith("T")) {
      delay(10);
      String stringW_Temp = HC.substring(HC.indexOf("T") + 1, HC.length());
      delay(10);
      windmill_temp = stringW_Temp.toFloat(); 
      screen_refresh = 1;
 }
if (HC.startsWith("HUM")) {
      delay(10);
      String stringHUM = HC.substring(HC.indexOf("M") + 1, HC.length());
      delay(10);
      windmill_humidity = stringHUM.toInt(); 
      Serial.println("OK");
      screen_refresh = 1;
 }
*/

if (digitalRead(4) == LOW && screen != 0) //MENU
 {item = 0;
  frame = 0;
  screen = 0;
  screen_refresh = 1;
  delay(250);
 }

if (digitalRead(10) == LOW) //BACK
 {
  if (screen != last_screen)
  {
   item = last_item_list;
   screen = last_screen;
   screen_refresh = 1;
   underscreen_item = 0;
   delay(250);
  } 
  else{}
 }

 if (digitalRead(5) == LOW) //UP
 { 
  if (screen < 10)
  {
  if (item == 0)
  {
    if (screen == 0)
      {item = 2;}

    if (screen == 1)
      {item = 9;
       frame = 6;}
                
    if(screen == 2)
    {item = 4;
     frame = 1;}  
  }
  else {item--;}
  
  if (item == 5 && frame > 5 && screen == 1)
  {frame = 5;}
  if (item == 4 && frame > 4 && screen == 1)
  {frame = 4;}
  if (item == 3 && frame > 3 && screen == 1)
  {frame = 3;}
  if (item == 2 && frame > 2 && screen == 1)
  {frame = 2;}
  if (item == 1 && frame > 1)
  {frame = 1;}
  if (item == 0 && frame != 0)
  {frame = 0;}
  screen_refresh = 1;
  delay(250);
 }
 if (screen > 10)
  {if (underscreen_item == 0)
    {underscreen_item = 1;}
   else{underscreen_item--;} 
   screen_refresh = 1;
   delay(250);
  } 
 
}

 if (digitalRead(7) == LOW) //DOWN
 {if (screen < 10)
  {
  
  item++;
  if ((item == 10 && screen == 1) || (item == 2 && screen == 0) || (item == 5 && screen == 2))
  {
    item = 0;
    frame = 0;
  }
  if (item == 4 && frame <= 1)
  {frame = 1;}
  if (item == 5 && frame <= 2)
  {frame = 2;}
  if (item == 6 && frame <= 3)
  {frame = 3;}
  if (item == 7 && frame <= 4)
  {frame = 4;}
  if (item == 8 && frame <= 5)
  {frame = 5;}
  if (item == 9 && frame != 6)
  {frame = 6;}
  screen_refresh = 1;
  delay(250);
 }
 if (screen > 10)
  {underscreen_item++;
   if (underscreen_item == 2)
    {underscreen_item = 0;}
   screen_refresh = 1;
   delay(250);
  } 
} 
 
 if (digitalRead(9) == LOW) // LEFT
 {
  if (screen == 19)
  {windmill_bluetooth = !windmill_bluetooth;
   screen_refresh = 1;
   delay(250);
  }
  if (screen == 22)
  {RC_channel--;
   if (RC_channel == 0)
   {RC_channel = 4;}
   screen_refresh = 1;
   delay(250);
  }
  if (screen == 23)
  {refresh_rate = refresh_rate - 5000;
   if (refresh_rate == 0)
   {refresh_rate = 30000;}
   screen_refresh = 1;
   delay(250);
  }
  if (screen == 24)
  {beeper = !beeper;
   screen_refresh = 1;
   delay(250);
  }
 }

 if (digitalRead(8) == LOW) //ENTER
 {
  if (item == 0 && screen == 0)
  {last_screen = screen;
   last_item_list = item;
   item = 0;
   frame = 0;
   screen = 1;
   screen_refresh = 1;
   delay(250);
 }
 
  else if (item == 1 && screen == 0)
  {last_screen = screen;
  last_item_list = item;
  item = 0;
  frame = 0;
  screen = 2;
  screen_refresh = 1;
  delay(250);
 }

 else if (screen > 0)
  {last_screen = screen;
   last_item_list = item;
   screen = (screen * 10) + item;
   screen_refresh = 1;
   delay(250);
  }
 
    
  else
  {
  display.clearDisplay();
  //display.setTextColor(WHITE); 
  display.setCursor(0,22);
  display.print("Updates Needed");
  display.updateDisplay();
  screen_refresh = 1;
  delay(2000);
  }
 }

 if (digitalRead(6) == LOW) // RIGHT
 {
 if (screen == 19)
  {windmill_bluetooth = !windmill_bluetooth;
   screen_refresh = 1;
   delay(250);
  }
  if (screen == 22)
  {RC_channel++;
   if (RC_channel == 5)
   {RC_channel = 1;}
   screen_refresh = 1;
   delay(250);
  }
  if (screen == 23)
  {if (refresh_rate == 30000)
   {refresh_rate = 0;}
   refresh_rate = refresh_rate + 5000;
   screen_refresh = 1;
   delay(250);
  } 
  if (screen == 24)
  {beeper = !beeper;
   screen_refresh = 1;
   delay(250);
  }
 }


//-------------------------------------------screens----------------------------------------------
//-----------------------------------------MENU SCREEN--------------------------------
if (screen == 0 && screen_refresh == 1)
{ homescreen();
  display_item_text(menu_items [1], 22, (item == 0));
  display_item_text(menu_items [2], 32, (item == 1));
  display.updateDisplay();
  screen_refresh = 0;
  }

//-------------------------------------------windmill SCREEN--------------------------------------  
if (screen == 1 && screen_refresh == 1)
{ homescreen();

if (frame == 0)
{
  display_item_text(windmill_items [0], 22, (item == 0)); //RPM
  display.setCursor(90, 22); 
  display.print (RPM);
  display_item_text(windmill_items [1], 32, (item == 1)); //MAX RPM T.
  display.setCursor(90, 32); 
  display.print (MAX_RPM_T);
  display_item_text(windmill_items [2], 42, (item == 2)); //MAX RPM L.
  display.setCursor(90, 42); 
  display.print (MAX_RPM_L);
  display_item_text(windmill_items [3], 52, (item == 3)); //Brake
  display.setCursor(90, 52); 
  display.print(brake);
  display.print("%");
}


if (frame == 1)
{
  display_item_text(windmill_items [1], 22, (item == 1)); //MAX RPM T.
  display.setCursor(90, 22); 
  display.print (MAX_RPM_T);
  display_item_text(windmill_items [2], 32, (item == 2)); //MAX RPM L.
  display.setCursor(90, 32); 
  display.print (MAX_RPM_L);
  display_item_text(windmill_items [3], 42, (item == 3)); //Brake
  display.setCursor(90, 42); 
  display.print(brake);
  display.print("%");
  display_item_text(windmill_items [4], 52, (item == 4)); //S.C. Brake
  display.setCursor(90, 52); 
  display.print(on_off[short_circuit_brake]);
}


if (frame == 2)
{
  display_item_text(windmill_items [2], 22, (item == 2)); //MAX RPM L.
  display.setCursor(90, 22); 
  display.print (MAX_RPM_L);
  display_item_text(windmill_items [3], 32, (item == 3)); //Brake
  display.setCursor(90, 32); 
  display.print(brake);
  display.print("%");
  display_item_text(windmill_items [4], 42, (item == 4)); //S.C. Brake
  display.setCursor(90, 42); 
  display.print(on_off[short_circuit_brake]);
  display_item_text(windmill_items [5], 52, (item == 5)); //Tail Def.
  display.setCursor(90, 52); 
  display.print(on_off[tail_deflection]);
}

if (frame == 3)
{
  display_item_text(windmill_items [3], 22, (item == 3)); //Brake
  display.setCursor(90, 22); 
  display.print(brake);
  display.print("%");
  display_item_text(windmill_items [4], 32, (item == 4)); //S.C. Brake
  display.setCursor(90, 32); 
  display.print(on_off[short_circuit_brake]);
  display_item_text(windmill_items [5], 42, (item == 5)); //Tail Def.
  display.setCursor(90, 42); 
  display.print(on_off[tail_deflection]);
  display_item_text(windmill_items [6], 52, (item == 6)); //Battery
  display.setCursor(90, 52); 
  display.print(windmill_battery/1000);
  display.print(".");
  display.print((windmill_battery%1000)/10);
  display.print("V");
}

if (frame == 4)
{
  display_item_text(windmill_items [4], 22, (item == 4));//S.C. Brake
  display.setCursor(90, 22); 
  display.print(on_off[short_circuit_brake]);
  display_item_text(windmill_items [5], 32, (item == 5));//Tail Def.
  display.setCursor(90, 32); 
  display.print(on_off[tail_deflection]);
  display_item_text(windmill_items [6], 42, (item == 6));//Battery
  display.setCursor(90, 42); 
  display.print(windmill_battery/1000);
  display.print(".");
  display.print((windmill_battery%1000)/10);
  display.print("V");
  display_item_text(windmill_items [7], 52, (item == 7));//Temp.
  display.setCursor(90, 52); 
  display.print(windmill_temp/100);
  display.print(".");
  display.print(windmill_temp%100);
}

if (frame == 5)
{
  display_item_text(windmill_items [5], 22, (item == 5));//Tail Def.
  display.setCursor(90, 22); 
  display.print(on_off[tail_deflection]);
  display_item_text(windmill_items [6], 32, (item == 6));//Battery
  display.setCursor(90, 32);
  display.print(windmill_battery/1000);
  display.print(".");
  display.print((windmill_battery%1000)/10);
  display.print("V");
  display_item_text(windmill_items [7], 42, (item == 7));//Temp.
  display.setCursor(90, 42); 
  display.print(windmill_temp/100);
  display.print(".");
  display.print(windmill_temp%100);
  display_item_text(windmill_items [8], 52, (item == 8));//Humidity
  display.setCursor(90, 52); 
  display.print(windmill_humidity);
  display.print("%");
}


if (frame == 6)
{
  display_item_text(windmill_items [6], 22, (item == 6));//Battery
  display.setCursor(90, 22); 
  display.print(windmill_battery/1000);
  display.print(".");
  display.print((windmill_battery%1000)/10);
  display.print("V"); 
  display_item_text(windmill_items [7], 32, (item == 7));//Temp.
  display.setCursor(90, 32); 
  display.print(windmill_temp/100);
  display.print(".");
  display.print(windmill_temp%100);
  display_item_text(windmill_items [8], 42, (item == 8));//Humidity
  display.setCursor(90, 42); 
  display.print(windmill_humidity);
  display.print("%");
  display_item_text(windmill_items [9], 52, (item == 9));//Bluetooth
  display.setCursor(90, 52); 
  display.print(on_off[windmill_bluetooth]);
}


  display.updateDisplay();
  screen_refresh = 0;
  }

 
//------------------------------RC_unit SCREEN------------------------------------------  
if (screen == 2 && screen_refresh == 1)
{homescreen();
 if (frame == 0)
 {
  display_item_text(RC_unit_items [0], 22, (item == 0));
  display.setCursor(90, 22); 
  display.print(internal_battery/1000);
  display.print(".");
  display.print((internal_battery%1000)/10);
  display.print("V");
  display_item_text(RC_unit_items [1], 32, (item == 1));
  display.setCursor(90, 32); 
  display.print(internal_temp/100);
  display.print(".");
  display.print(internal_temp%100);
  display_item_text(RC_unit_items [2], 42, (item == 2));
  display.setCursor(90, 42); 
  display.print("CH ");
  display.print (RC_channel);
  display_item_text(RC_unit_items [3], 52, (item == 3));
  display.setCursor(90, 52); 
  display.print (refresh_rate/1000);
  display.print ("s");
 }

 if (frame == 1)
 {
  display_item_text(RC_unit_items [1], 22, (item == 1));
  display.setCursor(90, 22); 
  display.print(internal_temp/100);
  display.print(".");
  display.print(internal_temp%100);
  display_item_text(RC_unit_items [2], 32, (item == 2));
  display.setCursor(90, 32); 
  display.print("CH ");
  display.print (RC_channel);
  display_item_text(RC_unit_items [3], 42, (item == 3));
  display.setCursor(90, 42); 
  display.print (refresh_rate/1000);
  display.print ("s");
  display_item_text(RC_unit_items [4], 52, (item == 4));
  display.setCursor(90, 52); 
  display.print (on_off[beeper]); 
 }
 
 display.updateDisplay();
 screen_refresh = 0;
}
//--------------------------------underscreens----------------------------------  
//------------------------underscreens for windmill screen---------------------- 
// 10, 11, 12, 16, 17, 18.
if (screen == 10 && screen_refresh == 1) //RPM
{ homescreen();
  //display.setTextSize(2);//u8g2_font_9x18_tf
  display.setFont(u8g2_font_crox4hb_tf);
  display.setCursor(1, 29); 
  display.print(windmill_items [item]);
  display.setCursor(1, 49); 
  display.print(RPM);
  display.updateDisplay();
  screen_refresh = 0;
}
if (screen == 11 && screen_refresh == 1) //MAX_RPM_T
{ homescreen();
  //display.setTextSize(2);
  display.setFont(u8g2_font_crox4hb_tf);
  display.setCursor(1, 29); 
  display.print(windmill_items [item]);
  display.setCursor(1, 49); 
  display.print(MAX_RPM_T);
  display.updateDisplay();
  screen_refresh = 0;
}
if (screen == 12 && screen_refresh == 1) //MAX_RPM_L
{ homescreen();
  //display.setTextSize(2);
  display.setFont(u8g2_font_crox4hb_tf);
  display.setCursor(1, 29); 
  display.print(windmill_items [item]);
  display.setCursor(1, 49); 
  display.print(MAX_RPM_L);
  display.updateDisplay();
  screen_refresh = 0;
}
if (screen == 16 && screen_refresh == 1) //Battery
{ homescreen();
  //display.setTextSize(2);
  display.setFont(u8g2_font_crox4hb_tf);
  display.setCursor(1, 29); 
  display.print(windmill_items [item]);
  display.setCursor(1, 49); 
  display.print(windmill_battery/1000);
  display.print(".");
  display.print((windmill_battery%1000)/10);
  display.print("V");
  display.updateDisplay();
  screen_refresh = 0;
}
if (screen == 17 && screen_refresh == 1) //Temp
{ homescreen();
  //display.setTextSize(2);
  display.setFont(u8g2_font_crox4hb_tf);
  display.setCursor(1, 29); 
  display.print(windmill_items [item]);
  display.setCursor(1, 49); 
  display.print(windmill_temp/100);
  display.print(".");
  display.print(windmill_temp%100);
  display.print(" C");
  display.updateDisplay();
  screen_refresh = 0;
}
if (screen == 18 && screen_refresh == 1) //Humidity
{ homescreen();
  //display.setTextSize(2);
  display.setFont(u8g2_font_crox4hb_tf);
  display.setCursor(1, 29); 
  display.print(windmill_items [item]);
  display.setCursor(1, 49); 
  display.print(windmill_humidity);
  display.print(" %");
  display.updateDisplay();
  screen_refresh = 0;
}


//bluetooth
if (screen == 19 && screen_refresh == 1)
{homescreen();  
 //display.setTextSize(2);
 display.setFont(u8g2_font_crox4hb_tf);
 display.setCursor(1, 29); 
 display.print(windmill_items [item]);
 display.setCursor(1, 49); 
 display.print ("< ");
 display.print(on_off [windmill_bluetooth]);
 display.print(" >");
 display.updateDisplay();
 screen_refresh = 0;
} 

if (screen == 15 && screen_refresh == 1)
{homescreen();  
 display.setFont(u8g2_font_crox4hb_tf);
 display.setCursor(1, 29); 
 display.print(windmill_items [item]);
 display.setFont(u8g2_font_6x10_tf);
 if (underscreen_item == 0)
 {display.drawBox(0, 35, 128, 10);  
  display.setDrawColor(0);}
 else {display.setDrawColor(1);}     
 display.setCursor(1, 42); 
 display.print ("< ");
 display.print(auto_manual [tail_deflection_manual]);
 display.print(" >");
 if (underscreen_item == 1)
 {display.drawBox(0, 45, 128, 10);  
  display.setDrawColor(0);}
 else {display.setDrawColor(1);}     
 display.setCursor(1, 52); 
 display.print ("< ");
 display.print(on_off[tail_deflection]);
 display.print(" >");
 display.updateDisplay();
 screen_refresh = 0;
} 

if (screen == 14 && screen_refresh == 1)
{homescreen();  
 display.setFont(u8g2_font_crox4hb_tf);
 display.setCursor(1, 29); 
 display.print(windmill_items [item]);
 display.setFont(u8g2_font_6x10_tf);
 if (underscreen_item == 0)
 {display.drawBox(0, 35, 128, 10);
  display.setDrawColor(0);}
 else {display.setDrawColor(1);}     
 display.setCursor(1, 42); 
 display.print ("< ");
 display.print(auto_manual [short_circuit_brake_manual]);
 display.print(" >");
 if (underscreen_item == 1)
 {display.drawBox(0, 45, 128, 10);
  display.setDrawColor(0);}
 else {display.setDrawColor(1);}     
 display.setCursor(1, 52); 
 display.print ("< ");
 display.print(on_off [short_circuit_brake]);
 display.print(" >");
 display.updateDisplay();
 screen_refresh = 0;
} 

if (screen == 13 && screen_refresh == 1)
{homescreen();  
 display.setFont(u8g2_font_crox4hb_tf);
 display.setCursor(1, 29); 
 display.print(windmill_items [item]);
 display.setFont(u8g2_font_6x10_tf);
 if (underscreen_item == 0)
 {display.drawBox(0, 35, 128, 10);
  display.setDrawColor(0);}
 else {display.setDrawColor(1);}     
 display.setCursor(1, 42); 
 display.print ("< ");
 display.print(auto_manual [brake_manual]);
 display.print(" >");
 if (underscreen_item == 1)
 {display.drawBox(0, 45, 128, 10);  
  display.setDrawColor(0);}
 else {display.setDrawColor(1);}     
 display.setCursor(1, 52); 
 display.print ("< ");
 display.print(brake);
 display.print("% >");
 display.setDrawColor(1);
 display.updateDisplay();
 screen_refresh = 0;
} 
//-------------------------------underscreens for RC_unit------------------------------------------------------

if ((screen == 20) && screen_refresh == 1)
{homescreen();
  display.setFont(u8g2_font_crox4hb_tf);
  display.setCursor(1, 29); 
  display.print(RC_unit_items [item]);
  display.setCursor(1, 49); 
  display.print(internal_battery/1000);
  display.print(".");
  display.print((internal_battery%1000)/10);
  display.print("V");
  display.updateDisplay();
  screen_refresh = 0;
} 

if ((screen == 21) && screen_refresh == 1)
{homescreen();
  display.setFont(u8g2_font_crox4hb_tf);
  display.setCursor(1, 29); 
  display.print(RC_unit_items [item]);
  display.setCursor(1, 49); 
  display.print(internal_temp/100);
  display.print(".");
  display.print(internal_temp%100);
  display.print(" C");
  display.updateDisplay();
  screen_refresh = 0;
} 

if (screen == 22 && screen_refresh == 1)
{homescreen();  
 display.setFont(u8g2_font_crox4hb_tf);
 display.setCursor(1, 29); 
 display.print(RC_unit_items [item]); 
 display.setCursor(1, 49); 
 display.print ("< CH ");
 display.print(RC_channel);
 display.print(" >");
 display.updateDisplay();
 screen_refresh = 0;
} 

if (screen == 23 && screen_refresh == 1)
{homescreen();  
 display.setFont(u8g2_font_crox4hb_tf);
 display.setCursor(1, 29); 
 display.print(RC_unit_items [item]); 
 display.setCursor(1, 49); 
 display.print ("< ");
 display.print(refresh_rate /1000);
 display.print("s");
 display.print(" >");
 display.updateDisplay();
 screen_refresh = 0;
} 

if (screen == 24 && screen_refresh == 1)
{homescreen();  
 display.setFont(u8g2_font_crox4hb_tf);
 display.setCursor(1, 29); 
 display.print(RC_unit_items [item]);
 display.setCursor(1, 49); 
 display.print ("< ");
 display.print(on_off [beeper]);
 display.print(" >");
 display.updateDisplay();
 screen_refresh = 0;
}
//-------------------------------serial R/W----------------
//update needed
}  

void homescreen()
{
  display.clearDisplay();
  display.setDrawColor(1);
  display.setFont(u8g2_font_6x10_tf);
  display.drawFrame(0,0,19,10);
  display.drawBox(19, 3, 3, 4);  

  display.drawBox(2, 2, 3, 6);
  display.drawBox(6, 2, 3, 6);
  display.drawBox(10, 2, 3, 6);
  display.drawBox(14, 2, 3, 6);
  
  display.setCursor(45,8);
  if (screen < 3)
  {display.print(menu_items[screen]);  }
  else if (screen >= 10 && screen < 20)
  {display.print(menu_items[1]);  }
  else if (screen >= 20 && screen < 30)
  {display.print(menu_items[2]);}
  display.drawPixel(117, 10);
  display.drawPixel(118, 10);
  
  display.drawLine(120, 10, 120, 7);
  display.drawLine(121, 10, 121, 7);
  
  display.drawLine(123, 10, 123, 4);
  display.drawLine(124, 10, 124, 4);
  
  display.drawLine(126, 10, 126, 1);
  display.drawLine(127, 10, 127, 1);

  display.drawLine(0, 12, 128, 12); 

  
  display.drawLine(0, 55, 128, 55);
  display.setCursor(1, 64); 
  display.print("BACK");
  display.setCursor(100, 64); 
  display.print("MENU");
     
}


void display_item_text(char* text, int pos, boolean selected)
{
    if(selected)
    {
      display.setDrawColor(1);
      display.drawBox(0, pos-8, 128, 10);  
      display.setDrawColor(0);
    }else
    {
      display.setDrawColor(1);
    }
    display.setCursor(2, pos);
    display.print(text);
}
0
"Nemôžete sa báť ľudí, že vám ublížia, pretože ak sa budete obávať života, nikdy nebudete žiť..."
Chester Bennington

Napísať odpoveď
  • Podobné témy
    Odpovedí
    Zobrazení
    Posledný príspevok