Go Down

Topic: Need help getting Bus route menu + route text (Read 171 times) previous topic - next topic

DHELL

Hi, I'm new with arduino and programming, but it would be awesome if I can get this to work for my actual work. I'm a busdriver for profession and to learn the new routes I'm going to drive I thought I would make an arduino nano with an oled display with a few buttons to operate the menu and text screens.

I'm using:
- Arduino Nano
- SH1106_128X64 oled screen
- 4 push buttons

What I need is a minimalist menu with a choice of 8 routes (actually 16, because for the return journey they are slightly different). And that I can select it, and then drive the route (by clicking next page at each bus stop) (I think of 4 buttons, (page up/down (or foreward/back)), select and back (to menu).

What does the oled need to display in the selected bus route (per page)?
A typical busline consist of 78 busstops (yeah a lot of text pages).
Screen size is 128x64 on 1.3 inch monochrome.
Screen divided into 4 long boxes (not equal)
• Top of the bus line with start and end point
  (Example: Lijn 90 Lisse - Den Haag)
• Divide line
• In the middle of the busstop
  (Example: De Nachtegaal)
There under the zone (on the right side of the screen)
  (Example: Zone 5544)
• Divide line
• Below that the direction for after the busstop
  (Example: Roundabout ◄)
  (Example 2: (traffic light left), right and onto the buslane)
  (would be nice to use symbols: up, down, left, right, roundabout, traffic light, tunnel, buslane)

Then I need it so, that I can press next page with a next page button and that the text change under the top line (the top line is the same for the whole submenu text) to the next busstop.
I have already downloaded a menu from the Internet via Github, but I do not really know how it can be changed or where I have to put my text.


Possible code I found on internet:

Code: [Select]
/*

Menu.pde

Simple Menu Selection

>>> Before compiling: Please remove comment from the constructor of the
>>> connected graphics display (see below).

Universal 8bit Graphics Library, https://github.com/olikraus/u8glib/

Copyright (c) 2012, olikraus@gmail.com
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


*/


#include "U8glib.h"

U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NO_ACK); // Display which does not send ACK


#define KEY_NONE 0
#define KEY_PREV 1
#define KEY_NEXT 2
#define KEY_SELECT 3
#define KEY_BACK 4

// DOGS102 shield configuration values
//uint8_t uiKeyPrev = 2;
//uint8_t uiKeyNext = 4;
//uint8_t uiKeySelect = 5;
//uint8_t uiKeyBack = 3;

// DOGM128-Shield configuration values
// DOGXL60-Shield configuration values
uint8_t uiKeyPrev = 7;
uint8_t uiKeyNext = 3;
uint8_t uiKeySelect = 2;
uint8_t uiKeyBack = 8;

uint8_t uiKeyCodeFirst = KEY_NONE;
uint8_t uiKeyCodeSecond = KEY_NONE;
uint8_t uiKeyCode = KEY_NONE;


void uiSetup(void) {
// configure input keys

pinMode(uiKeyPrev, INPUT_PULLUP); // set pin to input with pullup
pinMode(uiKeyNext, INPUT_PULLUP); // set pin to input with pullup
pinMode(uiKeySelect, INPUT_PULLUP); // set pin to input with pullup
pinMode(uiKeyBack, INPUT_PULLUP); // set pin to input with pullup
}

void uiStep(void) {
uiKeyCodeSecond = uiKeyCodeFirst;
if ( digitalRead(uiKeyPrev) == LOW )
uiKeyCodeFirst = KEY_PREV;
else if ( digitalRead(uiKeyNext) == LOW )
uiKeyCodeFirst = KEY_NEXT;
else if ( digitalRead(uiKeySelect) == LOW )
uiKeyCodeFirst = KEY_SELECT;
else if ( digitalRead(uiKeyBack) == LOW )
uiKeyCodeFirst = KEY_BACK;
else
uiKeyCodeFirst = KEY_NONE;

if ( uiKeyCodeSecond == uiKeyCodeFirst )
uiKeyCode = uiKeyCodeFirst;
else
uiKeyCode = KEY_NONE;
}


#define MENU_ITEMS 2
const char *menu_strings[MENU_ITEMS] = { "L 90 Lisse - Den Haag", "L 90 Den Haag - Lisse"};


uint8_t menu_current = 0;
uint8_t menu_redraw_required = 0;
uint8_t last_key_code = KEY_NONE;


void drawMenu(void) {
uint8_t i, h;
u8g_uint_t w, d;

u8g.setFont(u8g_font_6x13);
u8g.setFontRefHeightText();
u8g.setFontPosTop();

h = u8g.getFontAscent()-u8g.getFontDescent();
w = u8g.getWidth();
for( i = 0; i < MENU_ITEMS; i++ ) {
d = (w-u8g.getStrWidth(menu_strings[i]))/2;
u8g.setDefaultForegroundColor();
if ( i == menu_current ) {
u8g.drawBox(0, i*h+1, w, h);
u8g.setDefaultBackgroundColor();
}
u8g.drawStr(d, i*h, menu_strings[i]);
}
}

void updateMenu(void) {
if ( uiKeyCode != KEY_NONE && last_key_code == uiKeyCode ) {
return;
}
last_key_code = uiKeyCode;

switch ( uiKeyCode ) {
case KEY_NEXT:
menu_current++;
if ( menu_current >= MENU_ITEMS )
menu_current = 0;
menu_redraw_required = 1;
break;
case KEY_PREV:
if ( menu_current == 0 )
menu_current = MENU_ITEMS;
menu_current--;
menu_redraw_required = 1;
break;
}
}


void setup() {
// rotate screen, if required
// u8g.setRot180();

uiSetup(); // setup key detection and debounce algorithm
menu_redraw_required = 1; // force initial redraw
}

void loop() {

uiStep(); // check for key press

if ( menu_redraw_required != 0 ) {
u8g.firstPage();
do {
drawMenu();
} while( u8g.nextPage() );
menu_redraw_required = 0;
}

updateMenu(); // update menu bar

}


Thank you if you are willing to help me out.
Joris (DHELL)

wvmarle

Isn't it much easier to use your smartphone for this?

For starters you have a bit decent screen size and resolution to actually display a route (which may be a number of turns between each bus stop, and that whole stretch has to be displayed. I suppose you can program your routes in Google Maps which will automatically let you know where you are, show maps, etc.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

Go Up