Why is it still crap?
Because it is wrong. You never invoke the constructor directly.
Is there a pdf book I can download that will teach me how to use and write C?
No. Go to a bookstore or library.
Why is it still crap?
Because it is wrong. You never invoke the constructor directly.
Is there a pdf book I can download that will teach me how to use and write C?
No. Go to a bookstore or library.
This isn't 1998 Paul! ![]()
This code compiles ok.
I will first show what I can pull from the remote using the receiving sketch that came with the RCSwitch library
Decimal: 5592323 (24Bit) Binary: 010101010101010100000011 Tri-State: FFFFFFFF0001 PulseLength: 490 microseconds Protocol: 1
Raw data: 15224,460,1504,1456,536,444,1520,1452,532,440,1524,1452,524,460,1516,1444,548,440,1524,1436,540,448,1512,24,3780,88,240,64,144,200,152,56,128,284,508,236,16,48,16,248,3208,52,176,16,376,68,128,76,332,
That's what happens when I press the first button on my RF Remote.
Below is the code that compiles but does not do anything.
/*
Simple example for receiving
http://code.google.com/p/rc-switch/
*/
#include <RCSwitch.h>
int currentState = 0;
int RELAYSWITCH = 5; //Pin # that my relay's trigger/switching
//terminal is connected to
RCSwitch mySwitch;
void setup() {
Serial.begin(9600);
mySwitch.enableReceive(0); // Receiver on inerrupt 0 => that is pin #2
pinMode(RELAYSWITCH, OUTPUT); //setting relay switch pin as output
}
void loop() {
if (mySwitch.available()) {
int value = mySwitch.getReceivedValue();
if (value == 5592323) {
if(currentState == HIGH)
currentState = LOW;
else
currentState = HIGH;
//what do you mean use currentState somehow? It isn't
//changing to show that it's a command or anything?
}
mySwitch.resetAvailable(); //What does this do???
}
}
int value = mySwitch.getReceivedValue();
if (value == 5592323
Why won't you answer a simple question?
Is this running on a Due?
I asked what a due was?
What is a due? I no understaaaaan! ![]()
AutoElecHack:
This isn't 1998 Paul!
I still have, and still often refer to, books I bought then. Get over it.
Ohhhhhh, I thought you were reffering to the code being some for of due value or something.
No it's a uno!
PaulS:
AutoElecHack:
This isn't 1998 Paul!I still have, and still often refer to, books I bought then. Get over it.
Why so serious?
if (value == 5592323
On a sixteen bit "int" that can't work.
Make it a long or unsigned long
AutoElecHack:
PaulS:
AutoElecHack:
This isn't 1998 Paul!I still have, and still often refer to, books I bought then. Get over it.
Why so serious?
The implication in your asking for a pdf is that you want something for free. The C book I bought in 1980 is one I refer to at least once a month. Books are tools; buy the best you can and don't complain about the cost. Your (apparent) willingness, or lack thereof, to spend money on a book reflects in your willingness (or apparent lack thereof) to learn programming. That, in turn, reflects on my willingness to help.
How do you know it's 16 bit?
How do I make it an unsigned long? etc? It makes sense what you are saying though, because I think I can see in another tab something written about unsigned long.
Have you got the RCSwitch library? Should I upload the code for you? It's got three different tabs, how do those tabs work?
How do you know it's 16 bit?
Because you told me it wasn't a Due..
unsigned long value = mySwitch.getReceivedValue();
if (value == 5592323UL)
So the UL stands for Unsigned Long?
I will try this, thank you very much and I will let you know how I go! ![]()
/*
Simple example for receiving
http://code.google.com/p/rc-switch/
*/
#include <RCSwitch.h>
int currentState = 0;
int RELAYSWITCH = 5; //Pin # that my relay's trigger/switching
//terminal is connected to
RCSwitch mySwitch;
void setup() {
Serial.begin(9600);
mySwitch.enableReceive(0); // Receiver on inerrupt 0 => that is pin #2
pinMode(RELAYSWITCH, OUTPUT); //setting relay switch pin as output
}
void loop() {
if (mySwitch.available()) {
int value = mySwitch.getReceivedValue();
if (value == 5592323) {
if(currentState == HIGH)
currentState = LOW;
else
currentState = HIGH;
//what do you mean use currentState somehow? It isn't
//changing to show that it's a command or anything?
}
mySwitch.resetAvailable(); //What does this do???
}
}
So how do I put that into this code? Do I put the unsigned long value bit before setup??
Also, at the end of the sketch what does the last line do "myswitch.resetavailable" ?
OH MY EFFING GOD! You, my friend, are a FREAKING champion!!!!!!!
I GOT IT WORKING!!!! Thank you soooooo much! Far out! How did I not know about such a simple thing? Where can I learn about all these little essential things?!?!!
/*
Simple example for receiving
http://code.google.com/p/rc-switch/
*/
#include <RCSwitch.h>
#define RELAY 5
RCSwitch mySwitch = RCSwitch();
void setup() {
Serial.begin(9600);
pinMode(RELAY, OUTPUT);
mySwitch.enableReceive(0); // Receiver on inerrupt 0 => that is pin #2
}
void loop() {
if (mySwitch.available()) {
unsigned long value = mySwitch.getReceivedValue();
if (value == 5592323UL) {
digitalWrite(RELAY, HIGH);
Serial.print("Unknown encoding");
} else {
Serial.print("Received ");
Serial.print( mySwitch.getReceivedValue() );
Serial.print(" / ");
Serial.print( mySwitch.getReceivedBitlength() );
Serial.print("bit ");
Serial.print("Protocol: ");
Serial.println( mySwitch.getReceivedProtocol() );
}
mySwitch.resetAvailable();
}
}
This works, I just need to change the sketch to toggle on and off and that is it!!!
Thank you so much man!
And Paul, thanks alot for your help, even if you have the shits with me! ![]()
I have come up with this but the relay will only switch on. I need to somehow store the value or something of the relay pin which is an output.
All I want to do is press the button and have it toggle the relay either on or off depending on it's current state!
#include <RCSwitch.h>
#define RELAY1 5
int val = 0;
RCSwitch mySwitch = RCSwitch();
void setup() {
Serial.begin(9600);
pinMode(RELAY1, OUTPUT);
mySwitch.enableReceive(0);
}
void loop() {
if (mySwitch.available()) {
unsigned long value = mySwitch.getReceivedValue();
if (value == 5592323UL) {
digitalRead(RELAY1);
if (val == LOW) {
digitalWrite(RELAY1, HIGH);
}else{
digitalRead(RELAY1);
if (val == HIGH) {
digitalWrite(RELAY1, LOW);
}
mySwitch.resetAvailable();
}
}
}
}
OK, so with this sketch when I press button 1 it turns the relay on and the when i press button 1 again it turns the relay off. But that is it, the relay won't turn on again no matter how I press the button. It's almost as if the sketch isn't looping completely or something?
#include <RCSwitch.h>
#define RELAY1 5
int val = 0;
int old_val = 0;
int state = 1;
int RELAY = 5;
RCSwitch mySwitch = RCSwitch();
void setup() {
Serial.begin(9600);
pinMode(RELAY1, OUTPUT);
mySwitch.enableReceive(0);
}
void loop() {
if (mySwitch.available()) {
unsigned long value = mySwitch.getReceivedValue();
if (value == 5592323UL) {
val = digitalRead(RELAY1);
if ((val == HIGH) && (old_val == LOW)) {
state = 1 - state;
}
old_val = val;
if (state == 1) {
digitalWrite(RELAY1, HIGH);
} else {
digitalWrite(RELAY1, LOW);
}
mySwitch.resetAvailable();
}
}
}
You've initialized the serial port, so why not get it to tell what your sketch is doing, rather than working blind?
Ok, what do I write in the loop to make it show up in the serial monitor?
I'm SOOOOOO close to getting this to work!