switch(results.value){
case 0XFF6897:
if (power == 0) {
power = 1;
} else {
if (power == 1) {
power = 0;
}
}
This does nothing, How would I improve this to make it work?
switch(results.value){
case 0XFF6897:
if (power == 0) {
power = 1;
} else {
if (power == 1) {
power = 0;
}
}
This does nothing, How would I improve this to make it work?
switch(results.value){
case 0XFF6897:
if (power == 0) {
power = 1;
} else {
if (power == 1) {
power = 0;
}
}
A snippet in code tags is still a snippet.
Also, please always do a Tools > Auto Format on your code before posting it to the forum. That will make it easier for us to read.
just answer my question
There is no way to answer your question because your question is garbage. If you actually want help then you need to provide enough information for us to help you. If you had bothered to read the content at the link Delta_G provided you would already know this.
An IR remote has a power button on it with the hexadecimal signal stated as 0XFF6897, now say I take that signal and convert to a variable named "power". If the signal 0XFF6897 has been received from my IR sensor, the variable power would reverse/switch, so if it was 0, then it would be 1, and if it was 1, then it would be 0. How would I write out code for this specific problem?
if (irrecv.decode(&results)){
if (results.value == 0XFFFFFFFF)
results.value = key_value;
switch(results.value){
case 0XFF6897:
power = 1;
break ;
}
key_value = results.value;
irrecv.resume();
if you want the entire code,
#include <IRremote.h>
const int RECV_PIN = 9;
IRrecv irrecv(RECV_PIN);
decode_results results;
unsigned long key_value = 0;
int numb = 1;
int inp = 0;
int good = 1;
int power = 0;
void setup()
{
DDRD = DDRD | B11111100;
Serial.begin(9600);
irrecv.enableIRIn();
irrecv.blink13(true);
pinMode(8, OUTPUT);
pinMode(10, INPUT);
pinMode(13, INPUT);
pinMode(A0, OUTPUT);
pinMode(12, OUTPUT);
Serial.begin(9600);
}
void loop()
{
if (good == 1) {
good = 0;
numb = random(1, 10);
}
if (irrecv.decode(&results)){
if (results.value == 0XFFFFFFFF)
results.value = key_value;
switch(results.value){
case 0XFF6897:
power = 1;
break ;
case 0xFF30CF:
inp = 1;
break ;
case 0xFF18E7:
inp = 2;
break ;
case 0xFF7A85:
inp = 3;
break ;
case 0xFF10EF:
inp = 4;
break ;
case 0xFF38C7:
inp = 5;
break ;
case 0xFF5AA5:
inp = 6;
break ;
case 0xFF42BD:
inp = 7;
break ;
case 0xFF4AB5:
inp = 8;
break ;
case 0xFF52AD:
inp = 9;
break ;
}
key_value = results.value;
irrecv.resume();
if (numb != inp){
digitalWrite(A0, HIGH);
}
if (numb == inp) {
digitalWrite(A0, LOW);
digitalWrite(12, HIGH);
delay(200);
digitalWrite(12, LOW);
}
if (numb == inp) {
good = 1;
inp = 0;
}
if (power == 1) {
if (numb == 1) {
PORTD = B00011000;
digitalWrite(8, LOW);
}
if (numb == 2) {
PORTD = B01101110;
digitalWrite(8, HIGH);
}
if (numb == 3) {
PORTD = B00111100;
digitalWrite(8, HIGH);
}
if (numb == 4) {
PORTD = B10011000;
digitalWrite(8, HIGH);
}
if (numb == 5) {
PORTD = B10110100;
digitalWrite(8, HIGH);
}
if (numb == 6) {
PORTD = B11110100;
digitalWrite(8, HIGH);
}
if (numb == 7) {
PORTD = B00011100;
digitalWrite(8, LOW);
}
if (numb == 8) {
PORTD = B11111100;
digitalWrite(8, HIGH);
}
if (numb == 9) {
PORTD = B10011100;
digitalWrite(8, HIGH);
}
}
}
}
How about:
if (power == 1){
power = 0;
}
else if (power == 0) {
power = 1;
}
Not so hard is it?
If it is guaranteed to be 0 and 1 there's also good ole XOR with 1.
power ^= 1;
Or the always fashionable style of thinking mathematically:
power = 1 - power;
I added that, but still nothing changed.
case 0XFF6897:
if (power == 1){
power = 0;
}
else if (power == 0) {
power = 1;
}
break ;
Well you must have done something wrong. Or you must have the wrong expectations.
Post complete code, with the changes, formatted and readable and I'll try to help you. Press control-T to format the code before you post it. I'm not wading through trying to figure out where all the braces are if your code wanders all over the screen.
I see you ignored what I asked you to do in the previous thread about this:
pert:
Also, please always do a Tools > Auto Format on your code before posting it to the forum. That will make it easier for us to read.
Posting poorly formatted code to the forum is disrespectful to the people you're asking for help. It also indicates that you're not taking a methodical, precise approach to your coding. That sort of approach is bound to lead to a lot of confusion, frustration, and wasted time in the end.
pert:
I see you ignored what I asked you to do in the previous thread about this:
Didn't know he had already been asked. Seem to recall some jerk comment about "Just answer my question" when we asked him for code too.
I'll just stick this one on the ignore list then.
Yeah, I'm getting very close to that point also. It almost seems like some people on this forum don't actually want a solution to their problem. With sufficient information provided from the start, this one could have been solved within minutes rather than taking days.
To go a little further back, have you confirmed the receipt and the decode of the incoming IR signal? Such as have the, for troubleshooting, receipt and decode of the incoming signal print to the serial monitor and confirm that the receipt data is correct. If the received data is not correct no amount of code writing, based on incorrect incoming data will give x = !x'
@rootdoom33, please do not cross-post. Threads merged.