Browse Source

scrolling text

main
Hendrik Langer 7 years ago
parent
commit
500b0f9a4a
  1. 18
      src/main.cpp
  2. 7
      src/selectionlist.cpp
  3. 27
      src/selectionlist.h

18
src/main.cpp

@ -53,6 +53,7 @@
#include "BME280.h"
#include "image.h"
#include "rotary.h"
#include "selectionlist.h"
U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ 15, /* data=*/ 4, /* reset=*/ 16);
@ -66,9 +67,12 @@ char timeStr[20];
BME280 bme280;
MP3 mp3;
Rotary rotary;
SelectionList menu;
uint32_t lastButtonPress = 0;
u8g2_uint_t titleStr_offset = 0;
//Variables for the sensor and the battery
static const int buttonPin = 0;
static const int ResetPin = 17;
@ -297,16 +301,20 @@ void loop()
u8g2.setFont(u8g2_font_inb19_mf);
u8g2.drawStr(0, 20, timeStr);
char title1[32]; char title2[32];
strncpy(title1, titleStr, 22); title1[22] = '\0';
strncpy(title2, titleStr+22, 32); title2[31] = '\0';
char weather[32];
u8g2.setFont(u8g2_font_profont12_mf); // choose a suitable font
sprintf(weather, "%.1f°C %.1f%% %.0fhPa", bme280.readTemperature(), bme280.readHumidity(), bme280.readPressure());
u8g2.drawUTF8(0, 30, weather);
u8g2.setFont(u8g2_font_prospero_bold_nbp_tf); // choose a suitable font
u8g2.drawUTF8(0, 54, title1);
u8g2.drawUTF8(0, 64, title2);
u8g2_uint_t width = u8g2.getUTF8Width(titleStr); // calculate the pixel width of the text
// repeated drawing of the scrolling text...
u8g2.drawUTF8(titleStr_offset, 54, titleStr); // draw the scolling text
titleStr_offset-=4; // scroll by one pixel
if ( (u8g2_uint_t)titleStr_offset < (u8g2_uint_t)-width )
titleStr_offset = 0; // start over again // u8g2.getDisplayWidth()
} else {
u8g2.drawXBMP(0,0, IMG_1872_width, IMG_1872_height, IMG_1872_bits);
}

7
src/selectionlist.cpp

@ -0,0 +1,7 @@
#include "selectionlist.h"
SelectionList::SelectionList() {}
SelectionList::SelectionList(const char* title, uint8_t start_pos, const char* string_list) {}
void SelectionList::draw() {}

27
src/selectionlist.h

@ -0,0 +1,27 @@
#ifndef _SELECTIONLIST_H
#define _SELECTIONLIST_H
#include <Arduino.h>
class SelectionList {
public:
SelectionList();
SelectionList(const char*, uint8_t, const char*);
void draw(void);
private:
const char* title = "Cloud Types";
const char *string_list =
"Altocumulus\n"
"Altostratus\n"
"Cirrocumulus\n"
"Cirrostratus\n"
"Cirrus\n"
"Cumulonimbus\n"
"Cumulus\n"
"Nimbostratus\n"
"Stratocumulus\n"
"Stratus";
uint8_t current_selection = 1;
};
#endif /* _SELECTIONLIST_H */
Loading…
Cancel
Save