Saturday 2 April 2016

i2c LCD & Arduino - part 2

 A bit more about making graphics, how to position them
and scroll through different screens / menus

Part 1 is here
 

 
 
 The code:
// **************************************


#include <Wire.h>

#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
// RS, E, D4, D5, D6, D7
byte heart[] = {
  0x00,
  0x0A,
  0x1F,
  0x1F,
  0x0E,
  0x04,
  0x00,
  0x00
};

byte Speaker[] = {
0b00001,
0b00011,
0b01111,
0b01111,
0b01111,
0b00011,
0b00001,
0b00000
};

byte Sound[] = {
0b00001,
0b00011,
0b00101,
0b01001,
0b01001,
0b01011,
0b11011,
0b11000
};

byte Bell[] = {
0b00100,
0b01110,
0b01110,
0b01110,
0b11111,
0b00000,
0b00100,
0b00000
};

  byte Alien[8] = {
0b11111,
0b10101,
0b11111,
0b11111,
0b01110,
0b01010,
0b11011,
0b00000
};

byte Skull[] = {
0b00000,
0b01110,
0b10101,
0b11011,
0b01110,
0b01110,
0b00000,
0b00000
};

byte Lock[] = {
0b01110,
0b10001,
0b10001,
0b11111,
0b11011,
0b11011,
0b11111,
0b00000
};
 
void setup() {
   lcd.begin(16, 2);
  lcd.backlight();             // turn backlight on
  lcd.createChar(1, heart);    // define a symbol for memory position 1
  lcd.createChar(2, Speaker);    // define a symbol for memory position 2
  lcd.createChar(3, Sound);    // define a symbol for memory position 3
  lcd.createChar(4, Bell);    // define a symbol for memory position 4
  lcd.createChar(5, Alien);    // define a symbol for memory position 5
  lcd.createChar(6, Skull);    // define a symbol for memory position 6
  lcd.createChar(7, Lock);    // define a symbol for memory position 7

 
}
 
void loop() {
  lcd.clear();                 // clear the screen

  screen1();                   // execute screen1 function
  delay(1000);                 // pause for 1 second

  lcd.clear();                 // clear the screen

  screen2();                   // execute screen2 function
  delay(1000);                 // pause for 1 second

   lcd.clear();                 // clear the screen

  screen3();                   // execute screen3 function
  delay(1000);                 // pause for 1 second

   lcd.clear();                 // clear the screen

  screen4();                   // execute screen4 function
  delay(1000);                 // pause for 1 second
}

void screen1() {
  lcd.setCursor(0, 0);         // set the cursor to position 1, line 1
  lcd.print("I ");           // write on the screen
  lcd.write(1);                // write symbol from memory position 1
  lcd.print(" Synths");  // write on the screen

  lcd.setCursor(1, 1);         // set the cursor to position 2, line 2
  lcd.print("I ");           // write on the screen
  lcd.write(2);                // write symbol from memory position 2
  lcd.print(" Synths ");  // write on the screen
   lcd.write(5);                // write symbol from memory position 5
}

void screen2() {               
  lcd.setCursor(2, 1);         // set the cursor to position 3, line 2
  lcd.print("Buchla ");             // write on the screen
  lcd.write(3);                // write symbol from memory position 3
  lcd.print(" Rules");       // write on the screen
}

void screen3() {
  lcd.setCursor(0, 0);         // set the cursor to position 1, line 1
  lcd.print("Happy Easter");           // write on the screen
  lcd.write(1);                // write symbol from memory position 1
  lcd.write(2);                // write symbol from memory position 2
  lcd.write(3);                // write symbol from memory position 3
 
  lcd.setCursor(1, 1);         // set the cursor to position 2, line 2
  lcd.print("I ");           // write on the screen
  lcd.write(4);                // write symbol from memory position 2
  lcd.print(" Synths");  // write on the screen
}

void screen4() {
  lcd.setCursor(0, 0);         // set the cursor to position 1, line 1
  lcd.write(1);                // write symbol from memory position 1

 lcd.setCursor(2, 0);         // set the cursor to position 3, line 1
  lcd.write(2);                // write symbol from memory position 2

  lcd.setCursor(4, 0);         // set the cursor to position 5, line 1
  lcd.write(3);                // write symbol from memory position 3

   lcd.setCursor(6, 0);         // set the cursor to position 7, line 1
  lcd.write(4);                // write symbol from memory position 4

   lcd.setCursor(8, 0);         // set the cursor to position 9, line 1
  lcd.write(5);                // write symbol from memory position 5

   lcd.setCursor(10, 0);         // set the cursor to position 12, line 1
  lcd.write(6);                // write symbol from memory position 6

   lcd.setCursor(12, 0);         // set the cursor to position 14, line 1
  lcd.write(7);                // write symbol from memory position 7
 
  lcd.setCursor(1, 1);         // set the cursor to position 2, line 2
 
  lcd.write(4);                // write symbol from memory position 2
 
}
// ***************************************************




 ---------------------------------
------------------------------------- 
 

No comments:

Post a Comment