Skip to content

Instantly share code, notes, and snippets.

@JeffersGlass
Created May 9, 2020 22:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JeffersGlass/e60951492760d652061459b1d855e749 to your computer and use it in GitHub Desktop.
Save JeffersGlass/e60951492760d652061459b1d855e749 to your computer and use it in GitHub Desktop.
/*
LiquidCrystal Library - Hello World
Demonstrates the use a 16x2 LCD display. The LiquidCrystal
library works with all LCD displays that are compatible with the
Hitachi HD44780 driver. There are many of them out there, and you
can usually tell them by the 16-pin interface.
The circuit:
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* LCD VSS pin to ground
* LCD VCC pin to 5V
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
*/
#include <IRLibDecodeBase.h> // First include the decode base
#include <IRLib_P01_NEC.h> // Include only the protocol you are using
// include the library code:
#include <LiquidCrystal.h>
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 8, en = 9, d4 = 10, d5 = 11, d6 = 12, d7 = 13;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
#include <IRLibRecv.h>
IRrecv myReceiver(2); //pin number for the receiver
IRdecodeNEC myDecoder;
const int redPin = 3;
const int greenPin = 6;
const int bluePin = 5;
int pins[] = {redPin, greenPin, bluePin};
int cursorIndex = 0;
int displayPositions[] = {0, 6, 12};
int numPositions = 3;
int buttonIncrement = 5;
//red, green, blue
int color[] = {125, 125, 125};
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
displayColors();
lcd.cursor();
lcd.noBlink();
myReceiver.enableIRIn(); // Start the receiver
}
#define MYPROTOCOL NEC
#define CHMINUS 0xFFA25D
#define VOLMINUS 0xFF22DD
#define MINUS 0xFFE01F
#define ZERO 0xFF6897
#define ONEHUNDRED 0xFF9867
#define TWOHUNDRED 0xFFB04F
void loop() {
if (checkButtons()){
displayColors();
}
}
void displayColors(){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("RED");
lcd.setCursor(0,1);
lcd.print(color[0]);
lcd.setCursor(6,0);
lcd.print("GRN");
lcd.setCursor(6,1);
lcd.print(color[1]);
lcd.setCursor(12,0);
lcd.print("BLU");
lcd.setCursor(12,1);
lcd.print(color[2]);
lcd.setCursor(displayPositions[cursorIndex], 1);
}
boolean checkButtons(){
if (myReceiver.getResults()) {
if(myDecoder.decode()) {
switch(myDecoder.value) {
case CHMINUS: cursorIndex = 0; break;
case VOLMINUS: cursorIndex = 1; break;
case MINUS: cursorIndex = 2; break;
case ZERO: color[cursorIndex] = 0; break;
case ONEHUNDRED: color[cursorIndex] = 100; break;
case TWOHUNDRED: color[cursorIndex] = 200; break;
}
setLedColor(color);
}
myReceiver.enableIRIn();
return true;
}
else return false;
}
void setLedColor(int r, int g, int b){
analogWrite(redPin, r);
analogWrite(greenPin, g);
analogWrite(bluePin, b);
}
void setLedColor(int colorVector[]){
setLedColor(colorVector[0], colorVector[1], colorVector[2]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment