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 ) 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
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 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);
}
nejaké fotky