FL
Offline
Newbie
Karma: 0
Posts: 21
Arduino rocks
|
 |
« on: February 01, 2011, 11:25:22 am » |
I'm new to arduino, but I totally love this thang. Anyways... I'm writing a sketch that generates a random glyph -- it randomizes the binary used to build a custom character and creates an "alien-esque" letter or glyph. The code then plots the glyph from left to right on a 20x4 LCD, with the glyph being erased 5 positions back. I hooked up my LCD by using the ladyada tutorial for the 16x2 LCD. It.... works... but stops in the 16th column, and doesn't generate on the 4th row. I tried changing a bunch of things but nothing seems to work.
In the sketch is this code: LiquidCrystal lcd(7, 8, 9, 10, 11, 12); Initializing the LCD as the tutorial instructs.
I also changed the lcd.begin to: lcd.begin(20,4); thinking this would be right for a 20x4 display.
My guess is that either of these two are messing me up somehow. But I can't figure out how. And it's driving me nuts. Anyone out there care to have a look and see what I'm doing wrong? Or if there are any things that could be done in a more practical way? The entire code for the sketch is below. Again, I'm new, so please be kind!!!!!!!
/* ================================================= ALIEN TEXT ~ Corey Kingsbury ================================================= Creates a random "glyph" and then displays it on LCD screen. Notes: connect button to PIN 2. */ #include <LiquidCrystal.h>
String message="Press button to"; String message2="generate glyphs."; int button=2; int buttonState=0; int buttonSave=0; int theDelay=200; int glyph=0; int act=0; // btn action int col=0; // column 1 position int row=0; // row position int lag=5; // delay before deletion LiquidCrystal lcd(7, 8, 9, 10, 11, 12); // setup the LCD
void setup(){ lcd.begin(20,4); pinMode(button, INPUT); // Serial.begin(9600); }
void loop(){ buttonCheck(); if(act==2){ resetB(); makeGlyph(); }
if (act==0){ displayMessage(); } }
/*============================ ------- FUNCTIONS ------- ============================*/ //------- button operations void buttonCheck(){ buttonState=digitalRead(button); if(buttonState!=buttonSave){ resetA(); act++; if(act>3){ resetA(); act=0; } } buttonSave=buttonState; }
//------- create the glyph void makeGlyph(){ //-- generate it byte bin[] = {B00000,B10000,B10111,B10110,B10101,B11000,B11011,B11010,B11001,B11100,B11110,B11111,B01111,B00111,B00011,B00001,B00010,B01110,B10011,B01101,B01010,B00101,B10010,B10100,B11101,B01001,B01011,B10001,B00110,B01000,B00100,B01100}; byte setupGlyph[8] = {bin[random(31)],bin[random(31)],bin[random(31)],bin[random(31)],bin[random(31)],bin[random(31)],bin[random(31)],bin[random(31)],}; glyph++; if(glyph>20){ glyph=1; } lcd.createChar(glyph, setupGlyph);
//-- position if(col>19){ resetC(); } row=random(3); lcd.setCursor(col, row);
//-- write it lcd.write(glyph); delay(theDelay); col++; }
//------- push the btn msg void displayMessage(){ lcd.setCursor(0,0); lcd.print(message); lcd.setCursor(0,1); lcd.print(message2); }
//------- clear the LCD void resetA(){ lcd.clear(); col=0; row=0; }
void resetB(){ lcd.setCursor(col-lag,0); lcd.print(" ");
lcd.setCursor(col-lag,1); lcd.print(" ");
lcd.setCursor(col-lag,2); lcd.print(" ");
lcd.setCursor(col-lag,3); lcd.print(" "); }
void resetC(){ lcd.clear(); col=0; row=0; }
|