Hi, I am building a pinball machine using an arduino as a scoreboard, it works w 16x2 lcd and now I want to use a 128x64 display st7920 U8glib but I do not know how to use it.
I would like to ask for help from you with the code if possible by changing the command lcd.print with the appropriate command for the ST7920, thank you very much.
U8GLIB_ST7920_128X64_1X u8g(6, 5, 4 ,7); //Enable, RW, RS, RESET
Here is the code :
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
bool button_0State = LOW; // the current STABLE STATE of the input pin
bool lastButton_0State = LOW; // the previous reading from the input pin
long lastDebounce_0Time = 0; // the last time the output pin was toggled
long debounceDelay = 50; // the debounce time; increase if the output flickers
boolean lastReadButton1;
boolean lastReadButton2;
boolean lastReadButton3;
boolean lastReadButton4;
unsigned int score = 0;
int ballnumber = 5;
int a = 100;
int b = 500;
int c = 1000;
unsigned long bonusTime = 0; //isto fica fora da função loop().
unsigned char BonusOn = 0; //isto também fica fora da função loop()
// SETUP===========================================
void setup() {
//input pins for scoring triggers
pinMode(7, INPUT);
pinMode(8, INPUT);
pinMode(9, INPUT);
pinMode(10, INPUT);
// set up the LCD:
lcd.begin(16, 2);
lcd.clear();
}
//LOOP==============================================
void loop() {
//LCD TOP ROW: SCORE / GAME OVER
lcd.setCursor(0, 0);
if (ballnumber < 0)
{
lcd.print("GAME OVER ");
}
else
{
lcd.print("SCORE: BALL:");
lcd.print(ballnumber);
}
//LCD BOTTOM ROW: NUMERIC SCORE
lcd.setCursor(0, 1);
lcd.print(score);
//BONUS faltando millis//////////////////////////////////////
boolean readButton4 = digitalRead( 10 ) ;
if (readButton4 == LOW and lastReadButton4 == HIGH)
{
BonusOn = 1;
a = a*5; b = b*5; c = c*5;
bonusTime = millis();
}
lastReadButton4 = readButton4;
if (BonusOn == 1 && (millis() - bonusTime >= 60000) ) {
BonusOn = 0;
a = 100;
b = 500;
c = 1000;
}
//Placar de 100 PTS //////////////////////////////////////
boolean readButton1 = digitalRead ( 8 ) ;
if (readButton1 == LOW and lastReadButton1 == HIGH)
{
score = score + a;
}
lastReadButton1 = readButton1;
//Placar de 500 PTS //////////////////////////////////////
boolean readButton2 = digitalRead ( 9 ) ;
if (readButton2 == LOW and lastReadButton2 == HIGH)
{
score = score + b;
}
lastReadButton2 = readButton2;
///Bola perdida///GAME OVER///////////////////////////////////
bool reading = digitalRead( 7 );
if (reading != lastButton_0State) {
lastDebounce_0Time = millis(); // reset the time since last stable state
lastButton_0State = reading;
}
if ((millis() - lastDebounce_0Time) > debounceDelay) {
// test for a transition from low-high or high-low
if (button_0State != lastButton_0State) {
button_0State = lastButton_0State;
if (button_0State == HIGH) {
ballnumber = ballnumber - 1;
}
}
}
}
Are there any examples with the library ?
UKHeliBob:
Are there any examples with the library ?
Hi HeliBob and tank you for your help, i hope this help u better than me .
/*
HelloWorld.pde
"Hello World!" example code.
>>> Before compiling: Please remove comment from the constructor of the
>>> connected graphics display (see below).
Universal 8bit Graphics Library, http://code.google.com/p/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.
*/
U8GLIB_ST7920_128X64_1X u8g(6, 5, 4 ,7); //Enable, RW, RS, RESET
void draw(void) {
// graphic commands to redraw the complete screen should be placed here
u8g.setFont(u8g_font_unifont);
//u8g.setFont(u8g_font_osb21);
u8g.drawStr( 0, 22, "Hello World!");
}
void setup(void) {
// flip screen, if required
// u8g.setRot180();
// set SPI backup if required
//u8g.setHardwareBackup(u8g_backup_avr_spi);
// assign default color value
if ( u8g.getMode() == U8G_MODE_R3G3B2 ) {
u8g.setColorIndex(255); // white
}
else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) {
u8g.setColorIndex(3); // max intensity
}
else if ( u8g.getMode() == U8G_MODE_BW ) {
u8g.setColorIndex(1); // pixel on
}
else if ( u8g.getMode() == U8G_MODE_HICOLOR ) {
u8g.setHiColorByRGB(255,255,255);
}
}
void loop(void) {
// picture loop
u8g.firstPage();
do {
draw();
} while( u8g.nextPage() );
// rebuild the picture after some delay
delay(500);
}
i have read all the manual , but i cant figure out how to print and then clear like i do in 16x2.
Does the example work ?
I am surprised not to see a library #included in the program
What is it about the example that you don't understand ? Have you tried incorporating the principles into your program ?
Normally you would need to do the following :
#include the library
Create an object to print to and give it a name
Choose the font
Print your text at the coordinates you want
UKHeliBob:
Does the example work ?
I am surprised not to see a library #included in the program
What is it about the example that you don't understand ? Have you tried incorporating the principles into your program ?
Normally you would need to do the following :
#include the library
Create an object to print to and give it a name
Choose the font
Print your text at the coordinates you want
I have tried this but i got an error draw was not declared in this scope , maybe something is wrong , if u could help i will apreciate it .
#include "U8glib.h"
U8GLIB_ST7920_128X64_1X u8g(6, 5, 4 ,7); //Enable, RW, RS, RESET
bool button_0State = LOW; // the current STABLE STATE of the input pin
bool lastButton_0State = LOW; // the previous reading from the input pin
long lastDebounce_0Time = 0; // the last time the output pin was toggled
long debounceDelay = 50; // the debounce time; increase if the output flickers
boolean lastReadButton1;
boolean lastReadButton2;
boolean lastReadButton3;
boolean lastReadButton4;
//Placar//
unsigned int score = 0;
int ballnumber = 5;
int a = 100;
int b = 500;
int c = 1000;
unsigned long bonusTime = 0; //isto fica fora da função loop().
unsigned char BonusOn = 0; //isto também fica fora da função loop()
// SETUP===========================================
void setup() {
u8g.setFont(u8g_font_unifont);
u8g.setColorIndex(1);
//PINOS//
pinMode(7, INPUT);
pinMode(8, INPUT);
pinMode(9, INPUT);
pinMode(10, INPUT);
// set up the LCD:
//lcd.begin(16, 2);
//lcd.clear();
}
//LOOP==============================================
void loop() {
//LCD TOP ROW: SCORE / GAME OVER
//lcd.setCursor(0, 0);
u8g.firstPage();
do {
draw();
} while( u8g.nextPage() );}
if (ballnumber < 0)
void draw(){
u8g.drawStr( 0, 20, "GAME OVER");
}
else
{
//lcd.print("SCORE: BALL:");
//lcd.print(ballnumber);
u8g.drawStr(0,20,"SCORE: BALL:");
u8g.drawStr(0,60,ballnumber);
}
//LCD BOTTOM ROW: NUMERIC SCORE
//lcd.setCursor(0, 1);
//lcd.print(score);
Look at the example you posted. It has a daw() function in it
Look at your program. It does not have a draw() function in it