I am trying to get a reading from a potentiometer(0-5000) on the serial monitor and then be able to zero and recalibrate at different points with an IR remote at different points(say the value is 2000, I need to make that 0 if I hit a button and go from there). Thank you in advance, any help is much appreciated!
Here is my code so far(I have added and deleted much)
#include <IRremote.h> // use the library
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int analogOutPin = 9; // Analog output pin that the LED is attached to
int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the PWM (analog out)
int receiver = 11;
IRrecv irrecv(receiver); // create instance of 'irrecv'
decode_results results;
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
}
void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
sVal();
// change the analog out value:
analogWrite(analogOutPin, outputValue);
// print the results to the serial monitor:
Serial.print("sensor = " );
Serial.print(sensorValue);
Serial.print("\t output = ");
Serial.println(outputValue);
// for the analog-to-digital converter to settle
// after the last reading:
delay(300);
}
void sVal()
{
I am trying to get a reading from a potentiometer(0-5000) on the serial monitor and then be able to zero and recalibrate at different points with an IR remote at different points(say the value is 2000,
What????
You can't get 2000 from the analog-to-digital converter. It goes 0-1023.
Check your map function.. Your map() function maps zero to zero.
Maybe you want another map() function to map from 0-5000 to 2000- ...something??? Or, to re-map your orginal values from 0-1023 values to 2000- ....something.
carlislew:
I am trying to get a reading from a potentiometer(0-5000) on the serial monitor and then be able to zero and recalibrate at different points with an IR remote at different points(say the value is 2000, I need to make that 0 if I hit a button and go from there). Thank you in advance, any help is much appreciated!
I actually have it working when mapped 0-5000. It's when I try to zero and recalibrate with remote to digital input that I cannot get it to work. I have tried creating new methods to use a new map with different values when zeroed but to no avail. So my question is, how do I get a button press on an IR remote to zero the readout and recalibrate?
// read the analog in value:
sensorValue = 5*(analogRead(analogInPin));
and skip the mapping.
Result will be 0,5,10,15,20 ... 5100, 5105, 5110, 5115
I just assume I will have no idea what value the sensorValue will be when I zero it, but whatever it is I need to make that zero and the values go up from there when a button is pushed on an IR remote.
but whatever it is I need to make that zero and the values go up from there when a button is pushed on an IR remote.
So when the button is pressed you take a reading and use that reading as the minimum point in your new map function.
Or you can use that reading to subtract from subsequent readings.
I am trying to get a reading from a potentiometer(0-5000) on the serial monitor and then be able to zero and recalibrate at different points with an IR remote at different points(say the value is 2000,
What????
You can't get 2000 from the analog-to-digital converter. It goes 0-1023.
Check your map function.. Your map() function maps zero to zero.
Maybe you want another map() function to map from 0-5000 to 2000- ...something??? Or, to re-map your orginal values from 0-1023 values to 2000- ....something.
I have it mapped 0-5000 now and it works when I change value on the pot. I just need to be able to make whatever value that is zero when I get input from a remote and then recalibrate. I would compare it to the tare on a scale so that when a bag is on the scale the weight is not actually 0 but it starts at 0 and the weight added is what it reads.
I have it mapped 0-5000 now and it works when I change value on the pot.
Yes but you don't get all the numbers from 0 to 5000 they will go up in jumps of 5 or so.
What was wrong with my last answer?
I think you had a good answer, I am kind of to that point. I am just having trouble with getting that part in motion. When I set a variable to equal the value at the zero point, I end up going in circles trying to get it to work. Usually I just get a constant zero reading and go back and forth changing things around until it ends up a mess and start all over.