-
-
Save JeffersGlass/92b51b09b79b2d760b432f4363951523 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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}; | |
const int SELECT = 0; | |
const int TYPE = 1; | |
int mode = SELECT; | |
int subIndex = 0; | |
void setup() { | |
// set up the LCD's number of columns and rows: | |
lcd.begin(16, 2); | |
// Print a message to the LCD. | |
doDisplay(); | |
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 | |
#define ONE 0xFF30CF | |
#define TWO 0xFF18E7 | |
#define THREE 0xFF7A85 | |
#define FOUR 0xFF10EF | |
#define FIVE 0xFF38C7 | |
#define SIX 0xFF5AA5 | |
#define SEVEN 0xFF42BD | |
#define EIGHT 0xFF4AB5 | |
#define NINE 0xFF52AD | |
int getValueOfButton(int buttonHex){ | |
switch(buttonHex) { | |
case ZERO: return 0; break; | |
case ONE: return 1; break; | |
case TWO: return 2; break; | |
case THREE: return 3; break; | |
case FOUR: return 4; break; | |
case FIVE: return 5; break; | |
case SIX: return 6; break; | |
case SEVEN: return 7; break; | |
case EIGHT: return 8; break; | |
case NINE: return 9; break; | |
default: return -1000; break; | |
} | |
} | |
void loop() { | |
if (checkButtons()){ | |
doDisplay(); | |
} | |
} | |
void doDisplay(){ | |
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+subIndex], 1); | |
} | |
boolean checkButtons(){ | |
if (myReceiver.getResults()) { | |
if(myDecoder.decode()) { | |
if (mode == SELECT){ | |
switch(myDecoder.value) { | |
case CHMINUS: cursorIndex = 0; break; | |
case VOLMINUS: cursorIndex = 1; break; | |
case MINUS: cursorIndex = 2; break; | |
case ONEHUNDRED: color[cursorIndex] = 100; break; | |
case TWOHUNDRED: color[cursorIndex] = 200; break; | |
case ZERO: | |
case ONE: | |
case TWO: | |
case THREE: | |
case FOUR: | |
case FIVE: | |
case SIX: | |
case SEVEN: | |
case EIGHT: | |
case NINE: mode = TYPE; lcd.blink(); break; | |
} | |
if (mode == TYPE) setLedColor(color); | |
} | |
if (mode == TYPE) { | |
switch(myDecoder.value) { | |
case ZERO: | |
case ONE: | |
case TWO: | |
case THREE: | |
case FOUR: | |
case FIVE: | |
case SIX: | |
case SEVEN: | |
case EIGHT: | |
case NINE: | |
int digitValue = getValueOfButton(myDecoder.value); | |
setDigit(color[cursorIndex], subIndex, digitValue); | |
subIndex++; | |
doDisplay(); | |
if (subIndex == 3){ | |
subIndex = 0; | |
color[cursorIndex] = constrain(color[cursorIndex], 0, 255); | |
mode = SELECT; | |
lcd.noBlink(); | |
doDisplay(); | |
} | |
break; | |
} | |
} | |
} | |
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]); | |
} | |
int getDigit(int number, int digit){ | |
digit = 2 - digit; //input digit 0 will be the 100's digit | |
int truncate = number % int(pow(10, digit+1)); | |
int rounded = number / pow(10,digit); | |
return rounded; | |
} | |
int setDigit(int number, int digit, int digitVal){ | |
digit = 2 - digit; //input digit 0 will be the 100's digit | |
int currentDigit = getDigit(number, digit); | |
number -= currentDigit * pow(10, digit); | |
number += digitVal * pow(10, digit); | |
return number; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment