(sorry if I posted this again, it didnt show on my posts and i wasnt sure if i post it or not)
I am trying to make a project where the user will make a configuration with the ir controller and then according to the settings they choose, the button wil work either as a toggle or as a push button. The configuration works fine, but the button doesnt seem to work. If i do serial.print, it outputs 0, no matter if it is pressed or not. The code for the button works, i tried it on a different sketch, the button works too and the wires are ok. Does anyone have any idea what is going on? I don't know what is wrong with the code, so I ll post anything you ask
(the code structure is : setting1-> setting2/3/4-> setting4-> button)
Thanks in advance
There is no way to figure out what is wrong with your sketch if you don't post it.
it is this that causes the issue: IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);
I downloaded an older library, but it had issues with the lcd.
If anyone has any recommendations on how to fix this issue I would be grateful.
ToddL1962:
There is no way to figure out what is wrong with your sketch if you don't post it.
here is the code, dont know if it will help since the issues is in the library
#include <IRremote.h>
#include <LiquidCrystal.h>
int rs=7;
int en=8;
int d4=9;
int d5=10;
int d6=11;
int d7=12;
int mode=0;
int pew=0;
int firemode = 0;
int rpm;
int start = 1;
float bullet=0;
int select_fire = 1;
int text =0;
float ammo_start;
int ammo_burst=0;
int ammo_auto;
float ammo_left;
int lastButtonState;
int currentButtonState;
LiquidCrystal lcd(rs,en,d4,d5,d6,d7);
int IR_RECEIVE_PIN = 3;
String my_com;
int button = 13;
int but_press=0;
void setup()
{
pinMode(button, INPUT);
digitalWrite(button,HIGH);
lcd.begin(16,2);
Serial.begin(9600);
IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);
currentButtonState = digitalRead(button);
}
void loop(){
//start up text
if (start==1){
lcd.clear();lcd.setCursor(0,0);
lcd.print("Don't fire while");
lcd.setCursor(0,1);
lcd.print("set up");
}
while (IrReceiver.decode()==0){
}
Serial.println(IrReceiver.decodedIRData.command, HEX);
IrReceiver.resume();
if ( select_fire==1){
switch (IrReceiver.decodedIRData.command){
case 0x45:
select_fire=0;
mode = 1;
start=0;
lcd.clear();
break;}
}
//select firemode
if (mode==1){
lcd.setCursor(0,0);
lcd.print("select firemode");
switch (firemode){
case 0:
lcd.setCursor(0,0);
lcd.print("select firemode");
lcd.setCursor(0,1);
lcd.print("semi-automatic");
delay(500);
while (IrReceiver.decode()==0){}
switch (IrReceiver.decodedIRData.command){
case 0x7: firemode = 2;
lcd.clear();
break;
case 0x9: firemode=1;
lcd.clear();
break;
case 0x40: mode=3;
lcd.clear();
break;}
break;
case 1:
lcd.setCursor(0,0);
lcd.print("select firemode");
lcd.setCursor(0,1);
lcd.print("burst");
delay(500);
while (IrReceiver.decode()==0){}
switch (IrReceiver.decodedIRData.command){
case 0x7: firemode = 0;
break;
case 0x9: firemode=2;
break;
case 0x40: mode=5;
lcd.clear();
break;}
break;
case 2:
lcd.setCursor(0,0);
lcd.print("select firemode");
lcd.setCursor(0,1);
lcd.print("full auto");
delay(500);
while (IrReceiver.decode()==0){}
switch (IrReceiver.decodedIRData.command){
case 0x7: firemode = 1;
lcd.clear();
break;
case 0x9: firemode=0;
break;
case 0x40: mode=2;
lcd.clear();
break;}
break;}
}
//rpm for automatic firemode
if (mode==2){
lcd.setCursor(0,0);
lcd.print("RPM");
while (IrReceiver.decode()==0){}
while (IrReceiver.decodedIRData.command==0x9){
rpm=rpm+1;
lcd.setCursor(0,1);
lcd.print(rpm);
delay(100);
while (IrReceiver.decode()==0){}
IrReceiver.resume();}
while (IrReceiver.decodedIRData.command==0x7){
rpm=rpm-1;
if (rpm<0){
rpm=0;}
lcd.setCursor(0,1);
lcd.print(rpm);
delay(100);
while (IrReceiver.decode()==0){}
IrReceiver.resume();}
if(IrReceiver.decodedIRData.command==0x43){
mode=3;
lcd.clear();}
}
//how much ammo you have, all firemodes
if (mode == 3){
lcd.setCursor(0,0);
lcd.print("Magazine");
while (IrReceiver.decode()==0){}
IrReceiver.resume();
while (IrReceiver.decodedIRData.command==0x9){
bullet=bullet+1;
lcd.setCursor(0,1);
lcd.print(bullet);
delay(200);
while (IrReceiver.decode()==0){}
IrReceiver.resume();}
while (IrReceiver.decodedIRData.command==0x7){
bullet=bullet-1;
if (bullet<0){
bullet=0;}
lcd.setCursor(0,1);
lcd.print(bullet);
delay(200);
while (IrReceiver.decode()==0){}
IrReceiver.resume();}
if(IrReceiver.decodedIRData.command==0x44){
mode=4;
lcd.clear();}
}//how many bullets you shoot at one burst
if (mode==5){
lcd.setCursor(0,0);
lcd.print("Burst");
while (IrReceiver.decode()==0){}
IrReceiver.resume();
while (IrReceiver.decodedIRData.command==0x9){
ammo_burst=ammo_burst+1;
lcd.setCursor(0,1);
lcd.print(ammo_burst);
delay(200);
while (IrReceiver.decode()==0){}
IrReceiver.resume();}
while (IrReceiver.decodedIRData.command==0x7){
ammo_burst=ammo_burst-1;
if (ammo_burst<0){
ammo_burst=0;}
lcd.setCursor(0,1);
lcd.print(bullet);
delay(200);
while (IrReceiver.decode()==0){}
IrReceiver.resume();}
if(IrReceiver.decodedIRData.command==0x43){
mode=3;
lcd.clear();}
}//determines what firemode you are at
if(mode==4){
switch (firemode){
case 0: pew=1;
break;
case 1: pew=2;
break;
case 2: pew = 3;
break;}
}
//here starts the button stuff
while (pew==1){
lastButtonState = currentButtonState;
currentButtonState = digitalRead(button);
Serial.println(lastButtonState );
ammo_start=bullet;
ammo_left=bullet;
lcd.setCursor(0,0);
lcd.print("Ammo left");
lcd.setCursor(0,1);
lcd.print(ammo_left);
lastButtonState = currentButtonState;
currentButtonState = digitalRead(button);
if(lastButtonState == HIGH && currentButtonState == LOW) {
ammo_left=ammo_left-1;
lcd.setCursor(0,1);
lcd.print(ammo_left);
lastButtonState = currentButtonState;
currentButtonState = digitalRead(button);
if (ammo_left==0){
ammo_left=ammo_start;}}
}
while(pew==3){
ammo_start=bullet;
ammo_left=bullet;
ammo_auto= ammo_left;
lcd.setCursor(0,0);
lcd.print("Ammo left");
lcd.setCursor(0,1);
lcd.print(ammo_auto);
but_press = digitalRead(button);
if (but_press==0){
ammo_left=ammo_left-(1./60000.)*ammo_left;
ammo_auto=ammo_left;
if (ammo_left==0){
ammo_left=ammo_start;}
}
}
while (pew==2){
lastButtonState = currentButtonState;
currentButtonState = digitalRead(button);
Serial.println(lastButtonState );
ammo_start=bullet;
ammo_left=bullet;
lcd.setCursor(0,0);
lcd.print("Ammo left");
lcd.setCursor(0,1);
lcd.print(ammo_left);
lastButtonState = currentButtonState;
currentButtonState = digitalRead(button);
if(lastButtonState == HIGH && currentButtonState == LOW) {
ammo_left=ammo_left-ammo_burst;
lcd.setCursor(0,1);
lcd.print(ammo_left);
lastButtonState = currentButtonState;
currentButtonState = digitalRead(button);
if (ammo_left==0){
ammo_left=ammo_start;}}}
}
You're going to have to give us more to go on here. For a start read through How to get the best out of this forum (short version).
Then go through and comment your code so we can understand what you're trying to do and what's gong on.
Once you've done that done come back with a good description of what the problem is. At the moment we have no idea what button you talking about, how it's connected, which section of code to look at or even what library you're talking about.
if anyone has the same issue, just don't use the 3 and 11 pins, the ir controller library i used meshes up with the arduino clock
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.