Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Arduino-DEM jako licznik rowerowy
- Rysowanie bitmapy skali
- FreqCount - Example with serial output
- http://www.pjrc.com/teensy/td_libs_FreqCount.html
- LCD --- Arduino KS108
- 1 VSS - GND
- 2 VDD - +5V --- POT 1
- 3 V0 - --- --- POT 2
- 4 RS - A1
- 5 RW - A2
- 6 E - A3
- 7 DB0 - D4
- 8 DB1 - D5
- 9 DB2 - D6
- 10 DB3 - D7
- 11 DB4 - D8
- 12 DB5 - D9
- 13 DB6 - D10
- 14 DB7 - D11
- 15 CS1 - D12
- 16 RES - NIE PODLACZAC
- 17 CS2 - D13
- 18 CS3 - A0
- 19 VEE - --- --- POT 3
- 20 LED - +5V Podswietlenie
- */
- #include <Arduino.h>
- #include <U8g2lib.h>
- #include <EEPROM.h>
- #ifdef U8X8_HAVE_HW_SPI
- #include <SPI.h>
- #endif
- #ifdef U8X8_HAVE_HW_I2C
- #include <Wire.h>
- #endif
- //U8G2_SSD1306_128X32_WINSTAR_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE, /* clock=*/ SCL, /* data=*/ SDA); // pin remapping with ESP8266 HW I2C
- //U8G2_KS0108_128X64_1 u8g2(U8G2_R0, 21, 22, 23, 24, 25, 26, 27, 28, /*enable=*/ 20, /*dc=*/ 18, /*cs0=*/ 29, /*cs1=*/ 30, /*cs2=*/ U8X8_PIN_NONE, /* reset=*/ U8X8_PIN_NONE); // Set R/W to low!
- U8G2_KS0108_ERM19264_1 u8g2(U8G2_R0, 21, 22, 23, 24, 25, 26, 27, 28, /*enable=*/ 20, /*dc=*/ 18, /*cs0=*/ 29, /*cs1=*/ 30, /*cs2=*/ 31, /* reset=*/ U8X8_PIN_NONE); // Set R/W to low!
- //U8G2_T6963_240X128_1_8080 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable/wr=*/ 17, /*cs/ce=*/ 14, /*dc=*/ 15, /*reset=*/ 16); // Connect RD with +5V, FS0 and FS1 with GND
- //U8G2_T6963_256X64_1_8080 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable/wr=*/ 17, /*cs/ce=*/ 14, /*dc=*/ 15, /*reset=*/ 16); // Connect RD with +5V, FS0 and FS1 with GND
- //U8G2_T6963_160X80_1_8080 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable/wr=*/ 17, /*cs/ce=*/ 14, /*dc=*/ 15, /*reset=*/ 16); // Connect RD with +5V, FS0 and FS1 with GND
- //U8G2_T6963_128X64_1_8080 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable/wr=*/ 17, /*cs/ce=*/ 14, /*dc=*/ 15, /*reset=*/ 16); // Connect RD with +5V, FS0 and FS1 with GND
- //U8G2_T6963_128X64_ALT_1_8080 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable/wr=*/ 17, /*cs/ce=*/ 14, /*dc=*/ 15, /*reset=*/ 16); // Connect RD with +5V, FS0 and FS1 with GND
- //=================================================
- #include <OneWire.h> //Temperatura zewnetrzna
- #include <DallasTemperature.h>
- #define ONE_WIRE_BUS 6
- OneWire oneWire(ONE_WIRE_BUS);
- DallasTemperature sensors(&oneWire);
- // Adresy DS18B20
- uint8_t sensor1[8] = { 0x28, 0x90, 0x4E, 0x8A, 0x02, 0x00, 0x00, 0x69 }; //zewnetrzna
- //=================================================
- int lcd_gnd_RS = 18;
- int lcd_gnd_RW = 19;
- int Wejscie_LED_pozycyjne = 5;
- int Wyjscie_LED_pozycyjne = 34;
- int Wejscie_LED_pozycyjne_2 = 5;
- int Wyjscie_LED_pozycyjne_2 = 36;
- int Wejscie_LED_STOP = 4;
- int Wyjscie_LED_STOP = 40;
- int Wejscie_Migacz_Lewy = 9;
- int Wyjscie_Migacz_Lewy = 42;
- int Wejscie_Migacz_Prawy = 0;
- int Wyjscie_Migacz_Prawy = 44;
- int Wejscie_Stacyjka = 0;
- int Wyjscie_Stacyjka = 46;
- int Podswietlenie_PWM = 12;
- int Wyjscie_Alarm = 13;
- int Wejscie_Klawisz_Menu = 5;
- int Pomiar_Predkosci = 3; //pomiar predkosci z kola
- unsigned long aktualnyCzas = 0;
- unsigned long zapamietanyCzas_Migacz_Lewy = 0;
- int stan_Migacz_Lewy = LOW;
- unsigned long zapamietanyCzas_Migacz_Prawy = 0;
- int stan_Migacz_Prawy = LOW;
- int stateButton_Klawisz_Menu;
- int stateRelay_Klawisz_Menu = LOW;
- int previous_Klawisz_Menu = LOW;
- long time = 0;
- long debounce_Klawisz_Menu = 500;
- //=================================================
- boolean Strona_1 = false;
- boolean Strona_2 = false;
- //=================================================
- #define Suma_napiec Cela_1_in + Cela_2_in + Cela_3_in + Cela_4_in + Cela_5_in + Cela_6_in + Cela_7_in + Cela_8_in + Cela_9_in
- //#define Suma_napiec Cela_1_in + Cela_2_in + Cela_3_in + Cela_4_in + Cela_5_in + Cela_6_in + Cela_7_in + Cela_8_in + Cela_9_in + Cela_9_in + Cela_10_in + Cela_11_in + Cela_12_in + Cela_13_in + Cela_14_in + Cela_15_in + Cela_16_in
- //=================================================
- // RemoteXY select connection mode and include library
- #define REMOTEXY_MODE__ESP8266_HARDSERIAL_POINT
- #include <RemoteXY.h>
- // RemoteXY connection settings
- #define REMOTEXY_SERIAL Serial3
- #define REMOTEXY_SERIAL_SPEED 115200
- #define REMOTEXY_WIFI_SSID "Electrik Bike"
- #define REMOTEXY_WIFI_PASSWORD "Krzysiek19835"
- #define REMOTEXY_SERVER_PORT 6377
- // RemoteXY configurate
- #pragma pack(push, 1)
- uint8_t RemoteXY_CONF[] =
- { 255, 9, 0, 55, 0, 239, 1, 11, 24, 1,
- 2, 1, 38, 42, 15, 5, 24, 24, 135, 37,
- 79, 78, 0, 79, 70, 70, 0, 2, 1, 38,
- 47, 15, 5, 24, 24, 135, 37, 79, 78, 0,
- 79, 70, 70, 0, 2, 1, 38, 64, 15, 5,
- 24, 24, 135, 37, 79, 78, 0, 79, 70, 70,
- 0, 129, 0, 16, 43, 12, 3, 16, 83, 116,
- 97, 99, 121, 106, 107, 97, 0, 129, 0, 14,
- 48, 17, 3, 16, 79, 197, 155, 119, 105, 101,
- 116, 108, 101, 110, 105, 101, 0, 129, 0, 18,
- 65, 9, 3, 16, 65, 108, 97, 114, 109, 0,
- 129, 0, 12, 11, 3, 2, 16, 48, 37, 0,
- 129, 0, 48, 11, 5, 2, 16, 49, 48, 48,
- 37, 0, 129, 0, 22, 11, 4, 2, 16, 50,
- 53, 37, 0, 129, 0, 30, 11, 4, 2, 16,
- 53, 48, 37, 0, 129, 0, 38, 11, 4, 2,
- 16, 55, 53, 37, 0, 129, 0, 23, 2, 17,
- 5, 16, 66, 97, 116, 101, 114, 105, 97, 0,
- 1, 0, 36, 79, 9, 9, 64, 31, 226, 134,
- 144, 0, 1, 0, 46, 79, 9, 9, 64, 31,
- 226, 134, 146, 0, 129, 0, 11, 82, 24, 3,
- 16, 75, 105, 101, 114, 117, 110, 107, 111, 119,
- 115, 107, 97, 122, 121, 0, 129, 0, 2, 30,
- 29, 3, 16, 84, 101, 109, 112, 101, 114, 97,
- 116, 117, 114, 97, 32, 115, 105, 108, 110, 105,
- 107, 97, 58, 0, 129, 0, 15, 34, 8, 3,
- 16, 83, 116, 97, 110, 58, 0, 67, 0, 32,
- 29, 15, 5, 16, 26, 16, 67, 0, 32, 33,
- 30, 4, 16, 26, 26, 129, 0, 42, 29, 4,
- 4, 16, 194, 176, 67, 0, 2, 1, 38, 69,
- 15, 5, 24, 24, 135, 37, 79, 78, 0, 79,
- 70, 70, 0, 129, 0, 9, 70, 28, 3, 16,
- 79, 103, 114, 97, 110, 105, 99, 122, 101, 110,
- 105, 101, 32, 109, 111, 99, 121, 0, 65, 28,
- 12, 7, 3, 3, 65, 28, 16, 7, 3, 3,
- 65, 28, 20, 7, 3, 3, 65, 30, 24, 7,
- 3, 3, 65, 30, 28, 7, 3, 3, 65, 30,
- 32, 7, 3, 3, 65, 26, 36, 7, 3, 3,
- 65, 26, 40, 7, 3, 3, 65, 26, 44, 7,
- 3, 3, 65, 26, 48, 7, 3, 3, 2, 1,
- 38, 52, 15, 5, 24, 24, 135, 37, 79, 78,
- 0, 79, 70, 70, 0, 129, 0, 13, 53, 19,
- 3, 16, 79, 197, 155, 119, 105, 101, 116, 108,
- 101, 110, 105, 101, 32, 50, 0, 1, 0, 41,
- 90, 9, 9, 64, 31, 226, 153, 171, 0, 129,
- 0, 14, 94, 18, 3, 16, 79, 100, 115, 116,
- 114, 97, 115, 122, 97, 99, 122, 0, 1, 0,
- 43, 57, 6, 6, 1, 31, 83, 84, 79, 80,
- 0, 129, 0, 13, 59, 19, 3, 16, 197, 154,
- 119, 105, 97, 116, 108, 111, 32, 83, 84, 79,
- 80, 0
- };
- // this structure defines all the variables and events of your control interface
- struct {
- // input variables
- uint8_t switch_stacyjka; // =1 if switch ON and =0 if OFF
- uint8_t switch_swiatla; // =1 if switch ON and =0 if OFF
- uint8_t switch_alarm; // =1 if switch ON and =0 if OFF
- uint8_t button_migacz_lewy; // =1 if button pressed, else =0
- uint8_t button_migacz_prawy; // =1 if button pressed, else =0
- uint8_t switch_ograniczenie; // =1 if switch ON and =0 if OFF
- uint8_t switch_swiatla_2; // =1 if switch ON and =0 if OFF
- uint8_t button_migacz_odstraszacz; // =1 if button pressed, else =0
- uint8_t button_STOP; // =1 if button pressed, else =0
- // output variables
- char text_temperatura[16]; // string UTF8 end zero
- char text_stan[26]; // string UTF8 end zero
- uint8_t led_0_r; // =0..255 LED Red brightness
- uint8_t led_1_r; // =0..255 LED Red brightness
- uint8_t led_2_r; // =0..255 LED Red brightness
- uint8_t led_3_r; // =0..255 LED Red brightness
- uint8_t led_3_g; // =0..255 LED Green brightness
- uint8_t led_4_r; // =0..255 LED Red brightness
- uint8_t led_4_g; // =0..255 LED Green brightness
- uint8_t led_5_r; // =0..255 LED Red brightness
- uint8_t led_5_g; // =0..255 LED Green brightness
- uint8_t led_6_g; // =0..255 LED Green brightness
- uint8_t led_7_g; // =0..255 LED Green brightness
- uint8_t led_8_g; // =0..255 LED Green brightness
- uint8_t led_9_g; // =0..255 LED Green brightness
- // other variable
- uint8_t connect_flag; // =1 if wire connected, else =0
- } RemoteXY;
- #pragma pack(pop)
- //=================================================
- //Zmienne do pomiaru prędkości
- int count, count1;
- char m_str[6];
- String m1_str;
- unsigned long duration;
- float r_kola = 0.7; //promień koła w metrach
- float d_kola;
- //zmienne do obliczenia długosci drogi
- int lok; //liczba obrotów koła
- float d_etapu, de_km; //długość etapu, odległość w km
- int d_total; //odległość całkowita od początku
- char d_tot_str[6];
- int de_int, de_int1, de_dz;
- char de_str[3], de1_str[3];
- //zmienne do pomiaru czasu
- byte godz, minuty, sekundy;
- unsigned long czas_e; //całkowity czas etapu
- char godz_str[3], minuty_str[3], sekundy_str[3];
- //zmienne do pomiaru napiecia
- //================================= CELA_1
- float Cela_1_out = 0.0;
- float Cela_1_in = 0.0;
- float R1_Cela_1 = 100000.0; // resistance of R1 (100K)
- float R2_Cela_1 = 10000.0; // resistance of R2 (10K)
- int value_1 = 0;
- //================================= CELA_2
- float Cela_2_out = 0.0;
- float Cela_2_in = 0.0;
- float R1_Cela_2 = 100000.0; // resistance of R1 (100K)
- float R2_Cela_2 = 10000.0; // resistance of R2 (10K)
- int value_2 = 0;
- //================================= CELA_3
- float Cela_3_out = 0.0;
- float Cela_3_in = 0.0;
- float R1_Cela_3 = 100000.0; // resistance of R1 (100K)
- float R2_Cela_3 = 10000.0; // resistance of R2 (10K)
- int value_3 = 0;
- //================================= CELA_4
- float Cela_4_out = 0.0;
- float Cela_4_in = 0.0;
- float R1_Cela_4 = 100000.0; // resistance of R1 (100K)
- float R2_Cela_4 = 10000.0; // resistance of R2 (10K)
- int value_4 = 0;
- //================================= CELA_5
- float Cela_5_out = 0.0;
- float Cela_5_in = 0.0;
- float R1_Cela_5 = 100000.0; // resistance of R1 (100K)
- float R2_Cela_5 = 10000.0; // resistance of R2 (10K)
- int value_5 = 0;
- //================================= CELA_6
- float Cela_6_out = 0.0;
- float Cela_6_in = 0.0;
- float R1_Cela_6 = 100000.0; // resistance of R1 (100K)
- float R2_Cela_6 = 10000.0; // resistance of R2 (10K)
- int value_6 = 0;
- //================================= CELA_7
- float Cela_7_out = 0.0;
- float Cela_7_in = 0.0;
- float R1_Cela_7 = 100000.0; // resistance of R1 (100K)
- float R2_Cela_7 = 10000.0; // resistance of R2 (10K)
- int value_7 = 0;
- //================================= CELA_8
- float Cela_8_out = 0.0;
- float Cela_8_in = 0.0;
- float R1_Cela_8 = 100000.0; // resistance of R1 (100K)
- float R2_Cela_8 = 10000.0; // resistance of R2 (10K)
- int value_8 = 0;
- //================================= CELA_9
- float Cela_9_out = 0.0;
- float Cela_9_in = 0.0;
- float R1_Cela_9 = 100000.0; // resistance of R1 (100K)
- float R2_Cela_9 = 10000.0; // resistance of R2 (10K)
- int value_9 = 0;
- //================================= CELA_10
- float Cela_10_out = 0.0;
- float Cela_10_in = 0.0;
- float R1_Cela_10 = 100000.0; // resistance of R1 (100K)
- float R2_Cela_10 = 10000.0; // resistance of R2 (10K)
- int value_10 = 0;
- //================================= CELA_11
- float Cela_11_out = 0.0;
- float Cela_11_in = 0.0;
- float R1_Cela_11 = 100000.0; // resistance of R1 (100K)
- float R2_Cela_11 = 10000.0; // resistance of R2 (10K)
- int value_11 = 0;
- //================================= CELA_12
- float Cela_12_out = 0.0;
- float Cela_12_in = 0.0;
- float R1_Cela_12 = 100000.0; // resistance of R1 (100K)
- float R2_Cela_12 = 10000.0; // resistance of R2 (10K)
- int value_12 = 0;
- //================================= CELA_13
- float Cela_13_out = 0.0;
- float Cela_13_in = 0.0;
- float R1_Cela_13 = 100000.0; // resistance of R1 (100K)
- float R2_Cela_13 = 10000.0; // resistance of R2 (10K)
- int value_13 = 0;
- //================================= CELA_14
- float Cela_14_out = 0.0;
- float Cela_14_in = 0.0;
- float R1_Cela_14 = 100000.0; // resistance of R1 (100K)
- float R2_Cela_14 = 10000.0; // resistance of R2 (10K)
- int value_14 = 0;
- //================================= CELA_14
- float Cela_15_out = 0.0;
- float Cela_15_in = 0.0;
- float R1_Cela_15 = 100000.0; // resistance of R1 (100K)
- float R2_Cela_15 = 10000.0; // resistance of R2 (10K)
- int value_15 = 0;
- //================================= CELA_14
- float Cela_16_out = 0.0;
- float Cela_16_in = 0.0;
- float R1_Cela_16 = 100000.0; // resistance of R1 (100K)
- float R2_Cela_16 = 10000.0; // resistance of R2 (10K)
- int value_16 = 0;
- void setup(void) {
- Serial.begin(9600);
- RemoteXY_Init ();
- pinMode(Wejscie_LED_pozycyjne, INPUT_PULLUP);
- pinMode(Wejscie_LED_pozycyjne_2, INPUT_PULLUP);
- pinMode(Wejscie_LED_STOP, INPUT_PULLUP);
- pinMode(Wejscie_Migacz_Lewy, INPUT_PULLUP);
- pinMode(Wejscie_Migacz_Prawy, INPUT_PULLUP);
- pinMode(Wejscie_Stacyjka, INPUT_PULLUP);
- pinMode(Wejscie_Klawisz_Menu, INPUT_PULLUP);
- pinMode(Wyjscie_LED_pozycyjne, OUTPUT);
- pinMode(Wyjscie_LED_pozycyjne_2, OUTPUT);
- pinMode(Wyjscie_LED_STOP, OUTPUT);
- pinMode(Wyjscie_Migacz_Lewy, OUTPUT);
- pinMode(Wyjscie_Migacz_Prawy, OUTPUT);
- pinMode(Wyjscie_Stacyjka, OUTPUT);
- pinMode(Wyjscie_Alarm, OUTPUT);
- pinMode(Pomiar_Predkosci, INPUT_PULLUP); //linia do współpracy z hallotronem
- pinMode(Podswietlenie_PWM, OUTPUT);
- pinMode(lcd_gnd_RS, OUTPUT);
- pinMode(lcd_gnd_RW, OUTPUT);
- digitalWrite(lcd_gnd_RS, LOW);
- digitalWrite(lcd_gnd_RW, LOW);
- d_kola = r_kola * 2 * PI; //obwód kola
- Strona_2 = true;
- //=================================================
- sensors.begin();
- sensors.requestTemperatures();
- dtostrf(sensors.getTempC(sensor1), 0, 1, RemoteXY.text_temperatura);
- delay (50);
- u8g2.begin();
- Podswietlenie();
- }
- void loop(void) {
- aktualnyCzas = millis();
- RemoteXY_Handler ();
- Pulpit();
- Speed();
- Temperatura();
- d_total = readFromEEPROM();
- Dystans();
- sprintf(d_tot_str, " %d", d_total);
- //=================================
- Bateria();
- Stacyjka();
- Alarm();
- //=================================
- stateButton_Klawisz_Menu = digitalRead(Wejscie_Klawisz_Menu);
- if (stateButton_Klawisz_Menu == LOW && previous_Klawisz_Menu == LOW && millis() - time > debounce_Klawisz_Menu) {
- if (stateRelay_Klawisz_Menu == HIGH) {
- stateRelay_Klawisz_Menu = LOW;
- Strona_1 = true;
- Strona_2 = false;
- } else {
- stateRelay_Klawisz_Menu = HIGH;
- Strona_1 = false;
- Strona_2 = true;
- }
- time = millis();
- }
- previous_Klawisz_Menu == stateButton_Klawisz_Menu;
- if (Strona_2 == true) {
- u8g2.firstPage();
- do {
- //wypisanie Napiecia
- u8g2.setFont(u8g2_font_profont11_tf);
- u8g2.drawStr(124, 17, "BATERIA");
- u8g2.setFont(u8g_font_profont17r); // select font
- u8g2.drawRFrame(112, 18, 67, 20, 5); // draws frame with rounded edges
- u8g2.setCursor(119, 34);
- u8g2.println(Suma_napiec); //Prints the voltage
- u8g2.println("V");
- Rysuj_skale();
- Ograniczenie();
- Oswietlenie_1();
- Oswietlenie_2();
- Swiatlo_STOP();
- Migacz_Lewy();
- Migacz_Prawy();
- Temperatura_BMP();
- Ograniczenie_mocy_BMP();
- Akumulator_BMP();
- Ladowanie_BMP();
- Swiatla_Pozycyjne_BMP();
- Swiatla_Dlugie_BMP();
- Hamulec_BMP();
- Strzalka_Lewa_BMP();
- Strzalka_Prawa_BMP();
- //wypisanie prędkości
- u8g2.setFont(u8g2_font_logisoso16_tn);
- //równanie wyniku pomiaru do ostatniej cyfry
- if (m1_str.length() == 1 ) {
- u8g2.drawStr(88, 63, m_str); //dla wyniku 1-cyfrowego
- }
- if (m1_str.length() == 2 ) {
- u8g2.drawStr(78, 63, m_str); //dla wyniku 2-cyfrowego
- }
- /* if (m1_str.length() == 3 ) {
- u8g2.drawStr(82, 63, m_str); //dla wyniku 3-cyfrowego
- }
- if (m1_str.length() == 4 ) {
- u8g2.drawStr(72, 63, m_str); //dla wyniku 4-cyfrowego
- }
- */
- //wypisanie kilometrażu całkowitego
- u8g2.setFont(u8g2_font_profont11_tf);
- u8g2.drawStr(50, 63, d_tot_str);
- u8g2.setCursor(64, 63);
- u8g2.println("km");
- //wypisanie długosci etapu
- u8g2.drawStr(34, 55, de_str);
- u8g2.drawStr(44, 55, ".");
- u8g2.drawStr(50, 55, de1_str);
- u8g2.drawStr(64, 55, "km");
- //wypisanie temperatury
- u8g2.drawRFrame(112, 47, 67, 17, 5); // draws frame with rounded edges
- u8g2.setFont(u8g2_font_profont11_tf);
- u8g2.drawStr(113, 46, "TEMPERATURA");
- u8g2.drawGlyph(160, 57, 176);
- u8g2.setFont(u8g_font_profont17r); // select font
- u8g2.setCursor(116, 61);
- u8g2.println(sensors.getTempC(sensor1));
- u8g2.setCursor(166, 61);
- u8g2.println("C");
- } while ( u8g2.nextPage() );
- delay(5);
- }
- }
- int readFromEEPROM() {
- byte high = EEPROM.read(1);
- byte low = EEPROM.read(2);
- return (high << 8) + low;
- }
Add Comment
Please, Sign In to add comment