Writing small Arduino Program to classify certain signals from a tiny IR Remote. Skips condition and prints the same message [closed] - arduino

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 16 hours ago.
Improve this question
I am working on a small program to print certain things when a specific signal has been detected from an IR Remote. However, I am having trouble doing this. Below is the program...
#include <IRremote.h>
const byte IR_RECEIVE_PIN = 11;
void setup()
{
Serial.begin(115200);
Serial.println("IR Receive test");
IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);
}
void loop()
{
if (IrReceiver.decode())
{
Serial.println(IrReceiver.decodedIRData.command, HEX);
if ((IrReceiver.decodedIRData.command, HEX) == 18){
Serial.println("Yahtzee");
}
else{
Serial.println("Working Classification");
}
IrReceiver.resume();
}
}
Whenever it does detect 18, it still prints "Working Classification" as opposed to Yahtzee. This could be a syntax thing that I am not seeing but it does compile.

Related

Pointer of slice of pointers panicking when making [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I have the following code :
var ANIMATIONS *[]*SDL.Animable
....
func main() {
*ANIMATIONS = make([]*SDL.Animable, 0, 100)
But its panicking when running. What is the right way of initializing this?
Error :
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x4afe3a]
goroutine 1 [running, locked to thread]:
main.main()
To fix, you want:
s := make([]*SDL.Animable, 0, 100)
ANIMATIONS = &s
The reason your code was panicking is basically you were dereferencing a nil pointer (*ANIMATIONS). You need to get a reference variable to store your new slice & then you can get it's address (&s) and store that in your pointer.
Note: the following will NOT work &make([]*SDL.Animable, 0, 100) - as you cannot get the address of a returned result - hence the need to store the result & get it's address.

Pull-down resistor is needed? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 5 years ago.
Improve this question
I am using the attachInterrupt() function in Arduino One to recognize the limit of an actuator. Typically I test it as if(), but the actuator cycle is very fast and recognition thereby becomes complicated. Thus I chose to use attachInterrupt(), but I do not know if in the case of interruption I must use pull-down resistor at the input. Someone could tell me if this is needed?
Currently the system is shown below:
Piece of code:
attachInterrupt(digitalPinToInterrupt(interruptPin2), EndCourse2, FALLING);
attachInterrupt(digitalPinToInterrupt(interruptPin3), EndCourse3, FALLING);
void EndCourse2() {
digitalWrite(12,LOW);
btnpressed2=0;
}
void EndCourse3() {
if(btnpressed2==0) {
digitalWrite(12,HIGH);
CounterAT2++;
}
btnpressed2=1;
}
You need a pull-down resistor in this case.
The digital input of the Arduino has a high impedance, which can be though of an insulating input. If you omit the resistor and consider the case when the switch is open, the input of the Arduino is floating. This means the digital input is not connected to any potential. Electromagnetical interference will induce currents into your circuit. Basically, the voltage at the input can change from low to high due to this interference.
To define the state of the input, when the switch is open, you should add the resistor, which ensures, that the input is at low, independent of electromagentical interference.
If you mirror your circuit, such that the switch is connect to ground and the resistor is connect to Vcc, you can move the pull up resistor into the Arduoin by setting the input mode to INPUT_PULLUP. Since then an internal resistor is used, you can drop the resistor outside.

Qt4: How to read data from files in a directory using QDirIterator [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Using Qt 4.7, I need to look for a file in a given directory that has a certain name. If it is found, I need to get the text data from within that file. I have the code set up as follows:
QDirIterator iterator(dir_name, QDirIterator::IteratorFlag);
while(iterator.hasNext()
{
if(iterator.fileName() == nameOfNeededFile)
{
//Code need here to get data!
}
}
It's also probably worth noting that the directory only contains files, no subdirectories.
as being mentioned in comments you don't need an iterator..
QByteArray data;
if (QFile::exists("<your file name>")) {
QFile f("your file");
if (f.open( QIODevice::ReadOnly )) {
data = f.readAll();
f.close();
}
}

Arduino LCD gives weird output [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I've connected my LCD to different set of pins. It worked well with default pins, which LCDLirary use. But now it shows weird characters when i programmed to show something meaning full. How to solve this? (Rx pin is one of my new set of pins. But I disconnect the LCD when programming and connect only after uploading is finished. But that may not be related to the issue)
Well, THAT IS THE ISSUE!!! (if what I'm thinking is correct)
As you said you are disconnecting the LCD while programming, the LCD will not be connected at the time when the LCD unit is initialized by the board. (Initialization begins soon after the programming, eh?). So how can the LCD show correct values without getting properly initialized??
Just reset the board after connecting the LCD. You'll have to do this in other cases also, if you are hoping to use Rx (and probably Tx) pin for some other purposes other than communicating via USB.

Unix programming headerfile details [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
I'm very new to the programming field. Right now I'm trying out some basic programs in Linux. Today I've started off with time functions in time.h, but I'm getting stuck occasionally. I've done the following code to get a delay in seconds.
#include <stdio.h>
#include <sys/types.h>
#include <time.h>
void delay_sec ( int seconds );
int main()
{
printf ( "\nhaii\n" );
delay_sec ( 5 );
printf ( "\nbyee\n" );
return 0;
}
void delay_sec ( int seconds )
{
time_t t1 = time ( NULL );
while ( ( time ( NULL ) - t1 ) < seconds )
;
}
It works for me. But I need a delay in milliseconds. I've read the time.h manual, tried out a few of the functions defined there also, but nothing works like I've expected. The thing is that I actually didn't get any idea about what those functions does.
My question is nothing but where can I find something like a documentation of all the functions and details of arguments, return value, I mean a user manual of all the functions defined in all header files.
I don’t believe something like that really exist, but if you people help me to find something close to that, I would be extremely grateful.
I'm planning to learn fork, pipe, signals, process, thread etc..., I know it's a long way to go. Please help me out.
You should use the POSIX standard sleep function, instead of your busy waiting delay_sec ... (and use usleep for microseconds delay, or better yet nanosleep)
I suggest to install the man pages for development (e.g. manpages-dev package on Debian or Ubuntu).
Otherwise, look e.g. at the sleep(3) man page here.
I strongly suggest reading some good book on Advanced Unix Programming and then read some book on Advanced Linux Programming and then some good book on POSIX threads.
Also learn more on Wikipedia about Linux kernel, System calls etc etc

Resources