The Alpha Geek – Geeking Out

Project #3 – LCD Shield – Mk2

LCD Shield Mk2.01

LCD Shield Mk2.02

LCD Shield Mk2.03

LCD Shield Mk2.04

LCD Shield Mk2.05

LCD Shield Mk2.06

LCD Shield Mk2.07

LCD Shield Mk2.08

LCD Shield Mk2.09

LCD Shield Mk2.10

LCD Shield Mk2.11

LCD Shield Mk2.12

LCD Shield Mk2.13

LCD Shield Mk2.14

LCD Shield Mk2.15

LCD Shield Mk2.16

LCD Shield Mk2.17

LCD Shield Mk2.18

LCD Shield Mk2.19

LCD Shield Mk2.20

LCD Shield Mk2.21

LCD Shield Mk2.22

LCD Shield Mk2.23

LCD Shield Mk2.24

LCD Shield Mk2.25

1 X ChronoDot

1 X ProtoScrewShield

1 X Breadboard

4 X Jumper Wires Premium 3″ M/M

1 X CR1632

1 X Project #3 – LED Shield – Mk1

LCDShieldMk2.2.ino

// ***** Don Luc *****
// Software Version Information
// 2.2

// include the library code:
#include <Wire.h>
#include <Adafruit_MCP23017.h>
#include <Adafruit_RGBLCDShield.h>

Adafruit_RGBLCDShield RGBLCDShield = Adafruit_RGBLCDShield();

// These #defines make it easy to set the backlight color
#define OFF 0x0
#define RED 0x1
#define YELLOW 0x3
#define GREEN 0x2
#define TEAL 0x6
#define BLUE 0x4
#define VIOLET 0x5
#define WHITE 0x7

uint8_t i = 0;

void loop() {
  
  timeChrono();

  uint8_t momentaryButton = RGBLCDShield.readButtons();

  if ( momentaryButton ) {
    
    RGBLCDShield.clear();
    RGBLCDShield.setCursor(0,0);
    
    if ( momentaryButton & BUTTON_UP ) {
      RGBLCDShield.print("GREEN - UP ");
      RGBLCDShield.setBacklight(GREEN);
    }
    
    if ( momentaryButton & BUTTON_DOWN ) {
      RGBLCDShield.print("RED - DOWN ");
      RGBLCDShield.setBacklight(RED);
    }
    
    if ( momentaryButton & BUTTON_LEFT ) {
      RGBLCDShield.print("BLUE - LEFT ");
      RGBLCDShield.setBacklight(BLUE);
    }
    
    if ( momentaryButton & BUTTON_RIGHT ) {
      RGBLCDShield.print("YELLOW - RIGHT ");
      RGBLCDShield.setBacklight(YELLOW);
    }
    
    if ( momentaryButton & BUTTON_SELECT ) {
      RGBLCDShield.print("OFF ");
      RGBLCDShield.setBacklight(OFF);
    }
        
  }
  
  delay(1000);
  
}

setup.ino

void setup() {

  // set up the LCD's number of columns and rows: 
  RGBLCDShield.begin(16, 2);
  RGBLCDShield.print("Don Luc!!!");
  RGBLCDShield.setBacklight(VIOLET);
  
  // ChronoDot
  setupChrono();    
  
}

ChronoDot.ino

void setupChrono() {

  // clear /EOSC bit
  // Sometimes necessary to ensure that the clock
  // keeps running on just battery power. 
  Wire.beginTransmission(0x68); // address DS3231
  Wire.write(0x0E); // select register
  Wire.write(0b00011100); // write register bitmap, bit 7 is /EOSC
  Wire.endTransmission();  

}

void timeChrono() {

  // set the cursor to column 0, line 1
  RGBLCDShield.setCursor(0, 1);
  
   // send request to receive data starting at register 0
  Wire.beginTransmission(0x68); // 0x68 is DS3231 device address
  Wire.write((byte)0); // start at register 0
  Wire.endTransmission();
  Wire.requestFrom(0x68, 3); // request three bytes (seconds, minutes, hours)
 
  while(Wire.available())
  { 

    int seconds = Wire.read(); // get seconds
    int minutes = Wire.read(); // get minutes
    int hours = Wire.read();   // get hours
 
    seconds = (((seconds & 0b11110000)>>4)*10 + (seconds & 0b00001111)); // convert BCD to decimal
    minutes = (((minutes & 0b11110000)>>4)*10 + (minutes & 0b00001111)); // convert BCD to decimal
    hours = (((hours & 0b00100000)>>5)*20 + ((hours & 0b00010000)>>4)*10 + (hours & 0b00001111)); // convert BCD to decimal (assume 24 hour mode)
 
    // print the number of seconds since reset:
    RGBLCDShield.print(hours);
    RGBLCDShield.print(":");
    RGBLCDShield.print(minutes);
    RGBLCDShield.print(":");
    RGBLCDShield.print(seconds);

  }
  
}

Don Luc

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories
Archives