Hi everyone, I am having a trouble making code for my project. My project is a "TV like controlled". I should control LCD with two tact switches (push buttons) and also with IR remote (both have the same function) please help me
Hello cakemecakeme
Welcome to the forum.
Post your current sketch, well formated, with comments and in so called code tags "</>" and a schematic, not a Fritzy diagram, to see how we can help.
Have a nice day and enjoy coding in C++.
Дайте миру шанс
#include <IRremote.h>
#include <ir_Lego_PF_BitStreamEncoder.h>
#include <LiquidCrystal.h>
const int RECV_PIN = 6;
IRrecv irrecv(RECV_PIN);
decode_results results;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
//NEXT PAGE FUNCTION
int page_counter=1;
//FOR SCROLL UP AND SCROLL DOWN
int up = 8;
int down = 9;
//SCROLL UP AND DOWN FUNCTIONS
bool current_up = LOW;
bool last_up = LOW;
bool last_down = LOW;
bool current_down = LOW;
//FOR CHARACTERS
byte UP[8] = {
B00100,
B01110,
B11111,
B00000,
B00000,
B00000,
B00000,
B00000
};
byte DOWN[8] = {
B00000,
B00000,
B00000,
B00000,
B00000,
B11111,
B01110,
B00100
};
byte LAMBDA[8] = {
B00000,
B10000,
B01000,
B00100,
B00100,
B01010,
B10001,
B10001
};
byte REPEAT[8] = {
B00000,
B00010,
B11111,
B10010,
B01001,
B11111,
B01000,
B00000
};
void setup() {
Serial.begin(9600);
lcd.begin(16,2);
irrecv.enableIRIn();
lcd.createChar(1, UP);
lcd.createChar(2, DOWN);
lcd.createChar(3, LAMBDA);
lcd.createChar(4, REPEAT);
}
//DEBOUNCING FUNCTION
bool debounce(bool last, int pin)
{
bool current = digitalRead(pin);
if (last != current);
{
delay(5);
current = digitalRead(pin);
}
return current;
}
void loop() {
current_up = debounce(last_up, up);
current_down = debounce(last_down, down);
lcd.setCursor(0, 0);
if (irrecv.decode(&results))
{
int x = results.value;
Serial.println(" ");
Serial.print("Code: ");
Serial.println(results.value);
Serial.println(" ");
irrecv.resume();
}
switch(results.value)
{
//TEXT Up or Scroll Down to move pages
if (last_up== LOW && current_up == HIGH){
lcd.clear();
if(page_counter < 15){
page_counter = page_counter +1;
}
else{
page_counter = 1; //
}
}
last_up = current_up;
//TEXT Down or Scroll Up to move pages
if (last_down== LOW && current_down == HIGH){
lcd.clear();
if(page_counter > 1){
page_counter = page_counter -1;
}
else{
page_counter = 1;
}
}
last_down = current_down;
//PAGE COUNTER
switch (page_counter) {
case 1:{
lcd.setCursor(0,0);
lcd.print("Basic Arithmetic");
lcd.setCursor(1,1);
lcd.print(" by C.M. LORETIZO ");
lcd.setCursor(0,2);
lcd.write(byte(2));
}
break;
case 2:{
lcd.setCursor(1,0);
lcd.print(" by C.M. LORETIZO ");
lcd.setCursor(2,1);
lcd.print("Solve for the");
lcd.setCursor(0,0);
lcd.write(byte(1));
lcd.setCursor(0,1);
lcd.write(byte(2));
}
break;
case 3: {
lcd.setCursor(2,0);
lcd.print("Solve for the");
lcd.setCursor(2,1);
lcd.print("Relative permeability of the line");
lcd.write(byte(3));
lcd.setCursor(0,0);
lcd.write(byte(1));
lcd.setCursor(0,1);
lcd.write(byte(2));
}
break;
case 4: {
lcd.setCursor(2,0);
lcd.print("Relative permeability of the line");
lcd.write(byte(3));
lcd.setCursor(2,1);
lcd.print("Given: ");
lcd.setCursor(0,0);
lcd.write(byte(1));
lcd.setCursor(0,1);
lcd.write(byte(2));
}
break;
case 5: {
lcd.setCursor(2,0);
lcd.print("Given: ");
lcd.write(byte(3));
lcd.print("= u/u_o");
lcd.setCursor(2,1);
lcd.setCursor(3,1);
lcd.print("u=0.88x10^-6 H/m");
lcd.setCursor(0,0);
lcd.write(byte(1));
lcd.setCursor(0,1);
lcd.write(byte(2));
}
break;
case 6: {
lcd.setCursor(2,0);
lcd.setCursor(3,0);
lcd.print("u=0.88x10^-6 H/m");
lcd.setCursor(2,1);
lcd.print("u_o=1.25663706x10^-6 H/m");
lcd.setCursor(0,0);
lcd.write(byte(1));
lcd.setCursor(0,1);
lcd.write(byte(2));
}
break;
case 7: {
lcd.setCursor(2,0);
lcd.print("u_o=1.25663706x10^-6 H/m");
lcd.setCursor(2,1);
lcd.write(byte(3));
lcd.print("= u/u_o");
lcd.setCursor(0,0);
lcd.write(byte(1));
lcd.setCursor(0,1);
lcd.write(byte(2));
}
break;
case 8: {
lcd.setCursor(2,0);
lcd.write(byte(3));
lcd.print("= u/u_o");
lcd.setCursor(2,1);
lcd.print("Solution:");
lcd.setCursor(0,0);
lcd.write(byte(1));
lcd.setCursor(0,1);
lcd.write(byte(2));
}
break;
case 9: {
lcd.setCursor(2,0);
lcd.print("(0.88x10^-6)/1.25663706x10^-6");
lcd.setCursor(2,1);
lcd.write(byte(3));
lcd.print("=0.700 H/m");
lcd.setCursor(0,0);
lcd.write(byte(1));
lcd.setCursor(0,1);
lcd.write(byte(4));
}
break;
case 10:{
lcd.setCursor(0,0);
lcd.print("THANK YOU");
lcd.setCursor(1,1);
lcd.print(" by C.M. LORETIZO ");
lcd.setCursor(0,2);
lcd.write(byte(2));
}
break;
case 0xFF30CF :
{
lcd.print("Basic Arithmetic");
lcd.setCursor(1,1);
lcd.print(" by C.M. LORETIZO ");
lcd.setCursor(0,2);
lcd.write(byte(2));
delay(1000);
lcd.clear();
break;
}
case 0xFF18E7 :
{
lcd.setCursor(1,0);
lcd.print(" by C.M. LORETIZO ");
lcd.setCursor(2,1);
lcd.print("Solve for the");
lcd.setCursor(0,0);
lcd.write(byte(1));
lcd.setCursor(0,1);
lcd.write(byte(2));
}
case 0xFF7A85 :
{
lcd.setCursor(2,0);
lcd.print("Solve for the");
lcd.setCursor(2,1);
lcd.print("Relative permeability of the line");
lcd.write(byte(3));
lcd.setCursor(0,0);
lcd.write(byte(1));
lcd.setCursor(0,1);
lcd.write(byte(2));
}
break;
case 0xFF10EF :
{
lcd.setCursor(2,0);
lcd.print("Relative permeability of the line");
lcd.write(byte(3));
lcd.setCursor(2,1);
lcd.print("Given: ");
lcd.setCursor(0,0);
lcd.write(byte(1));
lcd.setCursor(0,1);
lcd.write(byte(2));
}
break;
case 0xFF38C7 :
{
lcd.setCursor(2,0);
lcd.print("Given: ");
lcd.write(byte(3));
lcd.print("= u/u_o");
lcd.setCursor(2,1);
lcd.setCursor(3,1);
lcd.print("u=0.88x10^-6 H/m");
lcd.setCursor(0,0);
lcd.write(byte(1));
lcd.setCursor(0,1);
lcd.write(byte(2));
}
break;
case 0xFF5AA5 :
{
lcd.setCursor(2,0);
lcd.setCursor(3,0);
lcd.print("u=0.88x10^-6 H/m");
lcd.setCursor(2,1);
lcd.print("u_o=1.25663706x10^-6 H/m");
lcd.setCursor(0,0);
lcd.write(byte(1));
lcd.setCursor(0,1);
lcd.write(byte(2));
}
break;
case 0xFF42BD :
{
lcd.setCursor(2,0);
lcd.print("u_o=1.25663706x10^-6 H/m");
lcd.setCursor(2,1);
lcd.write(byte(3));
lcd.print("= u/u_o");
lcd.setCursor(0,0);
lcd.write(byte(1));
lcd.setCursor(0,1);
lcd.write(byte(2));
}
break;
case 0xFF4AB5 :
{
lcd.setCursor(2,0);
lcd.write(byte(3));
lcd.print("= u/u_o");
lcd.setCursor(2,1);
lcd.print("Solution:");
lcd.setCursor(0,0);
lcd.write(byte(1));
lcd.setCursor(0,1);
lcd.write(byte(2));
}
break;
case 0xFF52AD :
{
lcd.setCursor(2,0);
lcd.print("(0.88x10^-6)/1.25663706x10^-6");
lcd.setCursor(2,1);
lcd.write(byte(3));
lcd.print("=0.700 H/m");
lcd.setCursor(0,0);
lcd.write(byte(1));
lcd.setCursor(0,1);
lcd.write(byte(4));
}
break;
case 0xFF6897 :
{
lcd.setCursor(0,0);
lcd.print("THANK YOU");
lcd.setCursor(1,1);
lcd.print(" by C.M. LORETIZO ");
lcd.setCursor(0,2);
lcd.write(byte(2));
}
break;
}
}
}
here is my schematic and code, thank you so much
Hi, @cakemecakeme
Welcome to the forum.
I'm sorry but this does not make sense.
What are the R1 and R2, 330R resistors for and why have you got them shorted together?
S2 and S1 are connected to what?
What do all the
Can I suggest you forget about the CAD and draw it by hand showing ALL connections and ALL components, don't use all net names for such a small project, connect ALL wires.
Gnd, 5V and 3V3 can be netnames as we all know they are common connections.
Where is your power supply?
Sorry mate, but for a first try is a good attempt, but try to stop wires circling around components like R4.
I hope you have not had a PCB made.
A picture of your project would be good.
Thanks.. Tom...
Hi,
I think this will make things clearer:
R3 and R4 the pulldown resistors are best as 10K resistors, rather than 330R.
Tom...
hello i tried but its not working
You tried what? "not working" conveys no useful information. What does "not working" mean? The code does something, tell us what.
Does the LCD work?
The resistor on the LCD pin 3 (Vo) should go to ground, not 5V.
The IR receiver should be powered by 5V. What is the part number of the IR receiver?
You read the IR signal but do nothing with it. Do you know if the remote works?
What version of the IRremote library are you using. The code is written for an older version of the IRremote library and may not work right with the newer version.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.