@liudr, wouldn't it be nice to have my rotating arrow in front of your menu items? maybe, this way I can slip into the credits of your phi-menu just a joke.
All the code I post here is for everyone to use, just mention my name and URL
/* For the animation of the arrow we use 4 frames, of which only 3 frames are different. We are using frame 2 two times. In *arrow[4] we set up the frame order. for(char i=0; i<4; i++) means, do this 4 times and each time "i" will be 1 more. So the first time i=0 and arrows[i] will be arrowA1. The secend time i=1 and arrows[i] will be arrowA2 and so on till i=3 (i<4) Rotating Arrow by JO3RI http://www.JO3RI.be/arduino */ #include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void Rarrow() { for(char i=0; i<4; i++) // go trough this part 4 times. { byte arrowA1[8] = { // set up arrow frame 1, look at the 0's and the 1's B00000, // ░░░░░ B11000, // ██░░░ B10100, // █░█░░ B10010, // █░░█░ B10010, // █░░█░ B10100, // █░█░░ B11000, // ██░░░ B00000};// ░░░░░ byte arrowA2[8] = { // set up arrow frame 2, look at the 0's and the 1's B00000, // ░░░░░ B00000, // ░░░░░ B11000, // ██░░░ B10110, // █░██░ B10110, // █░██░ B11000, // ██░░░ B00000, // ░░░░░ B00000};// ░░░░░ byte arrowA3[8] = { // set up arrow frame 3, look at the 0's and the 1's B00000, // ░░░░░ B00000, // ░░░░░ B00000, // ░░░░░ B11110, // ████░ B11110, // ████░ B00000, // ░░░░░ B00000, // ░░░░░ B00000};// ░░░░░ byte *arrows[4]={arrowA1,arrowA2,arrowA3,arrowA2}; // set up each animation step: frame 1, frame 2, frame 3, frame 2 lcd.createChar(0, arrows[i]); //here we actually create the character on position zero lcd.setCursor(0,0); // here we set the cursor on location x and y (row and column) lcd.write(0); // write the character we defined in lcd.createChar to the LCD delay(250); // wait for 250 millisecs } }
The * in front of a variable name (byte *arrows) means that the variable is a pointer
aha, Ok I understand your explanation and I tested the code: IT WORKS
Now I cleaned up the code and I've put it here as a reference:
A rotating arrow on a 16x2 LCD
Code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); int z = 250; // set animation speed (actual the delay between each frame of the animation) byte arrowA1[8] = {B00000,B11000,B10100,B10010,B10010,B10100,B11000,B00000}; // set up arrow 1 byte arrowA2[8] = {B00000,B00000,B11000,B10110,B10110,B11000,B00000,B00000}; // set up arrow 2 byte arrowA3[8] = {B00000,B00000,B00000,B11110,B11110,B00000,B00000,B00000}; // set up arrow 3 byte *arrows[4]={arrowA1,arrowA2,arrowA3,arrowA2}; // set up each animation step: arrow 1, arrow 2, arrow 3, arrow 2
void setup() { lcd.begin(16, 2); }
void loop() { for(int i=0; i<4; i++) { lcd.clear(); lcd.createChar(0, arrows[i]); //here we actually create the character on position zero lcd.setCursor(0,0); // here we set the cursor on location x and y (row and column) lcd.write(0); // write the character we defined in lcd.createChar to the LCD delay(z); // wait for z millisecs } }
to match arrows instead of the confusing arrowA I'll test this within 2 hours, but I think you helped me out. I tried to fill out those arrowA1 ... in byte arrows[], but it gave an error. when putting * in front of arrows it compiles sketch. Why is that? what does the * mean?
It is the part where I try to put the chars on the LCD I want to simplify. I tried this, but it doesn't work:
Code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); byte x = 0; //set row on LCD byte y = 0; // set column on LCD int z = 250; // set animation speed (actual the delay between each frame of the animation)
byte arrowA1[8] = {B00000,B11000,B10100,B10010,B10010,B10100,B11000,B00000}; // set up arrow 1 byte arrowA2[8] = {B00000,B00000,B11000,B10110,B10110,B11000,B00000,B00000}; // set up arrow 2 byte arrowA3[8] = {B00000,B00000,B00000,B11110,B11110,B00000,B00000,B00000}; // set up arrow 3
byte arrowA[]={1,2,3,2}; // set up each animation step: arrow 1, arrow 2, arrow 3, arrow 2 int character = 0; // set up the character number (we can only have 8 characters at the same time on the display, but now we only need one, 0 in this case)
void setup() { lcd.begin(16, 2); }
void loop() { for(int i=0; i<3; i++) { lcd.clear(); lcd.createChar(character, arrowA[i]); //here we actually create the character on position character lcd.setCursor(x,y); // here we set the cursor on location x and y (row and column) lcd.write(character); // write the "characterpos" we defined in lcd.createChar to the LCD delay(z); // wait for z millisecs }
normally the
Code:
for(int i=0; i<3; i++)
should write each arrow on the same location with a delay of 250 millisecs and do this accordingly to
Code:
byte arrowA[]={1,2,3,2};
this should be: arrowA1, arrowA2, arrowA3, arrowA2, but it gives me: sketch_mar07a.cpp: In function 'void rotatingarrow()': sketch_mar07a:16: error: invalid conversion from 'int' to 'uint8_t*' sketch_mar07a:16: error: initializing argument 2 of 'void LiquidCrystal::createChar(uint8_t, uint8_t*)'
one would think arrowA[] would be replaced by 1 then 2 then 3 and then 2 again.
Below you see the code for a rotating arrow. Now as you can see it is actually 3 character sets being put on after an other. Actually I need something like 123212321232 and so on, but I don't know how to do that.
Code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); int x = 250; int y = 0; int z = 1;
@ Simpson_Jr: you'll have to read a bit more on Character creating. watch this link, It might help: http://icontexto.com/charactercreator/. Mind you, you can only have 8 of those at once on the LCD screen.
@liudr: you want to see a fist fly? watch this, it's even better.
and of course the code:
Mmm, seems its to long to post here. I made a project page of this on my website: