The Alpha Geek – Geeking Out

Project #3 – LCD Shield – Mk5

LCD Shield Mk5.01

LCD Shield Mk5.02

LCD Shield Mk5.03

LCD Shield Mk5.04

LCD Shield Mk5.05

LCD Shield Mk5.06

LCDShieldMk5.1.ino

// ***** Don Luc *****
// Software Version Information
// 5.1

// include the library code:
#include <Wire.h>
#include <Adafruit_MCP23017.h>
#include <Adafruit_RGBLCDShield.h>
#include <SPI.h>
#include <RTClib.h>
#include <RTC_DS3231.h>
#include <OneWire.h> 

RTC_DS3231 RTC;

#define SQW_FREQ DS3231_SQW_FREQ_1024     //0b00001000   1024Hz

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

int yy = 0;
uint8_t momentaryButton = 0;

// Chorno
boolean isChorno = true;
boolean isChor = false;
char datastr[100];
int zz = 0;
// LDR (light dependent resistor)
int LDR_Pin = A0;
int LDRReading = 0;
String LDR = "";
// Temperature chip i/o
int DS18S20_Pin = 2; //DS18S20 Signal pin on digital 2
OneWire ds(DS18S20_Pin);  // on digital pin 2
float temperature = 0;
String tempZ = "";
// Potentiometer
int potPin = A2;    // select the input pin for the potentiometer
int ledPin = 4;   // select the pin for the LED
boolean isVal = false;
int potPot = 0;
String cap = "";

void loop() {

  RGBLCDShield.clear();
    
  // ChronoDot
  // set the cursor to column 0, line 1
  RGBLCDShield.setCursor(0, 1);
  timeChrono();
  // LDR (light dependent resistor)
  timeLDR();
  // Temperature chip i/o
  temperatu();
  // Potentiometer
  getPotentio();
    
  momentaryButton = RGBLCDShield.readButtons();

  // set the cursor to column 0, line 0
  RGBLCDShield.setCursor(0,0);

  switch ( yy ) {
    case 1:
      // LDR (light dependent resistor)
      isLDR();
      break;
    case 2:
      // Temperature chip i/o
      isTe();
      break;
    case 3:
      // Potentiometer
      isCap();
      break;
    case 4:
      // Yellow
      RGBLCDShield.print("YELLOW - RIGHT");
      break;
    case 5:
      // OFF
      RGBLCDShield.print("OFF");
      break;
    default: 
      yy = 0;
      RGBLCDShield.print("Don Luc!!!");
   }
   
  if ( momentaryButton ) {
    
    if ( momentaryButton & BUTTON_UP ) {
      isChorno = true;
      yy = 1;
      // LDR (light dependent resistor)
      RGBLCDShield.setBacklight(GREEN);
    }
    
    if ( momentaryButton & BUTTON_DOWN ) {
      isChorno = true;
      yy = 2;
      // Temperature chip i/o
      RGBLCDShield.setBacklight(RED);
    }
    
    if ( momentaryButton & BUTTON_LEFT ) {
      isChorno = true;
      yy =3;
      // Potentiometer
      RGBLCDShield.setBacklight(BLUE);
    }
    
    if ( momentaryButton & BUTTON_RIGHT ) {
      isChorno = true;
      yy = 4;
      //RGBLCDShield.print("YELLOW - RIGHT");
      RGBLCDShield.setBacklight(YELLOW);
    }
    
    if ( momentaryButton & BUTTON_SELECT ) {
      isChorno = false;
      yy = 5;
      //RGBLCDShield.print("OFF");
      RGBLCDShield.setBacklight(OFF);
    }
    
  }
  
  delay(5000);
  
}

setup.ino

void setup() {    
   
  // set up the LCD's number of columns and rows: 
  RGBLCDShield.begin(16, 2);
  RGBLCDShield.setBacklight(VIOLET);
  
  // ChronoDot
  setupChrono();
  
  // Pot
  pinMode(ledPin, OUTPUT);
    
}

ChronoDot.ino

void setupChrono() {

  RTC.begin();
  
  DateTime now = RTC.now();
  DateTime compiled = DateTime(__DATE__, __TIME__);
  RTC.getControlRegisterData( datastr[0] );  
   
}

void timeChrono() {
 
    DateTime now = RTC.now();
    DateTime isNow (now.unixtime() + 5572 * 86400L + 26980);

    if ( isChorno == true )
    {
      if ( isChor == false ) 
        {          
          isChor = true;
          RGBLCDShield.print(isNow.year(), DEC);
          RGBLCDShield.print('/');
          RGBLCDShield.print(isNow.month(), DEC);
          RGBLCDShield.print('/');
          RGBLCDShield.print(isNow.day(), DEC);
          RGBLCDShield.print(' ');
          RGBLCDShield.print(' ');
        }
        else if ( isChor == true )
        {
          isChor = false;
          RGBLCDShield.print(isNow.hour(), DEC);
          RGBLCDShield.print(':');
          RGBLCDShield.print(isNow.minute(), DEC);
          RGBLCDShield.print(':');
          RGBLCDShield.print(isNow.second(), DEC);
          RGBLCDShield.print(' ');
          RGBLCDShield.print(' ');
        }
    }
    
}

getLDR.ino

void timeLDR() {
  
  // LDR
  LDRReading = analogRead(LDR_Pin);
 
}

void isLDR() {
  
  LDR = "LDR: ";
  LDR.concat(LDRReading); 
  // LDR (light dependent resistor)
  RGBLCDShield.print( LDR ); 
  
} 

getPot.ino

void getPotentio() {
  
    if ( isVal == false ) 
    {
       isVal = true;
       digitalWrite(ledPin, HIGH);  // turn the ledPin on
    }
    else if ( isVal == true )
    {
       isVal = false;
       digitalWrite(ledPin, LOW);  // turn the ledPin off
    }       
    potPot = analogRead(potPin);    // read the value from the sensor
  
}

void isCap(){
  
    cap = "Pot: ";
    cap.concat(potPot);
    RGBLCDShield.print( cap );

}

getTemperature.ino

float getTemp() {
  
  //returns the temperature from one DS18S20 in DEG Celsius
  byte data[12];
  byte addr[8];

  if ( !ds.search(addr)) {
      //no more sensors on chain, reset search
      ds.reset_search();
      return -1001;
  }

  if ( OneWire::crc8( addr, 7) != addr[7]) {
      return -1002;
  }

  if ( addr[0] != 0x10 && addr[0] != 0x28) {
      return -1003;
  }

  ds.reset();
  ds.select(addr);
  ds.write(0x44,1); // start conversion, with parasite power on at the end

  byte present = ds.reset();
  ds.select(addr);    
  ds.write(0xBE); // Read Scratchpad

  
  for (int i = 0; i < 9; i++) { // we need 9 bytes
    data[i] = ds.read();
  }
  
  ds.reset_search();
  
  byte MSB = data[1];
  byte LSB = data[0];

  float tempRead = ((MSB << 8) | LSB); //using two's compliment
  float TemperatureSum = tempRead / 16;
  
  return TemperatureSum;

}

void temperatu(){
  
  temperature = getTemp();
 
}

void isTe() {
  
  tempZ = "Temp: ";
  tempZ.concat(temperature);
  tempZ.concat("C");
  RGBLCDShield.print( tempZ );
  
}

Don Luc

Leave a Reply

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

Categories
Archives