Store only non-zero values from analog read() and ignore all zeros

I want to store only non-zero values from analog read() in an array. And then parse int() the first integer in that array.

I'm a newbie so please excuse any silly errors/questions

We don't do homework.

welcome to the forum. How are you getting on with that?

Then, what do you need help with? Are you getting values from the analog read? Are any non-zero? Have you researched how to make an array of integers and how to access/store data into that array?

You would simply use an if statement before you store your value.

if( reading != 0) {
// store the reading into your array.
}

I'm reading analog data using analogRead()

It outputs zero when the button on remote is not pressed. When a button is pressed then it gives 1023.

So I want to make an array that stores only the 1023 part and not the zeros.

I did but it's returning zeros only. Even when I press the button

  1. yes, getting values from analog read
  2. want to store the data of analog read in an array ONLY when it is not zero or above certain threshold


Here's the code I've written. The serial monitor shows zeros only

So it's doing what it should do.

What button it is the first we have herd of this?

I think it is time to post your code and a schematic of what you are trying to make.

Posting code of an image is useless in most cases but in your cast you are mixing up the variable answer with something you might have read from a serial input string. Get rid of it and post your schematic.


So this is a remote that receives the input from these buttons on a receiver. The receiver is connected to analog input of Arduino.

The the code should read the non zero values only ;-;

That is not a schematic it is a photo of the outside. So a bit useless actually.

Also print out the value not your so called answer.

Alright got it. Thank you. Also does it Means the Arduino will only read the analog data?

The further manipulation I want with the analog Input should be done on PyCharm or any other IDE because I'm not very good with C++

That's a picture of a transmitter, not a receiver.
The receiver could already have a decoder chip, or not.
Leo..


Yes the receiver has the decoderr chip on it

I see a receiver/decoder (2272 chip).
The decoder has digital outputs.
You should be using digital inputs of the Arduino, not analogue.
Adafruit has an information page for this module.
Leo..

Thank you so much. Really helped a lot

Yes.
What were you expecting it to read?

What is PyCharm.

It is not at all difficult.

when you know how! :wink: